diff --git a/erpnext/accounts/doctype/payment_reconciliation/payment_reconciliation.py b/erpnext/accounts/doctype/payment_reconciliation/payment_reconciliation.py index bbbb3c978ff..68e9eef711a 100644 --- a/erpnext/accounts/doctype/payment_reconciliation/payment_reconciliation.py +++ b/erpnext/accounts/doctype/payment_reconciliation/payment_reconciliation.py @@ -211,12 +211,14 @@ class PaymentReconciliation(Document): if self.get("cost_center"): conditions.append(jea.cost_center == self.cost_center) - dr_or_cr = ( - "credit_in_account_currency" - if erpnext.get_party_account_type(self.party_type) == "Receivable" - else "debit_in_account_currency" - ) - conditions.append(jea[dr_or_cr].gt(0)) + account_type = erpnext.get_party_account_type(self.party_type) + + if account_type == "Receivable": + dr_or_cr = jea.credit_in_account_currency - jea.debit_in_account_currency + elif account_type == "Payable": + dr_or_cr = jea.debit_in_account_currency - jea.credit_in_account_currency + + conditions.append(dr_or_cr.gt(0)) if self.bank_cash_account: conditions.append(jea.against_account.like(f"%%{self.bank_cash_account}%%")) @@ -231,7 +233,7 @@ class PaymentReconciliation(Document): je.posting_date, je.remark.as_("remarks"), jea.name.as_("reference_row"), - jea[dr_or_cr].as_("amount"), + dr_or_cr.as_("amount"), jea.is_advance, jea.exchange_rate, jea.account_currency.as_("currency"), diff --git a/erpnext/accounts/utils.py b/erpnext/accounts/utils.py index 37dbaef51a8..144039b794f 100644 --- a/erpnext/accounts/utils.py +++ b/erpnext/accounts/utils.py @@ -630,6 +630,16 @@ def update_reference_in_journal_entry(d, journal_entry, do_not_save=False): if jv_detail.get("reference_type") in ["Sales Order", "Purchase Order"]: update_advance_paid.append((jv_detail.reference_type, jv_detail.reference_name)) + rev_dr_or_cr = ( + "debit_in_account_currency" + if d["dr_or_cr"] == "credit_in_account_currency" + else "credit_in_account_currency" + ) + if jv_detail.get(rev_dr_or_cr): + d["dr_or_cr"] = rev_dr_or_cr + d["allocated_amount"] = d["allocated_amount"] * -1 + d["unadjusted_amount"] = d["unadjusted_amount"] * -1 + if flt(d["unadjusted_amount"]) - flt(d["allocated_amount"]) != 0: # adjust the unreconciled balance amount_in_account_currency = flt(d["unadjusted_amount"]) - flt(d["allocated_amount"])