Merge pull request #17546 from rohitwaghchaure/incorrect_payment_amount_if_advance_amount_in_si_develop
fix: incorrect payment amount in the payment terms if the sales invoice has the advance amount
diff --git a/erpnext/accounts/doctype/purchase_invoice/test_purchase_invoice.py b/erpnext/accounts/doctype/purchase_invoice/test_purchase_invoice.py
index dde12d7..b4d584f 100644
--- a/erpnext/accounts/doctype/purchase_invoice/test_purchase_invoice.py
+++ b/erpnext/accounts/doctype/purchase_invoice/test_purchase_invoice.py
@@ -402,9 +402,9 @@
pi.save()
pi.submit()
- self.assertEqual(pi.payment_schedule[0].payment_amount, 756.15)
+ self.assertEqual(pi.payment_schedule[0].payment_amount, 606.15)
self.assertEqual(pi.payment_schedule[0].due_date, pi.posting_date)
- self.assertEqual(pi.payment_schedule[1].payment_amount, 756.15)
+ self.assertEqual(pi.payment_schedule[1].payment_amount, 606.15)
self.assertEqual(pi.payment_schedule[1].due_date, add_days(pi.posting_date, 30))
pi.load_from_db()
diff --git a/erpnext/controllers/accounts_controller.py b/erpnext/controllers/accounts_controller.py
index 155a996..0672b2d 100644
--- a/erpnext/controllers/accounts_controller.py
+++ b/erpnext/controllers/accounts_controller.py
@@ -787,6 +787,9 @@
if self.doctype in ("Sales Invoice", "Purchase Invoice"):
grand_total = grand_total - flt(self.write_off_amount)
+ if self.get("total_advance"):
+ grand_total -= self.get("total_advance")
+
if not self.get("payment_schedule"):
if self.get("payment_terms_template"):
data = get_payment_terms(self.payment_terms_template, posting_date, grand_total)
@@ -832,6 +835,9 @@
total = flt(total, self.precision("grand_total"))
grand_total = flt(self.get("rounded_total") or self.grand_total, self.precision('grand_total'))
+ if self.get("total_advance"):
+ grand_total -= self.get("total_advance")
+
if self.doctype in ("Sales Invoice", "Purchase Invoice"):
grand_total = grand_total - flt(self.write_off_amount)
if total != grand_total: