[product] migrate orders to ManyToManyField

This commit is contained in:
Nico Schottelius 2020-08-09 14:44:29 +02:00
parent 8df1d8dc7c
commit 2b29e300dd
2 changed files with 5 additions and 19 deletions

View file

@ -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):

View file

@ -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)