enhancement: ensure subscription is cancelled before attempting to restart

This commit is contained in:
tundebabzy 2018-03-03 07:37:59 +01:00
parent e13570f343
commit d43422c18e
2 changed files with 18 additions and 5 deletions

View File

@ -410,11 +410,14 @@ class Subscriptions(Document):
subscription and the `Subscription` will lose all the history of generated invoices
it has.
"""
self.status = 'Active'
self.db_set('start', nowdate())
self.update_subscription_period(nowdate())
self.invoices = []
self.save()
if self.status == 'Canceled':
self.status = 'Active'
self.db_set('start', nowdate())
self.update_subscription_period(nowdate())
self.invoices = []
self.save()
else:
frappe.throw(_('You cannot restart a Subscription that is not cancelled.'))
def process_all():

View File

@ -447,3 +447,13 @@ class TestSubscriptions(unittest.TestCase):
settings.cancel_after_grace = default_grace_period_action
settings.save()
subscription.delete()
def test_restart_active_subscription(self):
subscription = frappe.new_doc('Subscriptions')
subscription.subscriber = '_Test Customer'
subscription.append('plans', {'plan': '_Test Plan Name'})
subscription.save()
self.assertRaises(frappe.ValidationError, subscription.restart_subscription)
subscription.delete()