2017-03-25 01:23:04 +01: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 03:27:55 +01:00
|
|
|
edits = Operation.objects.filter(
|
|
|
|
is_checkout=False,
|
|
|
|
type__in=['withdraw', 'deposit'])
|
2017-03-25 01:23:04 +01:00
|
|
|
|
2017-03-25 03:27:55 +01:00
|
|
|
for ope in edits:
|
|
|
|
ope.type = 'edit'
|
|
|
|
ope.save()
|
|
|
|
|
|
|
|
|
|
|
|
def revert_operation_types(apps, schema_editor):
|
|
|
|
Operation = apps.get_model("kfet", "Operation")
|
|
|
|
|
|
|
|
for ope in Operation.objects.filter(type='edit'):
|
|
|
|
ope.type = 'deposit' if ope.amount > 0 else 'withdraw'
|
|
|
|
ope.is_checkout = False
|
|
|
|
ope.save()
|
2017-03-25 01:23:04 +01: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-25 03:27:55 +01:00
|
|
|
migrations.RunPython(adapt_operation_types, revert_operation_types),
|
2017-03-25 01:23:04 +01:00
|
|
|
migrations.RemoveField(
|
|
|
|
model_name='operation',
|
|
|
|
name='is_checkout',
|
|
|
|
),
|
|
|
|
]
|