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),
|
||||
]
|
||||
25
accounting/migrations/0008_invoice_cancelled_status.py
Normal file
25
accounting/migrations/0008_invoice_cancelled_status.py
Normal file
@@ -0,0 +1,25 @@
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('accounting', '0007_backfill_voucher_numbers'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='invoice',
|
||||
name='status',
|
||||
field=models.CharField(
|
||||
choices=[
|
||||
('draft', 'Draft'),
|
||||
('confirmed', 'Confirmed'),
|
||||
('paid', 'Paid'),
|
||||
('cancelled', 'Cancelled'),
|
||||
],
|
||||
default='draft',
|
||||
max_length=20,
|
||||
),
|
||||
),
|
||||
]
|
||||
30
accounting/migrations/0009_treasury_event_name.py
Normal file
30
accounting/migrations/0009_treasury_event_name.py
Normal file
@@ -0,0 +1,30 @@
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
"""
|
||||
DB already has event_name (NOT NULL) from an earlier manual/out-of-band change.
|
||||
Sync Django state and ensure NULLs become empty string so inserts never omit the column.
|
||||
"""
|
||||
|
||||
dependencies = [
|
||||
('accounting', '0008_invoice_cancelled_status'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.SeparateDatabaseAndState(
|
||||
state_operations=[
|
||||
migrations.AddField(
|
||||
model_name='treasurytxn',
|
||||
name='event_name',
|
||||
field=models.CharField(blank=True, default='', max_length=200),
|
||||
),
|
||||
],
|
||||
database_operations=[
|
||||
migrations.RunSQL(
|
||||
sql="UPDATE accounting_treasury_txns SET event_name = '' WHERE event_name IS NULL;",
|
||||
reverse_sql=migrations.RunSQL.noop,
|
||||
),
|
||||
],
|
||||
),
|
||||
]
|
||||
Reference in New Issue
Block a user