++stuff
This commit is contained in:
parent
d2bd6ba200
commit
9b00ef11fb
3 changed files with 33 additions and 4 deletions
|
|
@ -581,6 +581,16 @@ class Product(UncloudModel):
|
|||
# Default period for all products
|
||||
default_recurring_period = RecurringPeriod.PER_30D
|
||||
|
||||
def create_order_at(self, when_to_start, *args, **kwargs):
|
||||
billing_address = BillingAddress.get_address_for(self.owner)
|
||||
|
||||
order = Order.objects.create(owner=self.owner,
|
||||
billing_address=billing_address,
|
||||
starting_date=when_to_start,
|
||||
one_time_price=self.one_time_price,
|
||||
recurring_period=self.default_recurring_period,
|
||||
recurring_price=self.recurring_price,
|
||||
description=str(self))
|
||||
|
||||
def create_or_update_order(self, when_to_start=None):
|
||||
if not when_to_start:
|
||||
|
|
@ -620,8 +630,8 @@ class Product(UncloudModel):
|
|||
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
# Create order the first time a product is created
|
||||
if self._state.adding:
|
||||
# Create order if there is none already
|
||||
if not self.order:
|
||||
self.create_or_update_order()
|
||||
|
||||
super().save(*args, **kwargs)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue