snapshot: preserve configurable onboarding conditional logic
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
DEFAULT_RULES = {
|
||||
'business-card-box': [
|
||||
{'field': 'order_business_cards', 'operator': 'checked', 'value': True},
|
||||
],
|
||||
'employment-end-box': [
|
||||
{'field': 'employment_type', 'operator': 'equals', 'value': 'befristet'},
|
||||
],
|
||||
'group-mailboxes-box': [
|
||||
{'field': 'group_mailboxes_required_choice', 'operator': 'equals', 'value': 'ja'},
|
||||
],
|
||||
'extra-hardware-box': [
|
||||
{'field': 'additional_hardware_needed_choice', 'operator': 'equals', 'value': 'ja'},
|
||||
],
|
||||
'extra-software-box': [
|
||||
{'field': 'additional_software_needed_choice', 'operator': 'equals', 'value': 'ja'},
|
||||
],
|
||||
'extra-access-box': [
|
||||
{'field': 'additional_access_needed_choice', 'operator': 'equals', 'value': 'ja'},
|
||||
],
|
||||
'successor-box': [
|
||||
{'field': 'successor_required_choice', 'operator': 'equals', 'value': 'ja'},
|
||||
],
|
||||
'phone-box': [
|
||||
{'field': 'successor_required_choice', 'operator': 'equals', 'value': 'ja'},
|
||||
{'field': 'inherit_phone_number_choice', 'operator': 'not_equals', 'value': 'ja'},
|
||||
],
|
||||
}
|
||||
|
||||
|
||||
def seed_conditional_rules(apps, schema_editor):
|
||||
FormConditionalRuleConfig = apps.get_model('workflows', 'FormConditionalRuleConfig')
|
||||
for target_key, clauses in DEFAULT_RULES.items():
|
||||
FormConditionalRuleConfig.objects.get_or_create(
|
||||
form_type='onboarding',
|
||||
target_key=target_key,
|
||||
defaults={'clauses': clauses, 'is_active': True},
|
||||
)
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('workflows', '0053_formsectionconfig'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='FormConditionalRuleConfig',
|
||||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('form_type', models.CharField(choices=[('onboarding', 'Onboarding')], max_length=20)),
|
||||
('target_key', models.CharField(max_length=80)),
|
||||
('clauses', models.JSONField(blank=True, default=list)),
|
||||
('is_active', models.BooleanField(default=True)),
|
||||
],
|
||||
options={
|
||||
'verbose_name': 'Formular-Bedingungsregel',
|
||||
'verbose_name_plural': 'Formular-Bedingungsregeln',
|
||||
'ordering': ['form_type', 'target_key'],
|
||||
'unique_together': {('form_type', 'target_key')},
|
||||
},
|
||||
),
|
||||
migrations.RunPython(seed_conditional_rules, migrations.RunPython.noop),
|
||||
]
|
||||
Reference in New Issue
Block a user