Skip to content

Commit

Permalink
fix: unable to create partial invoice with auto fetch terms enabled
Browse files Browse the repository at this point in the history
With 'Automatically Fetch Payment Terms' enabled in Accounts Settings,
partial invoice creation from Orders wasn't possible, as the payment schedule
wasn't recalculated.
  • Loading branch information
ruthra-kumar committed May 13, 2023
1 parent ecc80a8 commit 2363dbc
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions erpnext/controllers/accounts_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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")
Expand Down

0 comments on commit 2363dbc

Please sign in to comment.