more tests and bug fixes
diff --git a/erpnext/accounts/doctype/subscriptions/subscriptions.py b/erpnext/accounts/doctype/subscriptions/subscriptions.py
index 15e4611..02a30a8 100644
--- a/erpnext/accounts/doctype/subscriptions/subscriptions.py
+++ b/erpnext/accounts/doctype/subscriptions/subscriptions.py
@@ -273,10 +273,11 @@
invoice.additional_discount_percentage = self.additional_discount_percentage
if self.additional_discount_amount:
- invoice.additional_discount_amount = self.additional_discount_amount
+ invoice.discount_amount = self.additional_discount_amount
- if not self.apply_additional_discount and (self.additional_discount_percentage or self.additional_discount_amount):
- self.apply_additional_discount = 'Grand Total'
+ if self.additional_discount_percentage or self.additional_discount_amount:
+ discount_on = self.apply_additional_discount
+ invoice.apply_additional_discount = discount_on if discount_on else 'Grand Total'
invoice.save()
invoice.submit()
diff --git a/erpnext/accounts/doctype/subscriptions/test_subscriptions.py b/erpnext/accounts/doctype/subscriptions/test_subscriptions.py
index fb92d86..b290f00 100644
--- a/erpnext/accounts/doctype/subscriptions/test_subscriptions.py
+++ b/erpnext/accounts/doctype/subscriptions/test_subscriptions.py
@@ -186,7 +186,7 @@
self.assertEqual(subscription.status, 'Past Due Date')
- subscription.process()
+ subscription.process()
# This should change status to Canceled since grace period is 0
self.assertEqual(subscription.status, 'Unpaid')
@@ -465,3 +465,33 @@
self.assertRaises(frappe.ValidationError, subscription.restart_subscription)
subscription.delete()
+
+ def test_subscription_invoice_discount_percentage(self):
+ subscription = frappe.new_doc('Subscriptions')
+ subscription.subscriber = '_Test Customer'
+ subscription.additional_discount_percentage = 10
+ subscription.append('plans', {'plan': '_Test Plan Name'})
+ subscription.save()
+ subscription.cancel_subscription()
+
+ invoice = subscription.get_current_invoice()
+
+ self.assertEqual(invoice.additional_discount_percentage, 10)
+ self.assertEqual(invoice.apply_discount_on, 'Grand Total')
+
+ subscription.delete()
+
+ def test_subscription_invoice_discount_amount(self):
+ subscription = frappe.new_doc('Subscriptions')
+ subscription.subscriber = '_Test Customer'
+ subscription.additional_discount_amount = 11
+ subscription.append('plans', {'plan': '_Test Plan Name'})
+ subscription.save()
+ subscription.cancel_subscription()
+
+ invoice = subscription.get_current_invoice()
+
+ self.assertEqual(invoice.discount_amount, 11)
+ self.assertEqual(invoice.apply_discount_on, 'Grand Total')
+
+ subscription.delete()