loko/streetup/interventions/migrations/0020_auto_20260722_1142.py
2026-07-22 14:48:40 +02:00

49 lines
1.7 KiB
Python

# Generated by Django 5.2.8 on 2026-07-22 09:42
from django.db import migrations
def inject_oa054_routing(apps, schema_editor):
DirectContractRouting = apps.get_model('interventions', 'DirectContractRouting')
Contract = apps.get_model('contracts', 'Contract')
Symptom = apps.get_model('interventions', 'Symptom')
# Find the contracts
contract_x005 = Contract.objects.filter(contract_number='X00.005').first()
contract_x006 = Contract.objects.filter(contract_number='X00.006').first()
symptom_clean = Symptom.objects.filter(code='TU_CLEAN_ROADWAY').first()
# If X00.005 and TU_CLEAN_ROADWAY symptom exist, create the routing rule
if contract_x005 and symptom_clean:
DirectContractRouting.objects.get_or_create(
thematic='structures',
asset_code='OA054',
symptom=symptom_clean,
defaults={'contract': contract_x005}
)
# If X00.006 exists, create the default routing rule for OA054
if contract_x006:
DirectContractRouting.objects.get_or_create(
thematic='structures',
asset_code='OA054',
symptom=None,
defaults={'contract': contract_x006}
)
def reverse_oa054_routing(apps, schema_editor):
DirectContractRouting = apps.get_model('interventions', 'DirectContractRouting')
DirectContractRouting.objects.filter(thematic='structures', asset_code='OA054').delete()
class Migration(migrations.Migration):
dependencies = [
('interventions', '0019_directcontractrouting'),
('contracts', '__first__'),
]
operations = [
migrations.RunPython(inject_oa054_routing, reverse_code=reverse_oa054_routing),
]