From 78b950c392af285523f5be998046f1bc8a1e6dd1 Mon Sep 17 00:00:00 2001 From: Hugo LEVY-FALK Date: Fri, 13 Jul 2018 15:15:01 +0200 Subject: [PATCH] =?UTF-8?q?condense=20toutes=20les=20migrations=20des=20pa?= =?UTF-8?q?iement=20personnalis=C3=A9s=20en=20une=20seule.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cotisations/migrations/0030_custom_payment.py | 123 ++++++++++++++++++ .../0030_paiement_allow_self_subscription.py | 20 --- .../0031_article_allow_self_subscription.py | 20 --- .../0032_chequepayment_comnpaypayment.py | 65 --------- cotisations/migrations/0033_balancepayment.py | 41 ------ .../migrations/0034_auto_20180703_0929.py | 26 ---- .../migrations/0035_auto_20180703_1005.py | 28 ---- .../migrations/0036_auto_20180703_1056.py | 28 ---- .../migrations/0037_auto_20180703_1202.py | 35 ----- .../migrations/0038_paiement_is_balance.py | 29 ----- .../migrations/0039_auto_20180704_1147.py | 21 --- .../migrations/0040_auto_20180705_0822.py | 20 --- .../0045_remove_unused_payment_fields.py | 2 +- 13 files changed, 124 insertions(+), 334 deletions(-) create mode 100644 cotisations/migrations/0030_custom_payment.py delete mode 100644 cotisations/migrations/0030_paiement_allow_self_subscription.py delete mode 100644 cotisations/migrations/0031_article_allow_self_subscription.py delete mode 100644 cotisations/migrations/0032_chequepayment_comnpaypayment.py delete mode 100644 cotisations/migrations/0033_balancepayment.py delete mode 100644 cotisations/migrations/0034_auto_20180703_0929.py delete mode 100644 cotisations/migrations/0035_auto_20180703_1005.py delete mode 100644 cotisations/migrations/0036_auto_20180703_1056.py delete mode 100644 cotisations/migrations/0037_auto_20180703_1202.py delete mode 100644 cotisations/migrations/0038_paiement_is_balance.py delete mode 100644 cotisations/migrations/0039_auto_20180704_1147.py delete mode 100644 cotisations/migrations/0040_auto_20180705_0822.py diff --git a/cotisations/migrations/0030_custom_payment.py b/cotisations/migrations/0030_custom_payment.py new file mode 100644 index 00000000..b81dab4b --- /dev/null +++ b/cotisations/migrations/0030_custom_payment.py @@ -0,0 +1,123 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10.7 on 2018-07-02 18:56 +from __future__ import unicode_literals + +import re2o.aes_field +import cotisations.payment_methods.mixins +from django.db import migrations, models +import django.db.models.deletion + + +def add_cheque(apps, schema_editor): + ChequePayment = apps.get_model('cotisations', 'ChequePayment') + Payment = apps.get_model('cotisations', 'Paiement') + for p in Payment.objects.filter(type_paiement=1): + cheque = ChequePayment() + cheque.payment = p + cheque.save() + + +def add_comnpay(apps, schema_editor): + ComnpayPayment = apps.get_model('cotisations', 'ComnpayPayment') + Payment = apps.get_model('cotisations', 'Paiement') + AssoOption = apps.get_model('preferences', 'AssoOption') + options, _created = AssoOption.objects.get_or_create() + try: + payment = Payment.objects.get( + moyen='Rechargement en ligne' + ) + except Payment.DoesNotExist: + return + comnpay = ComnpayPayment() + comnpay.payment_user = options.payment_id + comnpay.payment = payment + comnpay.save() + payment.moyen = "ComnPay" + + payment.save() + + +def add_solde(apps, schema_editor): + OptionalUser = apps.get_model('preferences', 'OptionalUser') + options, _created = OptionalUser.objects.get_or_create() + + Payment = apps.get_model('cotisations', 'Paiement') + BalancePayment = apps.get_model('cotisations', 'BalancePayment') + + try: + solde = Payment.objects.get(moyen="solde") + except Payment.DoesNotExist: + return + balance = BalancePayment() + balance.payment = solde + balance.minimum_balance = options.solde_negatif + balance.maximum_balance = options.max_solde + solde.is_balance = True + balance.save() + solde.save() + + +class Migration(migrations.Migration): + + dependencies = [ + ('preferences', '0044_remove_payment_pass'), + ('cotisations', '0029_auto_20180414_2056'), + ] + + operations = [ + migrations.AlterModelOptions( + name='paiement', + options={'permissions': (('view_paiement', "Can see a payement's details"), ('use_every_payment', 'Can use a payement')), 'verbose_name': 'Payment method', 'verbose_name_plural': 'Payment methods'}, + ), + migrations.AlterModelOptions( + name='article', + options={'permissions': (('view_article', "Can see an article's details"), ('buy_every_article', 'Can buy every_article')), 'verbose_name': 'Article', 'verbose_name_plural': 'Articles'}, + ), + migrations.AddField( + model_name='paiement', + name='available_for_everyone', + field=models.BooleanField(default=False, verbose_name='Is available for every user'), + ), + migrations.AddField( + model_name='paiement', + name='is_balance', + field=models.BooleanField(default=False, editable=False, help_text='There should be only one balance payment method.', verbose_name='Is user balance', validators=[cotisations.models.check_no_balance]), + ), + migrations.AddField( + model_name='article', + name='available_for_everyone', + field=models.BooleanField(default=False, verbose_name='Is available for every user'), + ), + migrations.CreateModel( + name='ChequePayment', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('payment', models.OneToOneField(editable=False, on_delete=django.db.models.deletion.CASCADE, related_name='payment_method', to='cotisations.Paiement')), + ], + bases=(cotisations.payment_methods.mixins.PaymentMethodMixin, models.Model), + ), + migrations.CreateModel( + name='ComnpayPayment', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('payment_credential', models.CharField(blank=True, default='', max_length=255, verbose_name='ComNpay VAD Number')), + ('payment_pass', re2o.aes_field.AESEncryptedField(blank=True, max_length=255, null=True, verbose_name='ComNpay Secret Key')), + ('payment', models.OneToOneField(editable=False, on_delete=django.db.models.deletion.CASCADE, related_name='payment_method', to='cotisations.Paiement')), + ], + bases=(cotisations.payment_methods.mixins.PaymentMethodMixin, models.Model), + ), + migrations.CreateModel( + name='BalancePayment', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('minimum_balance', models.DecimalField(decimal_places=2, default=0, help_text='The minimal amount of money allowed for the balance at the end of a payment. You can specify negative amount.', max_digits=5, verbose_name='Minimum balance')), + ('payment', models.OneToOneField(editable=False, on_delete=django.db.models.deletion.CASCADE, related_name='payment_method', to='cotisations.Paiement')), + ('maximum_balance', models.DecimalField(decimal_places=2, default=50, help_text='The maximal amount of money allowed for the balance.', max_digits=5, verbose_name='Maximum balance')), + ], + bases=(cotisations.payment_methods.mixins.PaymentMethodMixin, models.Model), + ), + migrations.RunPython(add_comnpay), + migrations.RunPython(add_cheque), + migrations.RunPython(add_solde) + + ] diff --git a/cotisations/migrations/0030_paiement_allow_self_subscription.py b/cotisations/migrations/0030_paiement_allow_self_subscription.py deleted file mode 100644 index 4e9ab60b..00000000 --- a/cotisations/migrations/0030_paiement_allow_self_subscription.py +++ /dev/null @@ -1,20 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.10.7 on 2018-06-17 14:59 -from __future__ import unicode_literals - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ('cotisations', '0029_auto_20180414_2056'), - ] - - operations = [ - migrations.AddField( - model_name='paiement', - name='allow_self_subscription', - field=models.BooleanField(default=False, verbose_name='Is available for self subscription'), - ), - ] diff --git a/cotisations/migrations/0031_article_allow_self_subscription.py b/cotisations/migrations/0031_article_allow_self_subscription.py deleted file mode 100644 index 64764edf..00000000 --- a/cotisations/migrations/0031_article_allow_self_subscription.py +++ /dev/null @@ -1,20 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.10.7 on 2018-06-17 17:13 -from __future__ import unicode_literals - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ('cotisations', '0030_paiement_allow_self_subscription'), - ] - - operations = [ - migrations.AddField( - model_name='article', - name='allow_self_subscription', - field=models.BooleanField(default=False, verbose_name='Is available for self subscription'), - ), - ] diff --git a/cotisations/migrations/0032_chequepayment_comnpaypayment.py b/cotisations/migrations/0032_chequepayment_comnpaypayment.py deleted file mode 100644 index 2277efb4..00000000 --- a/cotisations/migrations/0032_chequepayment_comnpaypayment.py +++ /dev/null @@ -1,65 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.10.7 on 2018-07-02 18:56 -from __future__ import unicode_literals - -import re2o.aes_field -import cotisations.payment_methods.mixins -from django.db import migrations, models -import django.db.models.deletion - - -def add_cheque(apps, schema_editor): - ChequePayment = apps.get_model('cotisations', 'ChequePayment') - Payment = apps.get_model('cotisations', 'Paiement') - for p in Payment.objects.filter(type_paiement=1): - cheque = ChequePayment() - cheque.payment = p - cheque.save() - - -def add_comnpay(apps, schema_editor): - ComnpayPayment = apps.get_model('cotisations', 'ComnpayPayment') - Payment = apps.get_model('cotisations', 'Paiement') - AssoOption = apps.get_model('preferences', 'AssoOption') - options, _created = AssoOption.objects.get_or_create() - payment, _created = Payment.objects.get_or_create( - moyen='Rechargement en ligne' - ) - comnpay = ComnpayPayment() - comnpay.payment_user = options.payment_id - comnpay.payment = payment - comnpay.save() - payment.moyen = "ComnPay" - - payment.save() - - -class Migration(migrations.Migration): - - dependencies = [ - ('preferences', '0044_remove_payment_pass'), - ('cotisations', '0031_article_allow_self_subscription'), - ] - - operations = [ - migrations.CreateModel( - name='ChequePayment', - fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('payment', models.OneToOneField(editable=False, on_delete=django.db.models.deletion.CASCADE, related_name='payment_method', to='cotisations.Paiement')), - ], - bases=(cotisations.payment_methods.mixins.PaymentMethodMixin, models.Model), - ), - migrations.CreateModel( - name='ComnpayPayment', - fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('payment_credential', models.CharField(blank=True, default='', max_length=255)), - ('payment_pass', re2o.aes_field.AESEncryptedField(blank=True, max_length=255, null=True)), - ('payment', models.OneToOneField(editable=False, on_delete=django.db.models.deletion.CASCADE, related_name='payment_method', to='cotisations.Paiement')), - ], - bases=(cotisations.payment_methods.mixins.PaymentMethodMixin, models.Model), - ), - migrations.RunPython(add_comnpay), - migrations.RunPython(add_cheque), - ] diff --git a/cotisations/migrations/0033_balancepayment.py b/cotisations/migrations/0033_balancepayment.py deleted file mode 100644 index 9308a7b0..00000000 --- a/cotisations/migrations/0033_balancepayment.py +++ /dev/null @@ -1,41 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.10.7 on 2018-07-03 13:53 -from __future__ import unicode_literals - -import cotisations.payment_methods.mixins -from django.db import migrations, models -import django.db.models.deletion - - -def add_solde(apps, schema_editor): - OptionalUser = apps.get_model('preferences', 'OptionalUser') - options, _created = OptionalUser.objects.get_or_create() - - Payment = apps.get_model('cotisations', 'Paiement') - BalancePayment = apps.get_model('cotisations', 'BalancePayment') - - solde, _created = Payment.objects.get_or_create(moyen="solde") - balance = BalancePayment() - balance.payment = solde - balance.minimum_balance = options.solde_negatif - balance.save() - - -class Migration(migrations.Migration): - - dependencies = [ - ('cotisations', '0032_chequepayment_comnpaypayment'), - ] - - operations = [ - migrations.CreateModel( - name='BalancePayment', - fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('minimum_balance', models.DecimalField(decimal_places=2, help_text='The minimal amount of money allowed for the balance at the end of a payment. You can specify negative amount.', max_digits=5, verbose_name='Minimum balance')), - ('payment', models.OneToOneField(editable=False, on_delete=django.db.models.deletion.CASCADE, related_name='payment_method', to='cotisations.Paiement')), - ], - bases=(cotisations.payment_methods.mixins.PaymentMethodMixin, models.Model), - ), - migrations.RunPython(add_solde) - ] diff --git a/cotisations/migrations/0034_auto_20180703_0929.py b/cotisations/migrations/0034_auto_20180703_0929.py deleted file mode 100644 index aa3ca10f..00000000 --- a/cotisations/migrations/0034_auto_20180703_0929.py +++ /dev/null @@ -1,26 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.10.7 on 2018-07-03 14:29 -from __future__ import unicode_literals - -import re2o.aes_field -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ('cotisations', '0033_balancepayment'), - ] - - operations = [ - migrations.AlterField( - model_name='comnpaypayment', - name='payment_credential', - field=models.CharField(blank=True, default='', max_length=255, verbose_name='ComNpay VAD Number'), - ), - migrations.AlterField( - model_name='comnpaypayment', - name='payment_pass', - field=re2o.aes_field.AESEncryptedField(blank=True, max_length=255, null=True, verbose_name='ComNpay Secret Key'), - ), - ] diff --git a/cotisations/migrations/0035_auto_20180703_1005.py b/cotisations/migrations/0035_auto_20180703_1005.py deleted file mode 100644 index 3b741d27..00000000 --- a/cotisations/migrations/0035_auto_20180703_1005.py +++ /dev/null @@ -1,28 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.10.7 on 2018-07-03 15:05 -from __future__ import unicode_literals - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ('cotisations', '0034_auto_20180703_0929'), - ] - - operations = [ - migrations.AlterModelOptions( - name='paiement', - options={'permissions': (('view_paiement', "Can see a payement's details"), ('use', 'Can use a payement')), 'verbose_name': 'Payment method', 'verbose_name_plural': 'Payment methods'}, - ), - migrations.RemoveField( - model_name='paiement', - name='allow_self_subscription', - ), - migrations.AddField( - model_name='paiement', - name='available_for_everyone', - field=models.BooleanField(default=False, verbose_name='Is available for every user'), - ), - ] diff --git a/cotisations/migrations/0036_auto_20180703_1056.py b/cotisations/migrations/0036_auto_20180703_1056.py deleted file mode 100644 index d14f20ad..00000000 --- a/cotisations/migrations/0036_auto_20180703_1056.py +++ /dev/null @@ -1,28 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.10.7 on 2018-07-03 15:56 -from __future__ import unicode_literals - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ('cotisations', '0035_auto_20180703_1005'), - ] - - operations = [ - migrations.AlterModelOptions( - name='article', - options={'permissions': (('view_article', "Can see an article's details"), ('buy_every_article', 'Can buy every_article')), 'verbose_name': 'Article', 'verbose_name_plural': 'Articles'}, - ), - migrations.RemoveField( - model_name='article', - name='allow_self_subscription', - ), - migrations.AddField( - model_name='article', - name='available_for_everyone', - field=models.BooleanField(default=False, verbose_name='Is available for every user'), - ), - ] diff --git a/cotisations/migrations/0037_auto_20180703_1202.py b/cotisations/migrations/0037_auto_20180703_1202.py deleted file mode 100644 index 3860ef87..00000000 --- a/cotisations/migrations/0037_auto_20180703_1202.py +++ /dev/null @@ -1,35 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.10.7 on 2018-07-03 17:02 -from __future__ import unicode_literals - -from django.db import migrations, models - -def create_max_balance(apps, schema_editor): - OptionalUser = apps.get_model('preferences', 'OptionalUser') - Payment = apps.get_model('cotisations', 'Paiement') - - balance, _created = Payment.objects.get_or_create(moyen='solde') - options, _created = OptionalUser.objects.get_or_create() - - balance.maximum_balance = options.max_solde - balance.save() - - -class Migration(migrations.Migration): - - dependencies = [ - ('cotisations', '0036_auto_20180703_1056'), - ] - - operations = [ - migrations.AlterModelOptions( - name='paiement', - options={'permissions': (('view_paiement', "Can see a payement's details"), ('use_every_payment', 'Can use every payement')), 'verbose_name': 'Payment method', 'verbose_name_plural': 'Payment methods'}, - ), - migrations.AddField( - model_name='balancepayment', - name='maximum_balance', - field=models.DecimalField(decimal_places=2, default=50, help_text='The maximal amount of money allowed for the balance.', max_digits=5, verbose_name='Maximum balance'), - ), - migrations.RunPython(create_max_balance) - ] diff --git a/cotisations/migrations/0038_paiement_is_balance.py b/cotisations/migrations/0038_paiement_is_balance.py deleted file mode 100644 index bea02a17..00000000 --- a/cotisations/migrations/0038_paiement_is_balance.py +++ /dev/null @@ -1,29 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.10.7 on 2018-07-04 16:30 -from __future__ import unicode_literals - -from django.db import migrations, models - -def update_balance(apps, _): - Payment = apps.get_model('cotisations', 'Paiement') - try: - balance = Payment.objects.get(moyen="solde") - balance.is_balance = True - balance.save() - except Payment.DoesNotExist: - pass - -class Migration(migrations.Migration): - - dependencies = [ - ('cotisations', '0037_auto_20180703_1202'), - ] - - operations = [ - migrations.AddField( - model_name='paiement', - name='is_balance', - field=models.BooleanField(default=False, editable=False, help_text='There should be only one balance payment method.', verbose_name='Is user balance'), - ), - migrations.RunPython(update_balance) - ] diff --git a/cotisations/migrations/0039_auto_20180704_1147.py b/cotisations/migrations/0039_auto_20180704_1147.py deleted file mode 100644 index 3f982430..00000000 --- a/cotisations/migrations/0039_auto_20180704_1147.py +++ /dev/null @@ -1,21 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.10.7 on 2018-07-04 16:47 -from __future__ import unicode_literals - -import cotisations.models -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ('cotisations', '0038_paiement_is_balance'), - ] - - operations = [ - migrations.AlterField( - model_name='paiement', - name='is_balance', - field=models.BooleanField(default=False, editable=False, help_text='There should be only one balance payment method.', validators=[cotisations.models.check_no_balance], verbose_name='Is user balance'), - ), - ] diff --git a/cotisations/migrations/0040_auto_20180705_0822.py b/cotisations/migrations/0040_auto_20180705_0822.py deleted file mode 100644 index 31b0652a..00000000 --- a/cotisations/migrations/0040_auto_20180705_0822.py +++ /dev/null @@ -1,20 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.10.7 on 2018-07-05 13:22 -from __future__ import unicode_literals - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ('cotisations', '0039_auto_20180704_1147'), - ] - - operations = [ - migrations.AlterField( - model_name='balancepayment', - name='minimum_balance', - field=models.DecimalField(decimal_places=2, default=0, help_text='The minimal amount of money allowed for the balance at the end of a payment. You can specify negative amount.', max_digits=5, verbose_name='Minimum balance'), - ), - ] diff --git a/preferences/migrations/0045_remove_unused_payment_fields.py b/preferences/migrations/0045_remove_unused_payment_fields.py index 49c628d4..6944f58c 100644 --- a/preferences/migrations/0045_remove_unused_payment_fields.py +++ b/preferences/migrations/0045_remove_unused_payment_fields.py @@ -9,7 +9,7 @@ class Migration(migrations.Migration): dependencies = [ ('preferences', '0044_remove_payment_pass'), - ('cotisations', '0032_chequepayment_comnpaypayment'), + ('cotisations', '0030_custom_payment'), ] operations = [