From 5b6fbc9f570667f6f0844a3999d2dc3771b5acdd Mon Sep 17 00:00:00 2001 From: roshmol Date: Wed, 11 Feb 2026 08:30:25 +0000 Subject: [PATCH 1/5] feat:payment advice currancy transaction --- .gitignore | 3 +- .../doctype/payment_advice/payment_advice.js | 137 ++++++++++++++++++ .../payment_advice/payment_advice.json | 43 +++++- .../doctype/payment_advice/payment_advice.py | 1 + 4 files changed, 179 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index ba04025..33110cf 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,5 @@ *.swp tags node_modules -__pycache__ \ No newline at end of file +__pycache__ +*.md \ No newline at end of file diff --git a/payment_advice/payment_advice/doctype/payment_advice/payment_advice.js b/payment_advice/payment_advice/doctype/payment_advice/payment_advice.js index 78bdf8b..59824c9 100644 --- a/payment_advice/payment_advice/doctype/payment_advice/payment_advice.js +++ b/payment_advice/payment_advice/doctype/payment_advice/payment_advice.js @@ -342,3 +342,140 @@ frappe.ui.form.on('Payment Advice Reference', { } }); + +// Payment Advice Main Form Events + +frappe.ui.form.on('Payment Advice', { + + refresh(frm) { + toggle_exchange_rate_field(frm); + set_amount_labels(frm); + convert_amount(frm); + }, + + transaction_currency(frm) { + toggle_exchange_rate_field(frm); + set_amount_labels(frm); + convert_amount(frm); + }, + + exchange_rate(frm) { + convert_amount(frm); + }, + + amount(frm) { + convert_amount(frm); + } +}); + + + +//Exchange Rate Show / Hide + +function toggle_exchange_rate_field(frm) { + + const company_currency = frappe.defaults.get_default("currency"); + + if (frm.doc.transaction_currency === company_currency) { + frm.set_df_property('exchange_rate', 'hidden', 1); + frm.set_value('exchange_rate', 1); + } else { + frm.set_df_property('exchange_rate', 'hidden', 0); + } +} + + + +//MAIN CALCULATION (MASTER) + +function convert_amount(frm) { + + if (!frm.doc.amount) return; + + let total = 0; + if ( + frm.doc.transaction_currency && + frm.doc.transaction_currency !== frm.doc.company_currency && + frm.doc.exchange_rate + ) { + total = flt(frm.doc.amount) * flt(frm.doc.exchange_rate); + } + else { + total = flt(frm.doc.amount); + } + + total = flt(total, 6); + frm.set_value("total_amount", total); + frm.set_value("total_amount_to_be_settled", total); + + + let total_amount_paid = flt(frm.doc.amount_paid) * flt(frm.doc.total_amount_paid); + frm.set_value("total_amount_paid", total_amount_paid); + + set_amount_in_words(frm); +} + + +//Amount In Words + + +function set_amount_in_words(frm, total) { + + if (!total) { + frm.set_value("amount_to_settled_in_words", ""); + return; + } + + const currency = + frm.doc.transaction_currency || + frappe.defaults.get_default("currency"); + + const words = frappe.utils.money_in_words(total, currency); + + frm.set_value("amount_to_settled_in_words", words); +} + +//Dynamic Labels + +function set_amount_labels(frm) { + + const company_currency = frappe.defaults.get_default("currency"); + const txn_currency = frm.doc.transaction_currency || company_currency; + + frm.set_df_property( + "amount", + "label", + `Total Amount (${company_currency})` + ); + + frm.set_df_property( + "amount_paid", + "label", + `Total Amount Paid (${company_currency})` + ); + + frm.set_df_property( + "amount_to_be_settled", + "label", + `Total To Be Settled (${company_currency})` + ); + + frm.set_df_property( + "total_amount", + "label", + `Total Amount (${txn_currency})` + ); + + frm.set_df_property( + "total_amount_paid", + "label", + `Total Amount Paid (${txn_currency})` + ); + + frm.set_df_property( + "total_amount_to_be_settled", + "label", + `Total To Be Settled (${txn_currency})` + ); +} + diff --git a/payment_advice/payment_advice/doctype/payment_advice/payment_advice.json b/payment_advice/payment_advice/doctype/payment_advice/payment_advice.json index a7c966b..0ce6dbc 100644 --- a/payment_advice/payment_advice/doctype/payment_advice/payment_advice.json +++ b/payment_advice/payment_advice/doctype/payment_advice/payment_advice.json @@ -24,12 +24,17 @@ "references_section", "payment_advice_reference", "transaction_details_section", + "transaction_currency", "amount", "amount_paid", - "column_break_stbs", - "amount_to_be_settled", "amount_to_be_settled_in_words", - "transaction_currency", + "amount_to_be_settled", + "column_break_stbs", + "exchange_rate", + "total_amount", + "total_amount_paid", + "amount_to_settled_in_words", + "total_amount_to_be_settled", "section_break_favc", "payment_amount", "reference_no", @@ -319,6 +324,36 @@ "fieldtype": "Date", "label": "Payment Entry Date", "read_only": 1 + }, + { + "fieldname": "exchange_rate", + "fieldtype": "Currency", + "label": "Exchange Rate", + "precision": "6" + }, + { + "fieldname": "total_amount", + "fieldtype": "Currency", + "label": "Total Amount", + "read_only": 1 + }, + { + "fieldname": "total_amount_paid", + "fieldtype": "Currency", + "label": "Total Amount Paid", + "read_only": 1 + }, + { + "fieldname": "amount_to_settled_in_words", + "fieldtype": "Data", + "label": "Amount To be Settled In Words", + "read_only": 1 + }, + { + "fieldname": "total_amount_to_be_settled", + "fieldtype": "Currency", + "label": "Total Amount To be Settled", + "read_only": 1 } ], "index_web_pages_for_search": 1, @@ -329,7 +364,7 @@ "link_fieldname": "custom_payment_advice" } ], - "modified": "2025-11-18 10:38:08.153731", + "modified": "2026-02-11 12:23:30.350144", "modified_by": "Administrator", "module": "Payment Advice", "name": "Payment Advice", diff --git a/payment_advice/payment_advice/doctype/payment_advice/payment_advice.py b/payment_advice/payment_advice/doctype/payment_advice/payment_advice.py index af92e58..93659f9 100644 --- a/payment_advice/payment_advice/doctype/payment_advice/payment_advice.py +++ b/payment_advice/payment_advice/doctype/payment_advice/payment_advice.py @@ -153,3 +153,4 @@ def create_payment_entry(payment_advice): except Exception as e: frappe.log_error(f"Error creating payment entry: {str(e)}") frappe.throw(f"Error creating payment entry: {str(e)}") + From dd200d00e31154a3ce68f0df75aadce83d9e32b3 Mon Sep 17 00:00:00 2001 From: AravindR97 Date: Thu, 12 Feb 2026 18:27:54 +0530 Subject: [PATCH 2/5] fix: Trans Currency amount fields names changed --- .../doctype/payment_advice/payment_advice.js | 34 ++++--------------- .../payment_advice/payment_advice.json | 18 +++++----- 2 files changed, 16 insertions(+), 36 deletions(-) diff --git a/payment_advice/payment_advice/doctype/payment_advice/payment_advice.js b/payment_advice/payment_advice/doctype/payment_advice/payment_advice.js index 59824c9..458b3b8 100644 --- a/payment_advice/payment_advice/doctype/payment_advice/payment_advice.js +++ b/payment_advice/payment_advice/doctype/payment_advice/payment_advice.js @@ -405,36 +405,16 @@ function convert_amount(frm) { } total = flt(total, 6); - frm.set_value("total_amount", total); - frm.set_value("total_amount_to_be_settled", total); + frm.set_value("amount_in_trans_cur", total); + frm.set_value("amount_to_be_settled_trans_curr", total); - let total_amount_paid = flt(frm.doc.amount_paid) * flt(frm.doc.total_amount_paid); - frm.set_value("total_amount_paid", total_amount_paid); + let total_amount_paid = flt(frm.doc.amount_paid) * flt(frm.doc.amount_paid_in_trans_curr); + frm.set_value("amount_paid_in_trans_curr", total_amount_paid); - set_amount_in_words(frm); } -//Amount In Words - - -function set_amount_in_words(frm, total) { - - if (!total) { - frm.set_value("amount_to_settled_in_words", ""); - return; - } - - const currency = - frm.doc.transaction_currency || - frappe.defaults.get_default("currency"); - - const words = frappe.utils.money_in_words(total, currency); - - frm.set_value("amount_to_settled_in_words", words); -} - //Dynamic Labels function set_amount_labels(frm) { @@ -461,19 +441,19 @@ function set_amount_labels(frm) { ); frm.set_df_property( - "total_amount", + "amount_in_trans_cur", "label", `Total Amount (${txn_currency})` ); frm.set_df_property( - "total_amount_paid", + "amount_paid_in_trans_curr", "label", `Total Amount Paid (${txn_currency})` ); frm.set_df_property( - "total_amount_to_be_settled", + "amount_to_be_settled_trans_curr", "label", `Total To Be Settled (${txn_currency})` ); diff --git a/payment_advice/payment_advice/doctype/payment_advice/payment_advice.json b/payment_advice/payment_advice/doctype/payment_advice/payment_advice.json index 0ce6dbc..2865567 100644 --- a/payment_advice/payment_advice/doctype/payment_advice/payment_advice.json +++ b/payment_advice/payment_advice/doctype/payment_advice/payment_advice.json @@ -31,10 +31,10 @@ "amount_to_be_settled", "column_break_stbs", "exchange_rate", - "total_amount", - "total_amount_paid", - "amount_to_settled_in_words", - "total_amount_to_be_settled", + "amount_in_trans_cur", + "amount_paid_in_trans_curr", + "amount_words_trans_curr", + "amount_to_be_settled_trans_curr", "section_break_favc", "payment_amount", "reference_no", @@ -332,25 +332,25 @@ "precision": "6" }, { - "fieldname": "total_amount", + "fieldname": "amount_in_trans_cur", "fieldtype": "Currency", "label": "Total Amount", "read_only": 1 }, { - "fieldname": "total_amount_paid", + "fieldname": "amount_paid_in_trans_curr", "fieldtype": "Currency", "label": "Total Amount Paid", "read_only": 1 }, { - "fieldname": "amount_to_settled_in_words", + "fieldname": "amount_words_trans_curr", "fieldtype": "Data", "label": "Amount To be Settled In Words", "read_only": 1 }, { - "fieldname": "total_amount_to_be_settled", + "fieldname": "amount_to_be_settled_trans_curr", "fieldtype": "Currency", "label": "Total Amount To be Settled", "read_only": 1 @@ -364,7 +364,7 @@ "link_fieldname": "custom_payment_advice" } ], - "modified": "2026-02-11 12:23:30.350144", + "modified": "2026-02-12 18:23:42.737425", "modified_by": "Administrator", "module": "Payment Advice", "name": "Payment Advice", From edfc62b4ef1fdc4448ddf2101b7d3292cc8b5a3c Mon Sep 17 00:00:00 2001 From: AravindR97 Date: Fri, 13 Feb 2026 10:40:12 +0530 Subject: [PATCH 3/5] feat(Payment Advice): Handle data from multi-currency records in table --- .../doctype/payment_advice/payment_advice.js | 45 +++++++++++++--- .../payment_advice_reference.json | 54 ++++++++++++++++++- 2 files changed, 92 insertions(+), 7 deletions(-) diff --git a/payment_advice/payment_advice/doctype/payment_advice/payment_advice.js b/payment_advice/payment_advice/doctype/payment_advice/payment_advice.js index 458b3b8..fd1289b 100644 --- a/payment_advice/payment_advice/doctype/payment_advice/payment_advice.js +++ b/payment_advice/payment_advice/doctype/payment_advice/payment_advice.js @@ -270,11 +270,30 @@ frappe.ui.form.on('Payment Advice Reference', { filter = ['advance_amount', date_field] } else if (row.reference_doctype == "Purchase Invoice") { if (frappe.meta.has_field("Purchase Invoice", "custom_job_record")) { - filter = ['grand_total', date_field, 'custom_job_record', 'outstanding_amount', 'bill_no']; + filter = ['grand_total', date_field, 'custom_job_record', 'outstanding_amount', 'bill_no', 'base_grand_total', 'currency', 'conversion_rate']; } else { - filter = ['grand_total', date_field, 'outstanding_amount', 'bill_no']; + filter = ['grand_total', date_field, 'outstanding_amount', 'bill_no', 'base_grand_total', 'currency', 'conversion_rate']; } - } else { + } else if (row.reference_doctype == "Sales Invoice") { + if (frappe.meta.has_field("Sales Invoice", "custom_job_record")) { + filter = ['grand_total', date_field, 'custom_job_record', 'outstanding_amount', 'base_grand_total', 'currency', 'conversion_rate']; + } else { + filter = ['grand_total', date_field, 'outstanding_amount', 'base_grand_total', 'currency', 'conversion_rate']; + } + } else if (row.reference_doctype == "Sales Order") { + if (frappe.meta.has_field("Sales Order", "custom_job_record")) { + filter = ['grand_total', date_field, 'custom_job_record', 'base_grand_total', 'currency', 'conversion_rate']; + } else { + filter = ['grand_total', date_field, 'base_grand_total', 'currency', 'conversion_rate']; + } + } else if (row.reference_doctype == "Purchase Order") { + if (frappe.meta.has_field("Purchase Order", "custom_job_record")) { + filter = ['grand_total', date_field, 'custom_job_record', 'base_grand_total', 'currency', 'conversion_rate']; + } else { + filter = ['grand_total', date_field, 'base_grand_total', 'currency', 'conversion_rate']; + } + } + else { filter = ['grand_total', date_field] } @@ -289,13 +308,27 @@ frappe.ui.form.on('Payment Advice Reference', { (r) => { if (r) { - if (r.grand_total != null) { - frappe.model.set_value(cdt, cdn, 'amount', r.grand_total); + if (r.base_grand_total != null) { + frappe.model.set_value(cdt, cdn, 'amount', r.base_grand_total); if (r.outstanding_amount && r.outstanding_amount != null) { frappe.model.set_value(cdt, cdn, 'net_payable_amount', r.outstanding_amount); - frappe.model.set_value(cdt, cdn, 'settled_amount', r.grand_total - r.outstanding_amount); + frappe.model.set_value(cdt, cdn, 'settled_amount', r.base_grand_total - r.outstanding_amount); + } + } + + if (r.currency && r.conversion_rate) { + frappe.model.set_value(cdt, cdn, 'currency', r.currency); + frappe.model.set_value(cdt, cdn, 'exchange_rate', r.conversion_rate); + + if (r.grand_total){ + frappe.model.set_value(cdt, cdn, 'amount_in_currency', r.grand_total); + if (r.outstanding_amount && r.outstanding_amount != null) { + frappe.model.set_value(cdt, cdn, 'net_payable_amount_in_currency', r.outstanding_amount/r.conversion_rate); + frappe.model.set_value(cdt, cdn, 'settled_amount_in_currency', r.grand_total - (r.outstanding_amount/r.conversion_rate)); + } } + } if (r.advance_amount != null) { diff --git a/payment_advice/payment_advice/doctype/payment_advice_reference/payment_advice_reference.json b/payment_advice/payment_advice/doctype/payment_advice_reference/payment_advice_reference.json index 8ee9aa4..2cf2aeb 100644 --- a/payment_advice/payment_advice/doctype/payment_advice_reference/payment_advice_reference.json +++ b/payment_advice/payment_advice/doctype/payment_advice_reference/payment_advice_reference.json @@ -12,9 +12,17 @@ "date", "aeging", "cost_center", + "currency", + "exchange_rate", + "section_break_pbul", "amount", "settled_amount", "net_payable_amount", + "column_break_dgbd", + "amount_in_currency", + "settled_amount_in_currency", + "net_payable_amount_in_currency", + "section_break_sfdc", "remarks" ], "fields": [ @@ -86,12 +94,56 @@ "label": "Cost Center", "options": "Cost Center", "read_only": 1 + }, + { + "fieldname": "section_break_pbul", + "fieldtype": "Section Break" + }, + { + "fieldname": "column_break_dgbd", + "fieldtype": "Column Break" + }, + { + "fieldname": "amount_in_currency", + "fieldtype": "Currency", + "label": "Total Amount in Currency", + "read_only": 1 + }, + { + "fieldname": "settled_amount_in_currency", + "fieldtype": "Currency", + "label": "Settled Amount in Currency", + "read_only": 1 + }, + { + "fieldname": "net_payable_amount_in_currency", + "fieldtype": "Currency", + "label": "Net Payable Amount in Currency", + "read_only": 1 + }, + { + "fieldname": "section_break_sfdc", + "fieldtype": "Section Break" + }, + { + "fieldname": "currency", + "fieldtype": "Link", + "label": "Currency", + "options": "Currency", + "read_only": 1 + }, + { + "fieldname": "exchange_rate", + "fieldtype": "Float", + "label": "Exchange Rate", + "precision": "6", + "read_only": 1 } ], "index_web_pages_for_search": 1, "istable": 1, "links": [], - "modified": "2025-08-12 14:38:26.178631", + "modified": "2026-02-12 19:20:45.177581", "modified_by": "Administrator", "module": "Payment Advice", "name": "Payment Advice Reference", From 8032cf0550f63c7270bd1d5a63ea59a5cbf4a315 Mon Sep 17 00:00:00 2001 From: AravindR97 Date: Fri, 13 Feb 2026 10:45:51 +0530 Subject: [PATCH 4/5] fix: Currency conversion calculation --- .../doctype/payment_advice/payment_advice.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/payment_advice/payment_advice/doctype/payment_advice/payment_advice.js b/payment_advice/payment_advice/doctype/payment_advice/payment_advice.js index fd1289b..84aa3cc 100644 --- a/payment_advice/payment_advice/doctype/payment_advice/payment_advice.js +++ b/payment_advice/payment_advice/doctype/payment_advice/payment_advice.js @@ -431,7 +431,7 @@ function convert_amount(frm) { frm.doc.transaction_currency !== frm.doc.company_currency && frm.doc.exchange_rate ) { - total = flt(frm.doc.amount) * flt(frm.doc.exchange_rate); + total = flt(frm.doc.amount) / flt(frm.doc.exchange_rate); } else { total = flt(frm.doc.amount); @@ -439,11 +439,11 @@ function convert_amount(frm) { total = flt(total, 6); frm.set_value("amount_in_trans_cur", total); - frm.set_value("amount_to_be_settled_trans_curr", total); + frm.set_value("amount_to_be_settled_trans_curr", flt(frm.doc.amount_to_be_settled) / flt(frm.doc.exchange_rate)); - let total_amount_paid = flt(frm.doc.amount_paid) * flt(frm.doc.amount_paid_in_trans_curr); - frm.set_value("amount_paid_in_trans_curr", total_amount_paid); + let amount_paid_trans = flt(frm.doc.amount_paid) / flt(frm.doc.exchange_rate); + frm.set_value("amount_paid_in_trans_curr", amount_paid_trans); } From 834367fe8bcb6edefb6cb45f11fe9a58f16a125b Mon Sep 17 00:00:00 2001 From: AravindR97 Date: Fri, 13 Feb 2026 11:14:11 +0530 Subject: [PATCH 5/5] fix: Refactor code --- .../doctype/payment_advice/payment_advice.js | 56 +++++++++---------- 1 file changed, 26 insertions(+), 30 deletions(-) diff --git a/payment_advice/payment_advice/doctype/payment_advice/payment_advice.js b/payment_advice/payment_advice/doctype/payment_advice/payment_advice.js index 84aa3cc..437ed1b 100644 --- a/payment_advice/payment_advice/doctype/payment_advice/payment_advice.js +++ b/payment_advice/payment_advice/doctype/payment_advice/payment_advice.js @@ -11,7 +11,10 @@ frappe.ui.form.on('Payment Advice', { refresh: function (frm) { if (frm.doc.__islocal && !frm.doc.transaction_date) { - frm.set_value('transaction_date', frappe.datetime.get_today()); + frm.set_value('transaction_date', frappe.datetime.get_today()); + toggle_exchange_rate_field(frm); + set_amount_labels(frm); + convert_amount(frm); } if (frm.doc.docstatus === 1) { @@ -95,6 +98,20 @@ frappe.ui.form.on('Payment Advice', { company: function(frm) { set_cost_center_filter(frm); }, + + transaction_currency(frm) { + toggle_exchange_rate_field(frm); + set_amount_labels(frm); + convert_amount(frm); + }, + + exchange_rate(frm) { + convert_amount(frm); + }, + + amount(frm) { + convert_amount(frm); + } }); // Set up event handlers for the table @@ -376,32 +393,6 @@ frappe.ui.form.on('Payment Advice Reference', { }); -// Payment Advice Main Form Events - -frappe.ui.form.on('Payment Advice', { - - refresh(frm) { - toggle_exchange_rate_field(frm); - set_amount_labels(frm); - convert_amount(frm); - }, - - transaction_currency(frm) { - toggle_exchange_rate_field(frm); - set_amount_labels(frm); - convert_amount(frm); - }, - - exchange_rate(frm) { - convert_amount(frm); - }, - - amount(frm) { - convert_amount(frm); - } -}); - - //Exchange Rate Show / Hide @@ -410,15 +401,14 @@ function toggle_exchange_rate_field(frm) { const company_currency = frappe.defaults.get_default("currency"); if (frm.doc.transaction_currency === company_currency) { - frm.set_df_property('exchange_rate', 'hidden', 1); + // frm.set_df_property('exchange_rate', 'hidden', 1); frm.set_value('exchange_rate', 1); } else { - frm.set_df_property('exchange_rate', 'hidden', 0); + // frm.set_df_property('exchange_rate', 'hidden', 0); } } - //MAIN CALCULATION (MASTER) function convert_amount(frm) { @@ -490,5 +480,11 @@ function set_amount_labels(frm) { "label", `Total To Be Settled (${txn_currency})` ); + + frm.set_df_property( + "exchange_rate", + "description", + `1 ${txn_currency} = ? ${company_currency}` + ); }