mirror of
https://github.com/frappe/erpnext.git
synced 2026-10-29 22:57:42 +00:00
fix(accounts): use receivable currency for dunning payments
This commit is contained in:
@@ -323,12 +323,12 @@ class Dunning(AccountsController):
|
||||
self.precision("dunning_amount"),
|
||||
)
|
||||
|
||||
def get_unpaid_overdue_payments(self):
|
||||
def get_unpaid_overdue_payments(self, in_account_currency=False):
|
||||
"""Overdue payments with their outstanding as of now, not as of dunning creation."""
|
||||
return [
|
||||
(row, outstanding)
|
||||
for row in self.overdue_payments
|
||||
if (outstanding := get_current_outstanding(row)) > 0
|
||||
if (outstanding := get_current_outstanding(row, in_account_currency=in_account_currency)) > 0
|
||||
]
|
||||
|
||||
def before_cancel(self):
|
||||
@@ -519,12 +519,12 @@ def get_paid_dunning_amount(dunning: str) -> float:
|
||||
return -flt(paid[0][0]) if paid else 0.0
|
||||
|
||||
|
||||
def get_current_outstanding(overdue_payment) -> float:
|
||||
"""Outstanding of an overdue payment as of now, in the invoice's transaction currency."""
|
||||
def get_current_outstanding(overdue_payment, in_account_currency=False) -> float:
|
||||
"""Return the live outstanding in transaction currency, or in receivable-account currency."""
|
||||
invoice = frappe.db.get_value(
|
||||
"Sales Invoice",
|
||||
overdue_payment.sales_invoice,
|
||||
["outstanding_amount", "currency", "party_account_currency"],
|
||||
["outstanding_amount", "currency", "party_account_currency", "conversion_rate"],
|
||||
as_dict=True,
|
||||
)
|
||||
if overdue_payment.payment_schedule:
|
||||
@@ -543,7 +543,11 @@ def get_current_outstanding(overdue_payment) -> float:
|
||||
return 0.0
|
||||
|
||||
outstanding = min(schedule_outstanding, flt(overdue_payment.outstanding))
|
||||
if invoice.currency == invoice.party_account_currency:
|
||||
if in_account_currency and invoice.currency != invoice.party_account_currency:
|
||||
outstanding = flt(
|
||||
outstanding * flt(invoice.conversion_rate), overdue_payment.precision("outstanding")
|
||||
)
|
||||
if in_account_currency or invoice.currency == invoice.party_account_currency:
|
||||
outstanding = min(outstanding, flt(invoice.outstanding_amount))
|
||||
|
||||
return outstanding
|
||||
|
||||
@@ -2835,7 +2835,7 @@ def get_payment_entry(
|
||||
pe.append("references", reference)
|
||||
else:
|
||||
if dt == "Dunning":
|
||||
for overdue_payment, outstanding in doc.get_unpaid_overdue_payments():
|
||||
for overdue_payment, outstanding in doc.get_unpaid_overdue_payments(in_account_currency=True):
|
||||
pe.append(
|
||||
"references",
|
||||
{
|
||||
@@ -3153,8 +3153,14 @@ def set_grand_total_and_outstanding_amount(party_amount, dt, party_account_curre
|
||||
outstanding_amount = doc.outstanding_amount
|
||||
elif dt == "Dunning":
|
||||
# only what is left to collect, the totals on the dunning are the ones it was raised with
|
||||
grand_total = sum(outstanding for _row, outstanding in doc.get_unpaid_overdue_payments())
|
||||
grand_total += doc.get_unpaid_dunning_amount()
|
||||
grand_total = sum(
|
||||
outstanding for _row, outstanding in doc.get_unpaid_overdue_payments(in_account_currency=True)
|
||||
)
|
||||
grand_total += (
|
||||
doc.get_unpaid_dunning_amount()
|
||||
if party_account_currency == doc.currency
|
||||
else doc.get_unpaid_base_dunning_amount()
|
||||
)
|
||||
outstanding_amount = grand_total
|
||||
else:
|
||||
if party_account_currency == doc.company_currency:
|
||||
|
||||
Reference in New Issue
Block a user