fix: Fetch outstanding and total amount for reference journal entry
(cherry picked from commit f331f9b15c)
# Conflicts:
# erpnext/accounts/doctype/payment_entry/payment_entry.js
# erpnext/accounts/doctype/payment_entry/payment_entry.py
This commit is contained in:
@@ -1395,8 +1395,17 @@ frappe.ui.form.on('Payment Entry Reference', {
|
|||||||
args: {
|
args: {
|
||||||
reference_doctype: row.reference_doctype,
|
reference_doctype: row.reference_doctype,
|
||||||
reference_name: row.reference_name,
|
reference_name: row.reference_name,
|
||||||
|
<<<<<<< HEAD
|
||||||
party_account_currency: frm.doc.payment_type=="Receive" ?
|
party_account_currency: frm.doc.payment_type=="Receive" ?
|
||||||
frm.doc.paid_from_account_currency : frm.doc.paid_to_account_currency
|
frm.doc.paid_from_account_currency : frm.doc.paid_to_account_currency
|
||||||
|
=======
|
||||||
|
party_account_currency:
|
||||||
|
frm.doc.payment_type == "Receive"
|
||||||
|
? frm.doc.paid_from_account_currency
|
||||||
|
: frm.doc.paid_to_account_currency,
|
||||||
|
party_type: frm.doc.party_type,
|
||||||
|
party: frm.doc.party,
|
||||||
|
>>>>>>> f331f9b15c (fix: Fetch outstanding and total amount for reference journal entry)
|
||||||
},
|
},
|
||||||
callback: function(r, rt) {
|
callback: function(r, rt) {
|
||||||
if(r.message) {
|
if(r.message) {
|
||||||
|
|||||||
@@ -348,7 +348,11 @@ class PaymentEntry(AccountsController):
|
|||||||
continue
|
continue
|
||||||
|
|
||||||
ref_details = get_reference_details(
|
ref_details = get_reference_details(
|
||||||
d.reference_doctype, d.reference_name, self.party_account_currency
|
d.reference_doctype,
|
||||||
|
d.reference_name,
|
||||||
|
self.party_account_currency,
|
||||||
|
self.party_type,
|
||||||
|
self.party,
|
||||||
)
|
)
|
||||||
|
|
||||||
# Only update exchange rate when the reference is Journal Entry
|
# Only update exchange rate when the reference is Journal Entry
|
||||||
@@ -1883,34 +1887,48 @@ def get_company_defaults(company):
|
|||||||
return frappe.get_cached_value("Company", company, fields, as_dict=1)
|
return frappe.get_cached_value("Company", company, fields, as_dict=1)
|
||||||
|
|
||||||
|
|
||||||
def get_outstanding_on_journal_entry(name):
|
def get_outstanding_on_journal_entry(voucher_no, party_type, party):
|
||||||
gl = frappe.qb.DocType("GL Entry")
|
ple = frappe.qb.DocType("Payment Ledger Entry")
|
||||||
res = (
|
|
||||||
frappe.qb.from_(gl)
|
outstanding = (
|
||||||
.select(
|
frappe.qb.from_(ple)
|
||||||
Case()
|
.select(Sum(ple.amount_in_account_currency))
|
||||||
.when(
|
|
||||||
gl.party_type == "Customer",
|
|
||||||
Coalesce(Sum(gl.debit_in_account_currency - gl.credit_in_account_currency), 0),
|
|
||||||
)
|
|
||||||
.else_(Coalesce(Sum(gl.credit_in_account_currency - gl.debit_in_account_currency), 0))
|
|
||||||
.as_("outstanding_amount")
|
|
||||||
)
|
|
||||||
.where(
|
.where(
|
||||||
(Coalesce(gl.party_type, "") != "")
|
(ple.against_voucher_no == voucher_no)
|
||||||
& (gl.is_cancelled == 0)
|
& (ple.party_type == party_type)
|
||||||
& ((gl.voucher_no == name) | (gl.against_voucher == name))
|
& (ple.party == party)
|
||||||
|
& (ple.delinked == 0)
|
||||||
)
|
)
|
||||||
).run(as_dict=True)
|
).run()
|
||||||
|
|
||||||
outstanding_amount = res[0].get("outstanding_amount", 0) if res else 0
|
outstanding_amount = outstanding[0][0] if outstanding else 0
|
||||||
|
|
||||||
return outstanding_amount
|
total = (
|
||||||
|
frappe.qb.from_(ple)
|
||||||
|
.select(Sum(ple.amount_in_account_currency))
|
||||||
|
.where(
|
||||||
|
(ple.voucher_no == voucher_no)
|
||||||
|
& (ple.party_type == party_type)
|
||||||
|
& (ple.party == party)
|
||||||
|
& (ple.delinked == 0)
|
||||||
|
)
|
||||||
|
).run()
|
||||||
|
|
||||||
|
total_amount = total[0][0] if total else 0
|
||||||
|
|
||||||
|
return outstanding_amount, total_amount
|
||||||
|
|
||||||
|
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
|
<<<<<<< HEAD
|
||||||
def get_reference_details(reference_doctype, reference_name, party_account_currency):
|
def get_reference_details(reference_doctype, reference_name, party_account_currency):
|
||||||
total_amount = outstanding_amount = exchange_rate = None
|
total_amount = outstanding_amount = exchange_rate = None
|
||||||
|
=======
|
||||||
|
def get_reference_details(
|
||||||
|
reference_doctype, reference_name, party_account_currency, party_type=None, party=None
|
||||||
|
):
|
||||||
|
total_amount = outstanding_amount = exchange_rate = account = None
|
||||||
|
>>>>>>> f331f9b15c (fix: Fetch outstanding and total amount for reference journal entry)
|
||||||
|
|
||||||
ref_doc = frappe.get_doc(reference_doctype, reference_name)
|
ref_doc = frappe.get_doc(reference_doctype, reference_name)
|
||||||
company_currency = ref_doc.get("company_currency") or erpnext.get_company_currency(ref_doc.company)
|
company_currency = ref_doc.get("company_currency") or erpnext.get_company_currency(ref_doc.company)
|
||||||
@@ -1920,12 +1938,13 @@ def get_reference_details(reference_doctype, reference_name, party_account_curre
|
|||||||
exchange_rate = 1
|
exchange_rate = 1
|
||||||
|
|
||||||
elif reference_doctype == "Journal Entry" and ref_doc.docstatus == 1:
|
elif reference_doctype == "Journal Entry" and ref_doc.docstatus == 1:
|
||||||
total_amount = ref_doc.get("total_amount")
|
|
||||||
if ref_doc.multi_currency:
|
if ref_doc.multi_currency:
|
||||||
exchange_rate = get_exchange_rate(party_account_currency, company_currency, ref_doc.posting_date)
|
exchange_rate = get_exchange_rate(party_account_currency, company_currency, ref_doc.posting_date)
|
||||||
else:
|
else:
|
||||||
exchange_rate = 1
|
exchange_rate = 1
|
||||||
outstanding_amount = get_outstanding_on_journal_entry(reference_name)
|
outstanding_amount, total_amount = get_outstanding_on_journal_entry(
|
||||||
|
reference_name, party_type, party
|
||||||
|
)
|
||||||
|
|
||||||
elif reference_doctype != "Journal Entry":
|
elif reference_doctype != "Journal Entry":
|
||||||
if not total_amount:
|
if not total_amount:
|
||||||
|
|||||||
@@ -1087,7 +1087,9 @@ class TestPaymentEntry(FrappeTestCase):
|
|||||||
pe.source_exchange_rate = 50
|
pe.source_exchange_rate = 50
|
||||||
pe.save()
|
pe.save()
|
||||||
|
|
||||||
ref_details = get_reference_details(so.doctype, so.name, pe.paid_from_account_currency)
|
ref_details = get_reference_details(
|
||||||
|
so.doctype, so.name, pe.paid_from_account_currency, "Customer", so.customer
|
||||||
|
)
|
||||||
expected_response = {
|
expected_response = {
|
||||||
"total_amount": 5000.0,
|
"total_amount": 5000.0,
|
||||||
"outstanding_amount": 5000.0,
|
"outstanding_amount": 5000.0,
|
||||||
|
|||||||
@@ -596,7 +596,11 @@ def update_payment_req_status(doc, method):
|
|||||||
|
|
||||||
if payment_request_name:
|
if payment_request_name:
|
||||||
ref_details = get_reference_details(
|
ref_details = get_reference_details(
|
||||||
ref.reference_doctype, ref.reference_name, doc.party_account_currency
|
ref.reference_doctype,
|
||||||
|
ref.reference_name,
|
||||||
|
doc.party_account_currency,
|
||||||
|
doc.party_type,
|
||||||
|
doc.party,
|
||||||
)
|
)
|
||||||
pay_req_doc = frappe.get_doc("Payment Request", payment_request_name)
|
pay_req_doc = frappe.get_doc("Payment Request", payment_request_name)
|
||||||
status = pay_req_doc.status
|
status = pay_req_doc.status
|
||||||
|
|||||||
Reference in New Issue
Block a user