mirror of
https://github.com/nanoy42/coope
synced 2024-08-20 00:43:40 +00:00
35 lines
1.1 KiB
Python
35 lines
1.1 KiB
Python
|
# 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)
|
||
|
]
|