diff --git a/erpnext/accounts/doctype/payment_entry/payment_entry.py b/erpnext/accounts/doctype/payment_entry/payment_entry.py index b990260e391..faba0be9c5c 100644 --- a/erpnext/accounts/doctype/payment_entry/payment_entry.py +++ b/erpnext/accounts/doctype/payment_entry/payment_entry.py @@ -1321,15 +1321,7 @@ class PaymentEntry(AccountsController): 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" - ): + if reference.account_type == "Receivable" and reference.payment_type == "Pay": return "credit", self.party_account else: return "debit", self.party_account @@ -2214,6 +2206,10 @@ def get_reference_details(reference_doctype, reference_name, party_account_curre ref_doc = frappe.get_doc(reference_doctype, reference_name) company_currency = ref_doc.get("company_currency") or erpnext.get_company_currency(ref_doc.company) + # Only applies for Reverse Payment Entries + account_type = None + payment_type = None + if reference_doctype == "Dunning": total_amount = outstanding_amount = ref_doc.get("dunning_amount") exchange_rate = 1 @@ -2226,6 +2222,18 @@ def get_reference_details(reference_doctype, reference_name, party_account_curre exchange_rate = 1 outstanding_amount = get_outstanding_on_journal_entry(reference_name) + elif reference_doctype == "Payment Entry": + if reverse_payment_details := frappe.db.get_all( + "Payment Entry", + filters={"name": reference_name}, + fields=["payment_type", "party_type"], + )[0]: + payment_type = reverse_payment_details.payment_type + account_type = frappe.db.get_value( + "Party Type", reverse_payment_details.party_type, "account_type" + ) + exchange_rate = 1 + elif reference_doctype != "Journal Entry": if not total_amount: if party_account_currency == company_currency: @@ -2270,6 +2278,8 @@ def get_reference_details(reference_doctype, reference_name, party_account_curre "outstanding_amount": flt(outstanding_amount), "exchange_rate": flt(exchange_rate), "bill_no": ref_doc.get("bill_no"), + "account_type": account_type, + "payment_type": payment_type, } ) if account: diff --git a/erpnext/accounts/doctype/payment_entry_reference/payment_entry_reference.json b/erpnext/accounts/doctype/payment_entry_reference/payment_entry_reference.json index e518009b061..352ece24f06 100644 --- a/erpnext/accounts/doctype/payment_entry_reference/payment_entry_reference.json +++ b/erpnext/accounts/doctype/payment_entry_reference/payment_entry_reference.json @@ -10,6 +10,8 @@ "due_date", "bill_no", "payment_term", + "account_type", + "payment_type", "column_break_4", "total_amount", "outstanding_amount", @@ -108,12 +110,22 @@ "fieldtype": "Link", "label": "Account", "options": "Account" + }, + { + "fieldname": "account_type", + "fieldtype": "Data", + "label": "Account Type" + }, + { + "fieldname": "payment_type", + "fieldtype": "Data", + "label": "Payment Type" } ], "index_web_pages_for_search": 1, "istable": 1, "links": [], - "modified": "2024-03-27 13:10:09.578312", + "modified": "2024-04-05 09:44:08.310593", "modified_by": "Administrator", "module": "Accounts", "name": "Payment Entry Reference", diff --git a/erpnext/accounts/doctype/payment_entry_reference/payment_entry_reference.py b/erpnext/accounts/doctype/payment_entry_reference/payment_entry_reference.py index 13707e53efc..4a027b4ee32 100644 --- a/erpnext/accounts/doctype/payment_entry_reference/payment_entry_reference.py +++ b/erpnext/accounts/doctype/payment_entry_reference/payment_entry_reference.py @@ -15,6 +15,7 @@ class PaymentEntryReference(Document): from frappe.types import DF account: DF.Link | None + account_type: DF.Data | None allocated_amount: DF.Float bill_no: DF.Data | None due_date: DF.Date | None @@ -25,6 +26,7 @@ class PaymentEntryReference(Document): parentfield: DF.Data parenttype: DF.Data payment_term: DF.Link | None + payment_type: DF.Data | None reference_doctype: DF.Link reference_name: DF.DynamicLink total_amount: DF.Float