|
@@ -0,0 +1,53 @@
|
|
|
+# -*- coding: utf-8 -*-
|
|
|
+from __future__ import unicode_literals
|
|
|
+
|
|
|
+from django.db import models, migrations
|
|
|
+
|
|
|
+
|
|
|
+PAYMENT_MEAN_MAPPING = {
|
|
|
+ 'cash': (1, 'Espèces'),
|
|
|
+ 'check': (2, 'Chèque'),
|
|
|
+ 'transfer': (3, 'Virement'),
|
|
|
+ 'other': (4, 'Autre')
|
|
|
+}
|
|
|
+
|
|
|
+def forward(apps, schema_editor):
|
|
|
+ PaymentMethod = apps.get_model("billing", "PaymentMethod")
|
|
|
+
|
|
|
+ # Add default payment means:
|
|
|
+ for key, payment_mean_values in PAYMENT_MEAN_MAPPING.iteritems():
|
|
|
+ payment_method = PaymentMethod(
|
|
|
+ id=payment_mean_values[0],
|
|
|
+ name=payment_mean_values[1])
|
|
|
+ payment_method.save()
|
|
|
+ # PAYMENT_MEAN_MAPPING[key] += (payment_method,)
|
|
|
+
|
|
|
+ # Change invoices payment mean choice field to foreign key
|
|
|
+ Payment = apps.get_model("billing", "Payment")
|
|
|
+
|
|
|
+ for payment in Payment.objects.all():
|
|
|
+ if payment.payment_mean and payment.payment_mean in PAYMENT_MEAN_MAPPING:
|
|
|
+ payment.method_id = PAYMENT_MEAN_MAPPING[payment.payment_mean][0]
|
|
|
+ payment.save()
|
|
|
+
|
|
|
+def backward(apps, schema_editor):
|
|
|
+ # Change invoices payment mean foreign key field to choice
|
|
|
+ Payment = apps.get_model("billing", "Payment")
|
|
|
+
|
|
|
+ for payment in Payment.objects.all():
|
|
|
+ if payment.method_id:
|
|
|
+ for k,v in PAYMENT_MEAN_MAPPING.iteritems():
|
|
|
+ if v[0]==payment.method_id:
|
|
|
+ payment.payment_mean = k
|
|
|
+ payment.save()
|
|
|
+
|
|
|
+
|
|
|
+class Migration(migrations.Migration):
|
|
|
+
|
|
|
+ dependencies = [
|
|
|
+ ('billing', '0003_auto_20141101_2337'),
|
|
|
+ ]
|
|
|
+
|
|
|
+ operations = [
|
|
|
+ migrations.RunPython(forward, backward),
|
|
|
+ ]
|