From b5452288edc861c408c1b9e6efcf07888972dce5 Mon Sep 17 00:00:00 2001 From: Sagar Vora Date: Mon, 4 Oct 2021 16:41:24 +0530 Subject: [PATCH] feat: add `total_billing_hours` to Sales Invoice (fp #26783) (#27742) * feat: add `total_billing_hours` to Sales Invoice * fix: re-save doctypes * fix: indentation * fix: replace reference to old function (cherry picked from commit 09ccdee2dbb1c56b553a531d95497860830ec90b) # Conflicts: # erpnext/accounts/doctype/sales_invoice/sales_invoice.js # erpnext/accounts/doctype/sales_invoice/sales_invoice.json # erpnext/accounts/doctype/sales_invoice/sales_invoice.py # erpnext/projects/doctype/timesheet/timesheet.py --- .../doctype/sales_invoice/sales_invoice.js | 35 +++++++++++++++++++ .../doctype/sales_invoice/sales_invoice.json | 7 ++++ .../doctype/sales_invoice/sales_invoice.py | 11 ++++++ .../projects/doctype/timesheet/timesheet.py | 9 +++++ 4 files changed, 62 insertions(+) diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.js b/erpnext/accounts/doctype/sales_invoice/sales_invoice.js index 7019621893a..acbcb0e7ed4 100644 --- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.js +++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.js @@ -478,7 +478,11 @@ erpnext.accounts.SalesInvoiceController = erpnext.selling.SellingController.exte let row = frappe.get_doc(d.doctype, d.name) set_timesheet_detail_rate(row.doctype, row.name, me.frm.doc.currency, row.timesheet_detail) }); +<<<<<<< HEAD this.frm.trigger("calculate_timesheet_totals"); +======= + frm.trigger("calculate_timesheet_totals"); +>>>>>>> 09ccdee2db ( feat: add `total_billing_hours` to Sales Invoice (fp #26783) (#27742)) } }, @@ -887,18 +891,37 @@ frappe.ui.form.on('Sales Invoice', { set_timesheet_data: function(frm, timesheets) { frm.clear_table("timesheets") +<<<<<<< HEAD timesheets.forEach(async (timesheet) => { if (frm.doc.currency != timesheet.currency) { const exchange_rate = await frm.events.get_exchange_rate( frm, timesheet.currency, frm.doc.currency ) frm.events.append_time_log(frm, timesheet, exchange_rate) +======= + timesheets.forEach(timesheet => { + if (frm.doc.currency != timesheet.currency) { + frappe.call({ + method: "erpnext.setup.utils.get_exchange_rate", + args: { + from_currency: timesheet.currency, + to_currency: frm.doc.currency + }, + callback: function(r) { + if (r.message) { + exchange_rate = r.message; + frm.events.append_time_log(frm, timesheet, exchange_rate); + } + } + }); +>>>>>>> 09ccdee2db ( feat: add `total_billing_hours` to Sales Invoice (fp #26783) (#27742)) } else { frm.events.append_time_log(frm, timesheet, 1.0); } }); }, +<<<<<<< HEAD async get_exchange_rate(frm, from_currency, to_currency) { if ( frm.exchange_rates @@ -925,6 +948,8 @@ frappe.ui.form.on('Sales Invoice', { }); }, +======= +>>>>>>> 09ccdee2db ( feat: add `total_billing_hours` to Sales Invoice (fp #26783) (#27742)) append_time_log: function(frm, time_log, exchange_rate) { const row = frm.add_child("timesheets"); row.activity_type = time_log.activity_type; @@ -935,7 +960,11 @@ frappe.ui.form.on('Sales Invoice', { row.billing_hours = time_log.billing_hours; row.billing_amount = flt(time_log.billing_amount) * flt(exchange_rate); row.timesheet_detail = time_log.name; +<<<<<<< HEAD row.project_name = time_log.project_name; +======= + row.project_name = time_log.project_name; +>>>>>>> 09ccdee2db ( feat: add `total_billing_hours` to Sales Invoice (fp #26783) (#27742)) frm.refresh_field("timesheets"); frm.trigger("calculate_timesheet_totals"); @@ -1032,13 +1061,19 @@ frappe.ui.form.on('Sales Invoice', { } }); +<<<<<<< HEAD +======= +>>>>>>> 09ccdee2db ( feat: add `total_billing_hours` to Sales Invoice (fp #26783) (#27742)) frappe.ui.form.on("Sales Invoice Timesheet", { timesheets_remove(frm) { frm.trigger("calculate_timesheet_totals"); } }); +<<<<<<< HEAD +======= +>>>>>>> 09ccdee2db ( feat: add `total_billing_hours` to Sales Invoice (fp #26783) (#27742)) var set_timesheet_detail_rate = function(cdt, cdn, currency, timelog) { frappe.call({ diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.json b/erpnext/accounts/doctype/sales_invoice/sales_invoice.json index c0b1c596007..f049366347d 100644 --- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.json +++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.json @@ -2022,6 +2022,7 @@ "label": "Total Billing Hours", "print_hide": 1, "read_only": 1 +<<<<<<< HEAD }, { "fieldname": "amount_eligible_for_commission", @@ -2035,6 +2036,8 @@ "fieldname": "is_cash_or_non_trade_discount", "fieldtype": "Check", "label": "Is Cash or Non Trade Discount" +======= +>>>>>>> 09ccdee2db ( feat: add `total_billing_hours` to Sales Invoice (fp #26783) (#27742)) } ], "icon": "fa fa-file-text", @@ -2047,7 +2050,11 @@ "link_fieldname": "consolidated_invoice" } ], +<<<<<<< HEAD "modified": "2023-01-28 19:45:47.538163", +======= + "modified": "2021-10-02 03:36:10.251715", +>>>>>>> 09ccdee2db ( feat: add `total_billing_hours` to Sales Invoice (fp #26783) (#27742)) "modified_by": "Administrator", "module": "Accounts", "name": "Sales Invoice", diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py index 4a4a0f839d2..d8415bdc645 100644 --- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py +++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py @@ -890,6 +890,7 @@ class SalesInvoice(SellingController): self.set("timesheets", []) if self.project: for data in get_projectwise_timesheet_data(self.project): +<<<<<<< HEAD self.append( "timesheets", { @@ -901,6 +902,16 @@ class SalesInvoice(SellingController): "description": data.description, }, ) +======= + self.append('timesheets', { + 'time_sheet': data.time_sheet, + 'billing_hours': data.billing_hours, + 'billing_amount': data.billing_amount, + 'timesheet_detail': data.name, + 'activity_type': data.activity_type, + 'description': data.description + }) +>>>>>>> 09ccdee2db ( feat: add `total_billing_hours` to Sales Invoice (fp #26783) (#27742)) self.calculate_billing_amount_for_timesheet() diff --git a/erpnext/projects/doctype/timesheet/timesheet.py b/erpnext/projects/doctype/timesheet/timesheet.py index 34e2e364b57..a325276e05d 100644 --- a/erpnext/projects/doctype/timesheet/timesheet.py +++ b/erpnext/projects/doctype/timesheet/timesheet.py @@ -294,7 +294,16 @@ def get_projectwise_timesheet_data(project=None, parent=None, from_time=None, to ORDER BY tsd.from_time ASC """ +<<<<<<< HEAD filters = {"project": project, "parent": parent, "from_time": from_time, "to_time": to_time} +======= + filters = { + "project": project, + "parent": parent, + "from_time": from_time, + "to_time": to_time + } +>>>>>>> 09ccdee2db ( feat: add `total_billing_hours` to Sales Invoice (fp #26783) (#27742)) return frappe.db.sql(query, filters, as_dict=1)