forked from uncloud/uncloud
[product] migrate orders to ManyToManyField
This commit is contained in:
parent
8df1d8dc7c
commit
2b29e300dd
2 changed files with 5 additions and 19 deletions
|
@ -615,19 +615,6 @@ class Product(UncloudModel):
|
||||||
description = "Generic Product"
|
description = "Generic Product"
|
||||||
|
|
||||||
orders = models.ManyToManyField(Order)
|
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,
|
status = models.CharField(max_length=32,
|
||||||
choices=UncloudStatus.choices,
|
choices=UncloudStatus.choices,
|
||||||
|
@ -656,6 +643,7 @@ class Product(UncloudModel):
|
||||||
price=self.one_time_price,
|
price=self.one_time_price,
|
||||||
recurring_period=RecurringPeriod.ONE_TIME,
|
recurring_period=RecurringPeriod.ONE_TIME,
|
||||||
description=str(self))
|
description=str(self))
|
||||||
|
self.orders.add(one_time_order)
|
||||||
else:
|
else:
|
||||||
one_time_order = None
|
one_time_order = None
|
||||||
|
|
||||||
|
@ -675,6 +663,7 @@ class Product(UncloudModel):
|
||||||
price=self.recurring_price,
|
price=self.recurring_price,
|
||||||
recurring_period=recurring_period,
|
recurring_period=recurring_period,
|
||||||
description=str(self))
|
description=str(self))
|
||||||
|
self.orders.add(recurring_order)
|
||||||
|
|
||||||
|
|
||||||
def create_or_update_order(self, when_to_start=None, recurring_period=None):
|
def create_or_update_order(self, when_to_start=None, recurring_period=None):
|
||||||
|
|
|
@ -41,25 +41,22 @@ class ProductTestCase(TestCase):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# One order
|
# 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.create_order_at(timezone.make_aware(datetime.datetime(2020,3,3)))
|
||||||
p.save()
|
|
||||||
|
|
||||||
order_count = Order.objects.filter(owner=self.user).count()
|
order_count = Order.objects.filter(owner=self.user).count()
|
||||||
self.assertEqual(order_count, 1)
|
self.assertEqual(order_count, 1)
|
||||||
|
|
||||||
# One more order
|
# 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.create_order_at(timezone.make_aware(datetime.datetime(2020,3,3)))
|
||||||
p.save()
|
|
||||||
|
|
||||||
order_count = Order.objects.filter(owner=self.user).count()
|
order_count = Order.objects.filter(owner=self.user).count()
|
||||||
self.assertEqual(order_count, 2)
|
self.assertEqual(order_count, 2)
|
||||||
|
|
||||||
# Should create 2 orders
|
# 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.create_order_at(timezone.make_aware(datetime.datetime(2020,3,3)))
|
||||||
p.save()
|
|
||||||
|
|
||||||
order_count = Order.objects.filter(owner=self.user).count()
|
order_count = Order.objects.filter(owner=self.user).count()
|
||||||
self.assertEqual(order_count, 4)
|
self.assertEqual(order_count, 4)
|
||||||
|
|
Loading…
Reference in a new issue