refactor: supplementary field to better handle reverse payments

(cherry picked from commit bdd36b0001)

# Conflicts:
#	erpnext/accounts/doctype/payment_entry_reference/payment_entry_reference.json
This commit is contained in:
ruthra kumar
2024-04-05 09:56:15 +05:30
committed by Mergify
parent f3eb559a71
commit d9826e3dfc
3 changed files with 37 additions and 9 deletions

View File

@@ -1210,15 +1210,7 @@ class PaymentEntry(AccountsController):
return "credit", reference.account return "credit", reference.account
if reference.reference_doctype == "Payment Entry": if reference.reference_doctype == "Payment Entry":
reverse_payment_details = frappe.db.get_all( if reference.account_type == "Receivable" and reference.payment_type == "Pay":
"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 return "credit", self.party_account
else: else:
return "debit", self.party_account return "debit", self.party_account
@@ -2114,6 +2106,10 @@ def get_reference_details(reference_doctype, reference_name, party_account_curre
ref_doc.company ref_doc.company
) )
# Only applies for Reverse Payment Entries
account_type = None
payment_type = None
if reference_doctype == "Dunning": if reference_doctype == "Dunning":
total_amount = outstanding_amount = ref_doc.get("dunning_amount") total_amount = outstanding_amount = ref_doc.get("dunning_amount")
exchange_rate = 1 exchange_rate = 1
@@ -2128,6 +2124,18 @@ def get_reference_details(reference_doctype, reference_name, party_account_curre
exchange_rate = 1 exchange_rate = 1
outstanding_amount = get_outstanding_on_journal_entry(reference_name) 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": elif reference_doctype != "Journal Entry":
if not total_amount: if not total_amount:
if party_account_currency == company_currency: if party_account_currency == company_currency:
@@ -2172,6 +2180,8 @@ def get_reference_details(reference_doctype, reference_name, party_account_curre
"outstanding_amount": flt(outstanding_amount), "outstanding_amount": flt(outstanding_amount),
"exchange_rate": flt(exchange_rate), "exchange_rate": flt(exchange_rate),
"bill_no": ref_doc.get("bill_no"), "bill_no": ref_doc.get("bill_no"),
"account_type": account_type,
"payment_type": payment_type,
} }
) )
if account: if account:

View File

@@ -10,6 +10,8 @@
"due_date", "due_date",
"bill_no", "bill_no",
"payment_term", "payment_term",
"account_type",
"payment_type",
"column_break_4", "column_break_4",
"total_amount", "total_amount",
"outstanding_amount", "outstanding_amount",
@@ -108,12 +110,26 @@
"fieldtype": "Link", "fieldtype": "Link",
"label": "Account", "label": "Account",
"options": "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, "index_web_pages_for_search": 1,
"istable": 1, "istable": 1,
"links": [], "links": [],
<<<<<<< HEAD
"modified": "2023-06-08 07:40:38.487874", "modified": "2023-06-08 07:40:38.487874",
=======
"modified": "2024-04-05 09:44:08.310593",
>>>>>>> bdd36b0001 (refactor: supplementary field to better handle reverse payments)
"modified_by": "Administrator", "modified_by": "Administrator",
"module": "Accounts", "module": "Accounts",
"name": "Payment Entry Reference", "name": "Payment Entry Reference",

View File

@@ -15,6 +15,7 @@ class PaymentEntryReference(Document):
from frappe.types import DF from frappe.types import DF
account: DF.Link | None account: DF.Link | None
account_type: DF.Data | None
allocated_amount: DF.Float allocated_amount: DF.Float
bill_no: DF.Data | None bill_no: DF.Data | None
due_date: DF.Date | None due_date: DF.Date | None
@@ -25,6 +26,7 @@ class PaymentEntryReference(Document):
parentfield: DF.Data parentfield: DF.Data
parenttype: DF.Data parenttype: DF.Data
payment_term: DF.Link | None payment_term: DF.Link | None
payment_type: DF.Data | None
reference_doctype: DF.Link reference_doctype: DF.Link
reference_name: DF.DynamicLink reference_name: DF.DynamicLink
total_amount: DF.Float total_amount: DF.Float