adds validation:
- ensure trial period dates are in order
diff --git a/erpnext/accounts/doctype/subscriptions/subscriptions.py b/erpnext/accounts/doctype/subscriptions/subscriptions.py
index 98f1548..435c364 100644
--- a/erpnext/accounts/doctype/subscriptions/subscriptions.py
+++ b/erpnext/accounts/doctype/subscriptions/subscriptions.py
@@ -42,3 +42,33 @@
self.status = 'Active'
# 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'))
+