mirror of
https://github.com/frappe/erpnext.git
synced 2026-04-15 04:45:09 +00:00
fix: difference amount calculation on payment reconciliation
(cherry picked from commit 122d5f2729)
This commit is contained in:
@@ -8,7 +8,11 @@ from frappe.model.document import Document
|
|||||||
from frappe.utils import flt, getdate, nowdate, today
|
from frappe.utils import flt, getdate, nowdate, today
|
||||||
|
|
||||||
import erpnext
|
import erpnext
|
||||||
from erpnext.accounts.utils import get_outstanding_invoices, reconcile_against_document
|
from erpnext.accounts.utils import (
|
||||||
|
get_outstanding_invoices,
|
||||||
|
reconcile_against_document,
|
||||||
|
update_reference_in_payment_entry,
|
||||||
|
)
|
||||||
from erpnext.controllers.accounts_controller import get_advance_payment_entries
|
from erpnext.controllers.accounts_controller import get_advance_payment_entries
|
||||||
|
|
||||||
|
|
||||||
@@ -190,6 +194,23 @@ class PaymentReconciliation(Document):
|
|||||||
inv.currency = entry.get("currency")
|
inv.currency = entry.get("currency")
|
||||||
inv.outstanding_amount = flt(entry.get("outstanding_amount"))
|
inv.outstanding_amount = flt(entry.get("outstanding_amount"))
|
||||||
|
|
||||||
|
def get_difference_amount(self, allocated_entry):
|
||||||
|
if allocated_entry.get("reference_type") != "Payment Entry":
|
||||||
|
return
|
||||||
|
|
||||||
|
dr_or_cr = (
|
||||||
|
"credit_in_account_currency"
|
||||||
|
if erpnext.get_party_account_type(self.party_type) == "Receivable"
|
||||||
|
else "debit_in_account_currency"
|
||||||
|
)
|
||||||
|
|
||||||
|
row = self.get_payment_details(allocated_entry, dr_or_cr)
|
||||||
|
|
||||||
|
doc = frappe.get_doc(allocated_entry.reference_type, allocated_entry.reference_name)
|
||||||
|
update_reference_in_payment_entry(row, doc, do_not_save=True)
|
||||||
|
|
||||||
|
return doc.difference_amount
|
||||||
|
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
def allocate_entries(self, args):
|
def allocate_entries(self, args):
|
||||||
self.validate_entries()
|
self.validate_entries()
|
||||||
@@ -205,12 +226,16 @@ class PaymentReconciliation(Document):
|
|||||||
res = self.get_allocated_entry(pay, inv, pay["amount"])
|
res = self.get_allocated_entry(pay, inv, pay["amount"])
|
||||||
inv["outstanding_amount"] = flt(inv.get("outstanding_amount")) - flt(pay.get("amount"))
|
inv["outstanding_amount"] = flt(inv.get("outstanding_amount")) - flt(pay.get("amount"))
|
||||||
pay["amount"] = 0
|
pay["amount"] = 0
|
||||||
|
|
||||||
|
res.difference_amount = self.get_difference_amount(res)
|
||||||
|
|
||||||
if pay.get("amount") == 0:
|
if pay.get("amount") == 0:
|
||||||
entries.append(res)
|
entries.append(res)
|
||||||
break
|
break
|
||||||
elif inv.get("outstanding_amount") == 0:
|
elif inv.get("outstanding_amount") == 0:
|
||||||
entries.append(res)
|
entries.append(res)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
else:
|
else:
|
||||||
break
|
break
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user