From 78d1de9031ca56288692d5676134053948cc5d13 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Sat, 8 Aug 2020 22:37:00 +0200 Subject: [PATCH] Remove orderrecord Signed-off-by: Nico Schottelius --- .../migrations/0008_delete_orderrecord.py | 16 ++++++++ uncloud_pay/models.py | 41 ++----------------- uncloud_pay/serializers.py | 6 --- uncloud_pay/tests.py | 19 ++++++++- 4 files changed, 37 insertions(+), 45 deletions(-) create mode 100644 uncloud_pay/migrations/0008_delete_orderrecord.py diff --git a/uncloud_pay/migrations/0008_delete_orderrecord.py b/uncloud_pay/migrations/0008_delete_orderrecord.py new file mode 100644 index 0000000..074210a --- /dev/null +++ b/uncloud_pay/migrations/0008_delete_orderrecord.py @@ -0,0 +1,16 @@ +# Generated by Django 3.1 on 2020-08-08 20:36 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('uncloud_pay', '0007_remove_bill_bill_records'), + ] + + operations = [ + migrations.DeleteModel( + name='OrderRecord', + ), + ] diff --git a/uncloud_pay/models.py b/uncloud_pay/models.py index 9de1631..2cbfd0f 100644 --- a/uncloud_pay/models.py +++ b/uncloud_pay/models.py @@ -412,6 +412,7 @@ class Bill(models.Model): # Calculate the start date if last_bill: + # TODO: check that last bill is finished/closed, if not continue using it starting_date = last_bill.end_date + datetime.timedelta(seconds=1) else: if first_order: @@ -436,7 +437,9 @@ class Bill(models.Model): order=order, starting_date=starting_date, ending_date=ending_date) - pass + + # Bill all active, recurring orders + #if order. return bill @@ -544,42 +547,6 @@ class BillRecord(models.Model): return f"{self.bill}: {self.quantity} x {self.order}" -class OrderRecord(models.Model): - """ - Order records store billing informations for products: the actual product - might be mutated and/or moved to another order but we do not want to loose - the details of old orders. - - Used as source of trust to dynamically generate bill entries. - """ - - order = models.ForeignKey(Order, on_delete=models.CASCADE) - - one_time_price = 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 - - @property - def starting_date(self): - return self.order.starting_date - - @property - def ending_date(self): - return self.order.ending_date - - ### # Products diff --git a/uncloud_pay/serializers.py b/uncloud_pay/serializers.py index 5ee5ad5..e00541c 100644 --- a/uncloud_pay/serializers.py +++ b/uncloud_pay/serializers.py @@ -37,12 +37,6 @@ class CreatePaymentMethodSerializer(serializers.ModelSerializer): ### # Orders & Products. -class OrderRecordSerializer(serializers.ModelSerializer): - class Meta: - model = OrderRecord - fields = ['one_time_price', 'recurring_price', 'description'] - - class OrderSerializer(serializers.ModelSerializer): owner = serializers.PrimaryKeyRelatedField(queryset=get_user_model().objects.all()) diff --git a/uncloud_pay/tests.py b/uncloud_pay/tests.py index 6dc0aeb..b9fb23e 100644 --- a/uncloud_pay/tests.py +++ b/uncloud_pay/tests.py @@ -12,6 +12,14 @@ class ProductActivationTestCase(TestCase): username='jdoe', email='john.doe@domain.tld') + self.recurring_user = get_user_model().objects.create( + username='recurrent_product_user', + email='jane.doe@domain.tld') + + self.user_without_address = get_user_model().objects.create( + username='no_home_person', + email='far.away@domain.tld') + self.billing_address = BillingAddress.objects.create( owner=self.user, organization = 'Test org', @@ -19,6 +27,13 @@ class ProductActivationTestCase(TestCase): city="unknown", postal_code="unknown") + self.billing_address = BillingAddress.objects.create( + owner=self.recurring_user, + organization = 'Test org', + street="Somewhere", + city="Else", + postal_code="unknown") + self.order_meta = {} self.order_meta[1] = { 'starting_date': timezone.make_aware(datetime.datetime(2020,3,3)), @@ -46,9 +61,9 @@ class ProductActivationTestCase(TestCase): self.assertEqual(self.one_time_order.billrecord_set.count(), 1) - def test_bill_sum(self): + def test_bill_sum_onetime(self): """ - Ensure there is only 1 bill record per order + Check the bill sum for a single one time order """ bill = Bill.create_next_bill_for_user(self.user)