diff --git a/uncloud_pay/models.py b/uncloud_pay/models.py index 1eb2071..d1c03e7 100644 --- a/uncloud_pay/models.py +++ b/uncloud_pay/models.py @@ -615,19 +615,6 @@ class Product(UncloudModel): description = "Generic Product" orders = models.ManyToManyField(Order) - # one_time_order = models.ForeignKey(Order, - # on_delete=models.CASCADE, - # editable=True, - # null=True, - # related_name='product_one_time') - - # recurring_order = models.ForeignKey(Order, - # on_delete=models.CASCADE, - # editable=True, - # null=True, - # related_name='product_recurring') - - # FIXME: editable=True -> is in the admin, but also editable in DRF status = models.CharField(max_length=32, choices=UncloudStatus.choices, @@ -656,6 +643,7 @@ class Product(UncloudModel): price=self.one_time_price, recurring_period=RecurringPeriod.ONE_TIME, description=str(self)) + self.orders.add(one_time_order) else: one_time_order = None @@ -675,6 +663,7 @@ class Product(UncloudModel): price=self.recurring_price, recurring_period=recurring_period, description=str(self)) + self.orders.add(recurring_order) def create_or_update_order(self, when_to_start=None, recurring_period=None): diff --git a/uncloud_pay/tests.py b/uncloud_pay/tests.py index dbbedf4..9aa86ef 100644 --- a/uncloud_pay/tests.py +++ b/uncloud_pay/tests.py @@ -41,25 +41,22 @@ class ProductTestCase(TestCase): """ # One order - p = SampleOneTimeProduct(owner=self.user) + p = SampleOneTimeProduct.objects.create(owner=self.user) p.create_order_at(timezone.make_aware(datetime.datetime(2020,3,3))) - p.save() order_count = Order.objects.filter(owner=self.user).count() self.assertEqual(order_count, 1) # One more order - p = SampleRecurringProduct(owner=self.user) + p = SampleRecurringProduct.objects.create(owner=self.user) p.create_order_at(timezone.make_aware(datetime.datetime(2020,3,3))) - p.save() order_count = Order.objects.filter(owner=self.user).count() self.assertEqual(order_count, 2) # Should create 2 orders - p = SampleRecurringProductOneTimeFee(owner=self.user) + p = SampleRecurringProductOneTimeFee.objects.create(owner=self.user) p.create_order_at(timezone.make_aware(datetime.datetime(2020,3,3))) - p.save() order_count = Order.objects.filter(owner=self.user).count() self.assertEqual(order_count, 4)