From bcd141730d7ba3adcef27e182a6bb64524f68c48 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Sat, 23 May 2020 23:38:34 +0200 Subject: [PATCH] convert recurring period into an integerfield Signed-off-by: Nico Schottelius --- .../migrations/0015_auto_20200523_2132.py | 26 +++++++++++++++++++ .../migrations/0016_auto_20200523_2138.py | 23 ++++++++++++++++ uncloud_pay/models.py | 11 ++++---- 3 files changed, 54 insertions(+), 6 deletions(-) create mode 100644 uncloud_pay/migrations/0015_auto_20200523_2132.py create mode 100644 uncloud_pay/migrations/0016_auto_20200523_2138.py diff --git a/uncloud_pay/migrations/0015_auto_20200523_2132.py b/uncloud_pay/migrations/0015_auto_20200523_2132.py new file mode 100644 index 0000000..90a241d --- /dev/null +++ b/uncloud_pay/migrations/0015_auto_20200523_2132.py @@ -0,0 +1,26 @@ +# Generated by Django 3.0.6 on 2020-05-23 21:32 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('uncloud_pay', '0014_paymentsettings'), + ] + + operations = [ + migrations.AlterField( + model_name='order', + name='recurring_period', + field=models.CharField(choices=[(31536000, 'Per 365 days'), (2592000, 'Per 30 days'), (604800, 'Per Week'), (86400, 'Per Day'), (3600, 'Per Hour'), (60, 'Per Minute'), (1, 'Per Second'), (0, 'Onetime')], default=2592000, max_length=32), + ), + migrations.AlterField( + model_name='ordertimothee', + name='recurring_period', + field=models.CharField(choices=[(31536000, 'Per 365 days'), (2592000, 'Per 30 days'), (604800, 'Per Week'), (86400, 'Per Day'), (3600, 'Per Hour'), (60, 'Per Minute'), (1, 'Per Second'), (0, 'Onetime')], default=2592000, max_length=32), + ), + migrations.DeleteModel( + name='PaymentSettings', + ), + ] diff --git a/uncloud_pay/migrations/0016_auto_20200523_2138.py b/uncloud_pay/migrations/0016_auto_20200523_2138.py new file mode 100644 index 0000000..bcfdd3c --- /dev/null +++ b/uncloud_pay/migrations/0016_auto_20200523_2138.py @@ -0,0 +1,23 @@ +# Generated by Django 3.0.6 on 2020-05-23 21:38 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('uncloud_pay', '0015_auto_20200523_2132'), + ] + + operations = [ + migrations.AlterField( + model_name='order', + name='recurring_period', + field=models.IntegerField(choices=[(31536000, 'Per 365 days'), (2592000, 'Per 30 days'), (604800, 'Per Week'), (86400, 'Per Day'), (3600, 'Per Hour'), (60, 'Per Minute'), (1, 'Per Second'), (0, 'Onetime')], default=2592000), + ), + migrations.AlterField( + model_name='ordertimothee', + name='recurring_period', + field=models.IntegerField(choices=[(31536000, 'Per 365 days'), (2592000, 'Per 30 days'), (604800, 'Per Week'), (86400, 'Per Day'), (3600, 'Per Hour'), (60, 'Per Minute'), (1, 'Per Second'), (0, 'Onetime')], default=2592000), + ), + ] diff --git a/uncloud_pay/models.py b/uncloud_pay/models.py index 85c280b..8e6f4e1 100644 --- a/uncloud_pay/models.py +++ b/uncloud_pay/models.py @@ -315,8 +315,9 @@ class BillNico(models.Model): for order in Order.objects.filter(~Q(recurring_period=RecurringPeriod.ONE_TIME), Q(starting_date__lt=self.starting_date), owner=owner): - pass + if order.recurring_period > 0: # avoid div/0 - these are one time payments + pass @@ -661,8 +662,7 @@ class Order(models.Model): editable=False, blank=True) - recurring_period = models.CharField(max_length=32, - choices = RecurringPeriod.choices, default = RecurringPeriod.PER_30D) + recurring_period = models.IntegerField(choices = RecurringPeriod.choices, default = RecurringPeriod.PER_30D) one_time_price = models.DecimalField(default=0.0, max_digits=AMOUNT_MAX_DIGITS, @@ -766,9 +766,8 @@ class OrderTimothee(models.Model): editable=False, blank=True) - recurring_period = models.CharField(max_length=32, - choices = RecurringPeriod.choices, - default = RecurringPeriod.PER_30D) + recurring_period = models.IntegerField(choices = RecurringPeriod.choices, + default = RecurringPeriod.PER_30D) # Trigger initial bill generation at order creation. def save(self, *args, **kwargs):