3
0
Fork 0
mirror of https://github.com/nanoy42/coope synced 2024-11-28 15:42:25 +00:00
coope/users/migrations/0010_auto_20190623_1656.py

35 lines
1.1 KiB
Python
Raw Normal View History

2019-06-23 15:11:58 +00:00
# Generated by Django 2.1 on 2019-06-23 14:56
from django.db import migrations, models
def update(apps, schema_editor):
User = apps.get_model('auth', 'User')
ConsumptionHistory = apps.get_model('gestion', 'ConsumptionHistory')
for u in User.objects.all():
chs = ConsumptionHistory.objects.filter(customer=u).filter(paymentMethod__affect_balance=False)
u.profile.direct_debit = sum([x.amount for x in chs])
u.profile.save()
def reverse(apps, schema_editor):
pass
class Migration(migrations.Migration):
dependencies = [
('users', '0009_auto_20190623_1437'),
]
operations = [
migrations.AddField(
model_name='historicalprofile',
name='direct_debit',
field=models.DecimalField(decimal_places=2, default=0, max_digits=7, verbose_name='Débit (non compte)'),
),
migrations.AddField(
model_name='profile',
name='direct_debit',
field=models.DecimalField(decimal_places=2, default=0, max_digits=7, verbose_name='Débit (non compte)'),
),
migrations.RunPython(update, reverse)
]