erpnext
erpnext copied to clipboard
fix: negative outstanding amount in sales invoice
Information about bug
When you attempt to create payment entry using get_payment_entry from https://github.com/frappe/erpnext/blob/4ecce242a80a3cba7213ab7111ded8de7bb92081/erpnext/accounts/doctype/payment_entry/payment_entry.py#L1638 and send party_amount > outstanding_amount, it takes outstanding_amount to negative. If we send bank_amount and same account & company currency, then it also goes to negative.
Problem is emanating from https://github.com/frappe/erpnext/blob/4ecce242a80a3cba7213ab7111ded8de7bb92081/erpnext/accounts/doctype/payment_entry/payment_entry.py#L1827
def set_grand_total_and_outstanding_amount(party_amount, dt, party_account_currency, doc):
grand_total = outstanding_amount = 0
if party_amount:
grand_total = outstanding_amount = party_amount
elif dt in ("Sales Invoice", "Purchase Invoice"):
if party_account_currency == doc.company_currency:
grand_total = doc.base_rounded_total or doc.base_grand_total
else:
grand_total = doc.rounded_total or doc.grand_total
outstanding_amount = doc.outstanding_amount
elif dt == "Dunning":
grand_total = doc.grand_total
outstanding_amount = doc.grand_total
else:
if party_account_currency == doc.company_currency:
grand_total = flt(doc.get("base_rounded_total") or doc.get("base_grand_total"))
else:
grand_total = flt(doc.get("rounded_total") or doc.get("grand_total"))
outstanding_amount = doc.get("outstanding_amount") or (grand_total - flt(doc.advance_paid))
return grand_total, outstanding_amount
The fix is required in this part of the code.
Module
accounts
Version
ERPNext: v13.42.2 (version-13) Frappe Framework: v13.45.2 (version-13)
Installation method
FrappeCloud
Relevant log output / Stack trace / Full Error Message.
Not applicable