mirror of
https://github.com/frappe/erpnext.git
synced 2026-04-23 16:48:30 +00:00
feat: add exchange rate & base field in advance payment ledger, set exchange rate in journal entry on every refresh
This commit is contained in:
@@ -1,8 +1,9 @@
|
||||
// Copyright (c) 2024, Frappe Technologies Pvt. Ltd. and contributors
|
||||
// For license information, please see license.txt
|
||||
|
||||
// frappe.ui.form.on("Advance Payment Ledger Entry", {
|
||||
// refresh(frm) {
|
||||
|
||||
// },
|
||||
// });
|
||||
frappe.ui.form.on("Advance Payment Ledger Entry", {
|
||||
refresh(frm) {
|
||||
frm.set_currency_labels(["amount"], frm.doc.currency);
|
||||
frm.set_currency_labels(["base_amount"], erpnext.get_currency(frm.doc.company));
|
||||
},
|
||||
});
|
||||
|
||||
@@ -10,8 +10,10 @@
|
||||
"voucher_no",
|
||||
"against_voucher_type",
|
||||
"against_voucher_no",
|
||||
"amount",
|
||||
"currency",
|
||||
"exchange_rate",
|
||||
"amount",
|
||||
"base_amount",
|
||||
"event",
|
||||
"delinked"
|
||||
],
|
||||
@@ -76,13 +78,29 @@
|
||||
"fieldtype": "Check",
|
||||
"label": "DeLinked",
|
||||
"read_only": 1
|
||||
},
|
||||
{
|
||||
"depends_on": "base_amount",
|
||||
"fieldname": "base_amount",
|
||||
"fieldtype": "Currency",
|
||||
"label": "Amount (Company Currency)",
|
||||
"options": "Company:company:default_currency",
|
||||
"read_only": 1
|
||||
},
|
||||
{
|
||||
"depends_on": "exchange_rate",
|
||||
"fieldname": "exchange_rate",
|
||||
"fieldtype": "Float",
|
||||
"label": "Exchange Rate",
|
||||
"precision": "9",
|
||||
"read_only": 1
|
||||
}
|
||||
],
|
||||
"grid_page_length": 50,
|
||||
"in_create": 1,
|
||||
"index_web_pages_for_search": 1,
|
||||
"links": [],
|
||||
"modified": "2025-07-29 11:37:42.678556",
|
||||
"modified": "2025-11-13 12:45:03.014555",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Accounts",
|
||||
"name": "Advance Payment Ledger Entry",
|
||||
|
||||
@@ -19,10 +19,12 @@ class AdvancePaymentLedgerEntry(Document):
|
||||
against_voucher_no: DF.DynamicLink | None
|
||||
against_voucher_type: DF.Link | None
|
||||
amount: DF.Currency
|
||||
base_amount: DF.Currency
|
||||
company: DF.Link | None
|
||||
currency: DF.Link | None
|
||||
delinked: DF.Check
|
||||
event: DF.Data | None
|
||||
exchange_rate: DF.Float
|
||||
voucher_no: DF.DynamicLink | None
|
||||
voucher_type: DF.Link | None
|
||||
# end: auto-generated types
|
||||
|
||||
@@ -111,6 +111,10 @@ frappe.ui.form.on("Journal Entry", {
|
||||
}
|
||||
|
||||
erpnext.accounts.unreconcile_payment.add_unreconcile_btn(frm);
|
||||
|
||||
$.each(frm.doc.accounts || [], function (i, row) {
|
||||
erpnext.journal_entry.set_exchange_rate(frm, row.doctype, row.name);
|
||||
});
|
||||
},
|
||||
before_save: function (frm) {
|
||||
if (frm.doc.docstatus == 0 && !frm.doc.is_system_generated) {
|
||||
|
||||
@@ -1767,7 +1767,7 @@ def get_exchange_rate(
|
||||
|
||||
# The date used to retreive the exchange rate here is the date passed
|
||||
# in as an argument to this function.
|
||||
elif (not exchange_rate or flt(exchange_rate) == 1) and account_currency and posting_date:
|
||||
elif (not flt(exchange_rate) or flt(exchange_rate) == 1) and account_currency and posting_date:
|
||||
exchange_rate = get_exchange_rate(account_currency, company_currency, posting_date)
|
||||
else:
|
||||
exchange_rate = 1
|
||||
|
||||
@@ -1437,6 +1437,7 @@ class PaymentEntry(AccountsController):
|
||||
else allocated_amount_in_company_currency / self.transaction_exchange_rate,
|
||||
"advance_voucher_type": d.advance_voucher_type,
|
||||
"advance_voucher_no": d.advance_voucher_no,
|
||||
"transaction_exchange_rate": self.target_exchange_rate,
|
||||
},
|
||||
item=self,
|
||||
)
|
||||
|
||||
@@ -594,7 +594,11 @@ def check_if_advance_entry_modified(args):
|
||||
q.inner_join(payment_ref)
|
||||
.on(payment_entry.name == payment_ref.parent)
|
||||
.where(payment_ref.name == args.get("voucher_detail_no"))
|
||||
.where(payment_ref.reference_doctype.isin(("", "Sales Order", "Purchase Order")))
|
||||
.where(
|
||||
payment_ref.reference_doctype.isin(
|
||||
("", "Sales Order", "Purchase Order", "Employee Advance")
|
||||
)
|
||||
)
|
||||
.where(payment_ref.allocated_amount == args.get("unreconciled_amount"))
|
||||
)
|
||||
else:
|
||||
@@ -1906,8 +1910,19 @@ def get_payment_ledger_entries(gl_entries, cancel=0):
|
||||
|
||||
if gle.advance_voucher_no:
|
||||
# create advance entry
|
||||
base_amount, exchange_rate = (
|
||||
(dr_or_cr, gle.transaction_exchange_rate)
|
||||
if gle.advance_voucher_type == "Employee Advance"
|
||||
else (None, None)
|
||||
)
|
||||
adv = get_advance_ledger_entry(
|
||||
gle, against_voucher_type, against_voucher_no, dr_or_cr_account_currency, cancel
|
||||
gle,
|
||||
against_voucher_type,
|
||||
against_voucher_no,
|
||||
dr_or_cr_account_currency,
|
||||
cancel,
|
||||
base_amount,
|
||||
exchange_rate,
|
||||
)
|
||||
|
||||
ple_map.append(adv)
|
||||
@@ -1917,13 +1932,15 @@ def get_payment_ledger_entries(gl_entries, cancel=0):
|
||||
return ple_map
|
||||
|
||||
|
||||
def get_advance_ledger_entry(gle, against_voucher_type, against_voucher_no, amount, cancel):
|
||||
def get_advance_ledger_entry(
|
||||
gle, against_voucher_type, against_voucher_no, amount, cancel, base_amount=None, exchange_rate=None
|
||||
):
|
||||
event = (
|
||||
"Submit"
|
||||
if (against_voucher_type == gle.voucher_type and against_voucher_no == gle.voucher_no)
|
||||
else "Adjustment"
|
||||
)
|
||||
return frappe._dict(
|
||||
aple = frappe._dict(
|
||||
doctype="Advance Payment Ledger Entry",
|
||||
company=gle.company,
|
||||
voucher_type=gle.voucher_type,
|
||||
@@ -1937,6 +1954,12 @@ def get_advance_ledger_entry(gle, against_voucher_type, against_voucher_no, amou
|
||||
delinked=cancel,
|
||||
)
|
||||
|
||||
if base_amount is not None:
|
||||
aple.base_amount = base_amount
|
||||
if exchange_rate is not None:
|
||||
aple.exchange_rate = exchange_rate
|
||||
return aple
|
||||
|
||||
|
||||
def create_payment_ledger_entry(
|
||||
gl_entries, cancel=0, adv_adj=0, update_outstanding="Yes", from_repost=0, partial_cancel=False
|
||||
|
||||
Reference in New Issue
Block a user