enhancement: ensure subscription is cancelled before attempting to restart
This commit is contained in:
parent
e13570f343
commit
d43422c18e
@ -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():
|
||||
|
@ -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()
|
||||
|
Loading…
Reference in New Issue
Block a user