Add invoice cancelled status, treasury event name, and voucher number backfill.
EOF Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
31
accounting/migrations/0007_backfill_voucher_numbers.py
Normal file
31
accounting/migrations/0007_backfill_voucher_numbers.py
Normal file
@@ -0,0 +1,31 @@
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
def backfill_voucher_numbers(apps, schema_editor):
|
||||
Voucher = apps.get_model('accounting', 'Voucher')
|
||||
|
||||
max_number = (
|
||||
Voucher.objects.exclude(number__lte=0)
|
||||
.order_by('-number')
|
||||
.values_list('number', flat=True)
|
||||
.first()
|
||||
or 0
|
||||
)
|
||||
|
||||
missing_number_vouchers = Voucher.objects.filter(number__lte=0).order_by('created_at', 'id')
|
||||
|
||||
next_number = max_number + 1
|
||||
for voucher in missing_number_vouchers:
|
||||
voucher.number = next_number
|
||||
voucher.save(update_fields=['number'])
|
||||
next_number += 1
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
dependencies = [
|
||||
('accounting', '0006_treasury_fee_fields'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RunPython(backfill_voucher_numbers, migrations.RunPython.noop),
|
||||
]
|
||||
Reference in New Issue
Block a user