more tests and bug fix
diff --git a/erpnext/accounts/doctype/subscriptions/subscriptions.py b/erpnext/accounts/doctype/subscriptions/subscriptions.py
index 9a130f3..eed4e87 100644
--- a/erpnext/accounts/doctype/subscriptions/subscriptions.py
+++ b/erpnext/accounts/doctype/subscriptions/subscriptions.py
@@ -9,9 +9,6 @@
 from frappe import _
 
 
-SUBSCRIPTION_SETTINGS = frappe.get_single('Subscription Settings')
-
-
 class Subscriptions(Document):
 	def before_insert(self):
 		# update start just before the subscription doc is created
@@ -81,14 +78,16 @@
 			return data
 
 	def set_status_grace_period(self):
+		subscription_settings = frappe.get_single('Subscription Settings')
 		if self.status == 'Past Due Date' and self.is_past_grace_period():
-			self.status = 'Canceled' if cint(SUBSCRIPTION_SETTINGS.cancel_after_grace) else 'Unpaid'
+			self.status = 'Canceled' if cint(subscription_settings.cancel_after_grace) else 'Unpaid'
 
 	def set_subscription_status(self):
 		if self.is_trialling():
 			self.status = 'Trialling'
 		elif self.status == 'Past Due Date' and self.is_past_grace_period():
-			self.status = 'Canceled' if cint(SUBSCRIPTION_SETTINGS.cancel_after_grace) else 'Unpaid'
+			subscription_settings = frappe.get_single('Subscription Settings')
+			self.status = 'Canceled' if cint(subscription_settings.cancel_after_grace) else 'Unpaid'
 		elif self.status == 'Past Due Date' and not self.has_outstanding_invoice():
 			self.status = 'Active'
 		elif self.current_invoice_is_past_due():
@@ -111,7 +110,8 @@
 	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)
+			subscription_settings = frappe.get_single('Subscription Settings')
+			grace_period = cint(subscription_settings.grace_period)
 
 			return getdate(nowdate()) > add_days(current_invoice.due_date, grace_period)
 
diff --git a/erpnext/accounts/doctype/subscriptions/test_subscriptions.py b/erpnext/accounts/doctype/subscriptions/test_subscriptions.py
index 63177e4..01d05d2 100644
--- a/erpnext/accounts/doctype/subscriptions/test_subscriptions.py
+++ b/erpnext/accounts/doctype/subscriptions/test_subscriptions.py
@@ -173,6 +173,29 @@
 		settings.save()
 		subscription.delete()
 
+	def test_subscription_unpaid_after_grace_period(self):
+		settings = frappe.get_single('Subscription Settings')
+		default_grace_period_action = settings.cancel_after_grace
+		settings.cancel_after_grace = 0
+		settings.save()
+
+		subscription = frappe.new_doc('Subscriptions')
+		subscription.subscriber = '_Test Customer'
+		subscription.append('plans', {'plan': '_Test Plan Name'})
+		subscription.insert()
+		subscription.set_current_invoice_start('2018-01-01')
+		subscription.set_current_invoice_end()
+		subscription.process()	# generate first invoice
+
+		self.assertEqual(subscription.status, 'Past Due Date')
+
+		subscription.process()	
+		# This should change status to Canceled since grace period is 0
+		self.assertEqual(subscription.status, 'Unpaid')
+
+		settings.cancel_after_grace = default_grace_period_action
+		settings.save()
+		subscription.delete()
 
 	def test_subscription_invoice_days_until_due(self):
 		subscription = frappe.new_doc('Subscriptions')