mirror of
https://github.com/frappe/erpnext.git
synced 2026-10-29 22:57:42 +00:00
fix(accounts): keep paid amount in payment term outstanding on update items
This commit is contained in:
@@ -92,6 +92,7 @@ class PaymentScheduleService:
|
||||
and allocate_payment_based_on_payment_terms
|
||||
and self.linked_order_has_payment_terms(po_or_so, fieldname, doctype)
|
||||
):
|
||||
keep_settled = doc.docstatus == 1 and getattr(doc, "_action", None) != "submit"
|
||||
for d in doc.get("payment_schedule"):
|
||||
if d.invoice_portion:
|
||||
d.payment_amount = flt(
|
||||
@@ -100,20 +101,30 @@ class PaymentScheduleService:
|
||||
d.base_payment_amount = flt(
|
||||
base_grand_total * flt(d.invoice_portion) / 100, d.precision("base_payment_amount")
|
||||
)
|
||||
d.outstanding = d.payment_amount
|
||||
d.base_outstanding = d.base_payment_amount
|
||||
elif not d.invoice_portion:
|
||||
d.base_payment_amount = flt(
|
||||
d.payment_amount * doc.get("conversion_rate"), d.precision("base_payment_amount")
|
||||
)
|
||||
d.outstanding = d.payment_amount
|
||||
d.base_outstanding = d.base_payment_amount
|
||||
self.set_term_outstanding(d, keep_settled)
|
||||
else:
|
||||
self.fetch_payment_terms_from_order(
|
||||
po_or_so, doctype, grand_total, base_grand_total, automatically_fetch_payment_terms
|
||||
)
|
||||
doc.ignore_default_payment_terms_template = 1
|
||||
|
||||
def set_term_outstanding(self, term, keep_settled: bool) -> None:
|
||||
settled = base_settled = 0
|
||||
if keep_settled:
|
||||
settled = flt(term.paid_amount) + flt(term.discounted_amount)
|
||||
base_settled = flt(term.base_paid_amount) + flt(term.discounted_amount) * flt(
|
||||
self.doc.get("conversion_rate")
|
||||
)
|
||||
|
||||
term.outstanding = flt(term.payment_amount - settled, term.precision("outstanding"))
|
||||
term.base_outstanding = flt(
|
||||
term.base_payment_amount - base_settled, term.precision("base_outstanding")
|
||||
)
|
||||
|
||||
def get_order_details(self) -> tuple:
|
||||
doc = self.doc
|
||||
if not doc.get("items"):
|
||||
|
||||
Reference in New Issue
Block a user