mirror of
https://github.com/frappe/erpnext.git
synced 2026-02-17 08:35:00 +00:00
fix: invalid ledger entries on payment against reverse payments
On Advance payments booked on separate party account, reconciliation against a reverse payment posted invalid ledger entries.
This commit is contained in:
@@ -1316,6 +1316,26 @@ class PaymentEntry(AccountsController):
|
||||
):
|
||||
self.add_advance_gl_for_reference(gl_entries, ref)
|
||||
|
||||
def get_dr_and_account_for_advances(self, reference):
|
||||
if reference.reference_doctype == "Sales Invoice":
|
||||
return "credit", reference.account
|
||||
|
||||
if reference.reference_doctype == "Payment Entry":
|
||||
reverse_payment_details = frappe.db.get_all(
|
||||
"Payment Entry",
|
||||
filters={"name": reference.reference_name},
|
||||
fields=["payment_type", "party_type"],
|
||||
)[0]
|
||||
if (
|
||||
reverse_payment_details.payment_type == "Pay"
|
||||
and reverse_payment_details.party_type == "Customer"
|
||||
):
|
||||
return "credit", self.party_account
|
||||
else:
|
||||
return "debit", self.party_account
|
||||
|
||||
return "debit", reference.account
|
||||
|
||||
def add_advance_gl_for_reference(self, gl_entries, invoice):
|
||||
args_dict = {
|
||||
"party_type": self.party_type,
|
||||
@@ -1335,8 +1355,8 @@ class PaymentEntry(AccountsController):
|
||||
if getdate(posting_date) < getdate(self.posting_date):
|
||||
posting_date = self.posting_date
|
||||
|
||||
dr_or_cr = "credit" if invoice.reference_doctype in ["Sales Invoice", "Payment Entry"] else "debit"
|
||||
args_dict["account"] = invoice.account
|
||||
dr_or_cr, account = self.get_dr_and_account_for_advances(invoice)
|
||||
args_dict["account"] = account
|
||||
args_dict[dr_or_cr] = invoice.allocated_amount
|
||||
args_dict[dr_or_cr + "_in_account_currency"] = invoice.allocated_amount
|
||||
args_dict.update(
|
||||
|
||||
Reference in New Issue
Block a user