You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
40 lines
1.3 KiB
Python
40 lines
1.3 KiB
Python
# Generated by Django 4.2.20 on 2025-10-11 15:43
|
|
|
|
from django.db import migrations, models
|
|
|
|
|
|
def set_status_from_old_fields(apps, schema_editor):
|
|
"""
|
|
Set the status field based on the existing submitted and confirmed fields.
|
|
- If confirmed is True, status = CONFIRMED (2)
|
|
- If submitted is True but confirmed is False, status = SUBMITTED (1)
|
|
- Otherwise, status = UNSUBMITTED (0)
|
|
"""
|
|
Statement = apps.get_model('finance', 'Statement')
|
|
UNSUBMITTED, SUBMITTED, CONFIRMED = 0, 1, 2
|
|
|
|
for statement in Statement.objects.all():
|
|
if statement.confirmed:
|
|
statement.status = CONFIRMED
|
|
elif statement.submitted:
|
|
statement.status = SUBMITTED
|
|
else:
|
|
statement.status = UNSUBMITTED
|
|
statement.save(update_fields=['status'])
|
|
|
|
|
|
class Migration(migrations.Migration):
|
|
|
|
dependencies = [
|
|
('finance', '0009_statement_ljp_to'),
|
|
]
|
|
|
|
operations = [
|
|
migrations.AddField(
|
|
model_name='statement',
|
|
name='status',
|
|
field=models.IntegerField(choices=[(0, 'In preparation'), (1, 'Submitted'), (2, 'Confirmed')], default=0, verbose_name='Status'),
|
|
),
|
|
migrations.RunPython(set_status_from_old_fields, reverse_code=migrations.RunPython.noop),
|
|
]
|