From 7a2c6df645c9f747ae23d1e4699a1a0025c01889 Mon Sep 17 00:00:00 2001 From: tundebabzy Date: Mon, 26 Feb 2018 15:55:32 +0100 Subject: [PATCH] sets Subscription doc status in `before_save` --- .../doctype/subscriptions/subscriptions.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/erpnext/accounts/doctype/subscriptions/subscriptions.py b/erpnext/accounts/doctype/subscriptions/subscriptions.py index 353e83ddd5..98f154860c 100644 --- a/erpnext/accounts/doctype/subscriptions/subscriptions.py +++ b/erpnext/accounts/doctype/subscriptions/subscriptions.py @@ -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 +