sets Subscription doc status in before_save

This commit is contained in:
tundebabzy 2018-02-26 15:55:32 +01:00
parent 3010996cc5
commit 7a2c6df645

View File

@ -27,3 +27,18 @@ class Subscriptions(Document):
def set_current_invoice_end(self):
self.current_invoice_end = get_last_day(self.current_invoice_start)
def before_save(self):
self.set_status()
def set_status(self):
if self.is_trialling():
self.status = 'Trialling'
elif self.status == 'Past Due' and self.is_past_grace_period():
self.status = 'Canceled' if cint(SUBSCRIPTION_SETTINGS.cancel_after_grace) else 'Unpaid'
elif self.current_invoice_is_past_due():
self.status = 'Past Due'
elif self.is_new_subscription():
self.status = 'Active'
# todo: then generate new invoice