more tests and bug fixes

This commit is contained in:
tundebabzy 2018-03-03 11:19:18 +01:00
parent 024c28acf7
commit fbdd5d30e9
2 changed files with 35 additions and 4 deletions

View File

@ -273,10 +273,11 @@ class Subscriptions(Document):
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()

View File

@ -186,7 +186,7 @@ class TestSubscriptions(unittest.TestCase):
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 @@ class TestSubscriptions(unittest.TestCase):
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()