From 2363dbc25568124e34b777d8dddf63acc64a74e8 Mon Sep 17 00:00:00 2001 From: ruthra kumar Date: Sat, 13 May 2023 09:33:16 +0530 Subject: [PATCH] fix: unable to create partial invoice with auto fetch terms enabled With 'Automatically Fetch Payment Terms' enabled in Accounts Settings, partial invoice creation from Orders wasn't possible, as the payment schedule wasn't recalculated. --- erpnext/controllers/accounts_controller.py | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/erpnext/controllers/accounts_controller.py b/erpnext/controllers/accounts_controller.py index d0ec654162378..f041e047b48c9 100644 --- a/erpnext/controllers/accounts_controller.py +++ b/erpnext/controllers/accounts_controller.py @@ -1662,11 +1662,8 @@ def set_payment_schedule(self): ) self.append("payment_schedule", data) - if not ( - automatically_fetch_payment_terms - and self.linked_order_has_payment_terms(po_or_so, fieldname, doctype) - ): - for d in self.get("payment_schedule"): + def _set_schedule(doc): + for d in doc.get("payment_schedule"): if d.invoice_portion: d.payment_amount = flt( grand_total * flt(d.invoice_portion / 100), d.precision("payment_amount") @@ -1677,9 +1674,21 @@ def set_payment_schedule(self): d.outstanding = d.payment_amount elif not d.invoice_portion: d.base_payment_amount = flt( - d.payment_amount * self.get("conversion_rate"), d.precision("base_payment_amount") + d.payment_amount * doc.get("conversion_rate"), d.precision("base_payment_amount") ) + if not ( + automatically_fetch_payment_terms + and self.linked_order_has_payment_terms(po_or_so, fieldname, doctype) + ): + _set_schedule(self) + else: + # if partial invoice, set schedule + if self.doctype in ["Purchase Invoice", "Sales Invoice"]: + po_or_so_total_qty = frappe.db.get_value(doctype, po_or_so, "total_qty") + if po_or_so_total_qty != self.total_qty: + _set_schedule(self) + def get_order_details(self): if self.doctype == "Sales Invoice": po_or_so = self.get("items")[0].get("sales_order")