33 lines
1.1 KiB
Python
33 lines
1.1 KiB
Python
from decimal import Decimal
|
|
|
|
from django.db import migrations
|
|
|
|
|
|
def backfill_shenqing_jine(apps, schema_editor):
|
|
Tixianjilu = apps.get_model('yonghu', 'Tixianjilu')
|
|
TixianShenheJilu = apps.get_model('yonghu', 'TixianShenheJilu')
|
|
|
|
for row in Tixianjilu.objects.filter(shenqing_jine__isnull=True).iterator():
|
|
amount = None
|
|
if row.shenhe_jilu_id:
|
|
audit = TixianShenheJilu.objects.filter(pk=row.shenhe_jilu_id).only('shenqing_jine').first()
|
|
if audit and audit.shenqing_jine is not None:
|
|
amount = Decimal(str(audit.shenqing_jine))
|
|
if amount is None:
|
|
jine = Decimal(str(row.jine or 0))
|
|
fee = Decimal(str(row.shouxufei or 0))
|
|
amount = jine + fee
|
|
if amount > 0:
|
|
Tixianjilu.objects.filter(pk=row.pk).update(shenqing_jine=amount)
|
|
|
|
|
|
class Migration(migrations.Migration):
|
|
|
|
dependencies = [
|
|
('yonghu', '0021_tixianjilu_shenqing_jine_shouxufei'),
|
|
]
|
|
|
|
operations = [
|
|
migrations.RunPython(backfill_shenqing_jine, migrations.RunPython.noop),
|
|
]
|