From 8e41b894c030ad549b8130c3eeec873005a44ccc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Floure?= Date: Mon, 2 Mar 2020 08:09:42 +0100 Subject: [PATCH] Add OrderRecord model --- .../migrations/0012_orderrecord.py | 25 +++++++++++++++++++ uncloud/uncloud_pay/models.py | 23 +++++++++++++---- 2 files changed, 43 insertions(+), 5 deletions(-) create mode 100644 uncloud/uncloud_pay/migrations/0012_orderrecord.py diff --git a/uncloud/uncloud_pay/migrations/0012_orderrecord.py b/uncloud/uncloud_pay/migrations/0012_orderrecord.py new file mode 100644 index 0000000..7c655e4 --- /dev/null +++ b/uncloud/uncloud_pay/migrations/0012_orderrecord.py @@ -0,0 +1,25 @@ +# Generated by Django 3.0.3 on 2020-03-01 16:04 + +import django.core.validators +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('uncloud_pay', '0011_auto_20200229_1459'), + ] + + operations = [ + migrations.CreateModel( + name='OrderRecord', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('setup_fee', models.DecimalField(decimal_places=2, default=0.0, max_digits=10, validators=[django.core.validators.MinValueValidator(0)])), + ('recurring_price', models.DecimalField(decimal_places=2, default=0.0, max_digits=10, validators=[django.core.validators.MinValueValidator(0)])), + ('description', models.TextField()), + ('order', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='uncloud_pay.Order')), + ], + ), + ] diff --git a/uncloud/uncloud_pay/models.py b/uncloud/uncloud_pay/models.py index 8d4f14c..2862940 100644 --- a/uncloud/uncloud_pay/models.py +++ b/uncloud/uncloud_pay/models.py @@ -98,12 +98,25 @@ class Order(models.Model): @property def amount(self): - # amount = recurring_price - # if recurring and first_month: - # amount += one_time_price + records = OrderRecord.objects.filter(order=self) + return 1 - amount=1 - return amount +class OrderRecord(models.Model): + order = models.ForeignKey(Order, on_delete=models.CASCADE) + setup_fee = models.DecimalField(default=0.0, + max_digits=AMOUNT_MAX_DIGITS, + decimal_places=AMOUNT_DECIMALS, + validators=[MinValueValidator(0)]) + recurring_price = models.DecimalField(default=0.0, + max_digits=AMOUNT_MAX_DIGITS, + decimal_places=AMOUNT_DECIMALS, + validators=[MinValueValidator(0)]) + + description = models.TextField() + + @property + def recurring_period(self): + return self.order.recurring_period class PaymentMethod(models.Model): uuid = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)