fix: reset dr_or_cr for every reference
diff --git a/erpnext/accounts/doctype/payment_entry/payment_entry.py b/erpnext/accounts/doctype/payment_entry/payment_entry.py
index 2634972..448224b 100644
--- a/erpnext/accounts/doctype/payment_entry/payment_entry.py
+++ b/erpnext/accounts/doctype/payment_entry/payment_entry.py
@@ -1054,9 +1054,9 @@
item=self,
)
- dr_or_cr = "credit" if self.payment_type == "Receive" else "debit"
-
for d in self.get("references"):
+ # re-defining dr_or_cr for every reference in order to avoid the last value affecting calculation of reverse
+ dr_or_cr = "credit" if self.payment_type == "Receive" else "debit"
cost_center = self.cost_center
if d.reference_doctype == "Sales Invoice" and not cost_center:
cost_center = frappe.db.get_value(d.reference_doctype, d.reference_name, "cost_center")
@@ -1072,7 +1072,7 @@
against_voucher_type = d.reference_doctype
against_voucher = d.reference_name
- reverse_dr_or_cr, standalone_note = 0, 0
+ reverse_dr_or_cr = 0
if d.reference_doctype in ["Sales Invoice", "Purchase Invoice"]:
is_return = frappe.db.get_value(d.reference_doctype, d.reference_name, "is_return")
payable_party_types = get_party_types_from_account_type("Payable")
@@ -1098,6 +1098,7 @@
)
gl_entries.append(gle)
+ dr_or_cr = "credit" if self.payment_type == "Receive" else "debit"
if self.unallocated_amount:
exchange_rate = self.get_exchange_rate()
base_unallocated_amount = self.unallocated_amount * exchange_rate