gestioCOF/kfet/migrations/0049_remove_checkout.py

39 lines
1.2 KiB
Python
Raw Normal View History

2017-03-24 21:23:04 -03:00
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
def adapt_operation_types(apps, schema_editor):
Operation = apps.get_model("kfet", "Operation")
2017-03-25 10:46:18 -03:00
Operation.objects.filter(
2017-03-24 23:27:55 -03:00
is_checkout=False,
2017-03-25 10:46:18 -03:00
type__in=['withdraw', 'deposit']).update(type='edit')
2017-03-24 23:27:55 -03:00
def revert_operation_types(apps, schema_editor):
Operation = apps.get_model("kfet", "Operation")
2017-03-26 15:06:45 -03:00
edits = Operation.objects.filter(type='edit')
edits.filter(amount__gt=0).update(type='deposit')
edits.filter(amount__lte=0).update(type='withdraw')
2017-03-24 21:23:04 -03:00
class Migration(migrations.Migration):
dependencies = [
('kfet', '0048_article_hidden'),
]
operations = [
migrations.AlterField(
model_name='operation',
name='type',
field=models.CharField(choices=[('purchase', 'Achat'), ('deposit', 'Charge'), ('withdraw', 'Retrait'), ('initial', 'Initial'), ('edit', 'Édition')], max_length=8),
),
2017-03-24 23:27:55 -03:00
migrations.RunPython(adapt_operation_types, revert_operation_types),
2017-03-24 21:23:04 -03:00
migrations.RemoveField(
model_name='operation',
name='is_checkout',
),
]