adds validation:
- ensure trial period dates are in order
This commit is contained in:
parent
7a2c6df645
commit
b72aac6729
@ -42,3 +42,33 @@ class Subscriptions(Document):
|
|||||||
self.status = 'Active'
|
self.status = 'Active'
|
||||||
# todo: then generate new invoice
|
# todo: then generate new invoice
|
||||||
|
|
||||||
|
def is_past_grace_period(self):
|
||||||
|
current_invoice = self.get_current_invoice()
|
||||||
|
if self.current_invoice_is_past_due(current_invoice):
|
||||||
|
grace_period = cint(SUBSCRIPTION_SETTINGS.grace_period)
|
||||||
|
|
||||||
|
return nowdate() > add_days(current_invoice.due_date, grace_period)
|
||||||
|
|
||||||
|
def current_invoice_is_past_due(self, current_invoice=None):
|
||||||
|
if not current_invoice:
|
||||||
|
current_invoice = self.get_current_invoice()
|
||||||
|
|
||||||
|
if not current_invoice:
|
||||||
|
return False
|
||||||
|
else:
|
||||||
|
return nowdate() > current_invoice.due_date
|
||||||
|
|
||||||
|
def is_new_subscription(self):
|
||||||
|
return len(self.invoices) == 0
|
||||||
|
|
||||||
|
def validate(self):
|
||||||
|
self.validate_trial_period()
|
||||||
|
|
||||||
|
def validate_trial_period(self):
|
||||||
|
if self.trial_period_start and self.trial_period_end:
|
||||||
|
if getdate(self.trial_period_end) > getdate(self.trial_period_start):
|
||||||
|
frappe.throw(_('Trial Period End Date Cannot be before Trial Period Start Date'))
|
||||||
|
|
||||||
|
elif self.trial_period_start or self.trial_period_end:
|
||||||
|
frappe.throw(_('Both Trial Period Start Date and Trial Period End Date must be set'))
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user