From a7d0dbb085f23f3cedc1b88b546bcc64cb029d56 Mon Sep 17 00:00:00 2001 From: Rucha Mahabal Date: Thu, 20 May 2021 23:02:11 +0530 Subject: [PATCH] fix: calculate total billing amount on fetching timesheets - show timesheet billing amounts in doc currency --- .../doctype/sales_invoice/sales_invoice.js | 57 +++++++++---------- .../doctype/sales_invoice/sales_invoice.json | 5 +- .../sales_invoice_timesheet.json | 3 +- .../projects/doctype/timesheet/timesheet.py | 6 +- 4 files changed, 35 insertions(+), 36 deletions(-) diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.js b/erpnext/accounts/doctype/sales_invoice/sales_invoice.js index 747d0a931a5..1808005f62d 100644 --- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.js +++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.js @@ -820,7 +820,7 @@ frappe.ui.form.on('Sales Invoice', { }, add_timesheet_row: function(frm, row, exchange_rate) { - frm.add_child('timesheets',{ + frm.add_child('timesheets', { 'activity_type': row.activity_type, 'description': row.description, 'time_sheet': row.parent, @@ -828,7 +828,8 @@ frappe.ui.form.on('Sales Invoice', { 'billing_amount': flt(row.billing_amount) * flt(exchange_rate), 'timesheet_detail': row.name }); - frm.refresh_field('timesheets') + frm.refresh_field('timesheets'); + calculate_total_billing_amount(frm); }, refresh: function(frm) { @@ -871,36 +872,32 @@ frappe.ui.form.on('Sales Invoice', { project: data.project }, callback: function(r) { - if(!r.exc) { - if(r.message.length > 0) { - frm.clear_table('timesheets') - r.message.forEach((d) => { - let exchange_rate = 1.0; - if (frm.doc.currency != d.currency) { - frappe.call({ - method: "erpnext.setup.utils.get_exchange_rate", - args: { - from_currency: d.currency, - to_currency: frm.doc.currency - }, - callback: function(r) { - if (r.message) { - exchange_rate = r.message; - frm.events.add_timesheet_row(frm, d, exchange_rate); - } + if (!r.exc && r.message.length > 0) { + frm.clear_table('timesheets') + r.message.forEach((d) => { + let exchange_rate = 1.0; + if (frm.doc.currency != d.currency) { + frappe.call({ + method: 'erpnext.setup.utils.get_exchange_rate', + args: { + from_currency: d.currency, + to_currency: frm.doc.currency + }, + callback: function(r) { + if (r.message) { + exchange_rate = r.message; + frm.events.add_timesheet_row(frm, d, exchange_rate); } - }); - } - else { - frm.events.add_timesheet_row(frm, d, exchange_rate); - } - }); - } - else { - frappe.msgprint(__('No Timesheet Found.')) - } - d.hide(); + } + }); + } else { + frm.events.add_timesheet_row(frm, d, exchange_rate); + } + }); + } else { + frappe.msgprint(__('No Timesheets found with the selected filters.')) } + d.hide(); } }); }, diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.json b/erpnext/accounts/doctype/sales_invoice/sales_invoice.json index 48d644cb432..e7dd6b8a606 100644 --- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.json +++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.json @@ -772,6 +772,7 @@ "hide_days": 1, "hide_seconds": 1, "label": "Total Billing Amount", + "options": "currency", "print_hide": 1, "read_only": 1 }, @@ -1960,7 +1961,7 @@ "label": "Is Debit Note" }, { - "default": 0, + "default": "0", "depends_on": "grand_total", "fieldname": "disable_rounded_total", "fieldtype": "Check", @@ -1977,7 +1978,7 @@ "link_fieldname": "consolidated_invoice" } ], - "modified": "2021-05-13 17:53:26.185370", + "modified": "2021-05-20 22:48:33.988881", "modified_by": "Administrator", "module": "Accounts", "name": "Sales Invoice", diff --git a/erpnext/accounts/doctype/sales_invoice_timesheet/sales_invoice_timesheet.json b/erpnext/accounts/doctype/sales_invoice_timesheet/sales_invoice_timesheet.json index 9321630829c..f069e8dd0b8 100644 --- a/erpnext/accounts/doctype/sales_invoice_timesheet/sales_invoice_timesheet.json +++ b/erpnext/accounts/doctype/sales_invoice_timesheet/sales_invoice_timesheet.json @@ -34,6 +34,7 @@ "fieldtype": "Currency", "in_list_view": 1, "label": "Billing Amount", + "options": "currency", "read_only": 1 }, { @@ -64,7 +65,7 @@ ], "istable": 1, "links": [], - "modified": "2021-05-13 16:52:32.995266", + "modified": "2021-05-20 22:33:57.234846", "modified_by": "Administrator", "module": "Accounts", "name": "Sales Invoice Timesheet", diff --git a/erpnext/projects/doctype/timesheet/timesheet.py b/erpnext/projects/doctype/timesheet/timesheet.py index d42c6ab1758..a3e4577f909 100644 --- a/erpnext/projects/doctype/timesheet/timesheet.py +++ b/erpnext/projects/doctype/timesheet/timesheet.py @@ -342,9 +342,9 @@ def get_activity_cost(employee=None, activity_type=None, currency=None): rate = frappe.db.get_values("Activity Type", {"activity_type": activity_type}, ["costing_rate", "billing_rate"], as_dict=True) if rate and currency and currency!=base_currency: - exchnage_rate = get_exchange_rate(base_currency, currency) - rate[0]["costing_rate"] = rate[0]["costing_rate"] * exchnage_rate - rate[0]["billing_rate"] = rate[0]["billing_rate"] * exchnage_rate + exchange_rate = get_exchange_rate(base_currency, currency) + rate[0]["costing_rate"] = rate[0]["costing_rate"] * exchange_rate + rate[0]["billing_rate"] = rate[0]["billing_rate"] * exchange_rate return rate[0] if rate else {}