From 1c6e4649bd424cba951c0e18aa62cdefacbd5089 Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Wed, 5 Mar 2025 14:06:55 +0530 Subject: [PATCH] feat(Sales Invoice): add items row via "Fetch Timesheet" (backport #46071) (#46311) feat(Sales Invoice): add items row via "Fetch Timesheet" (#46071) (cherry picked from commit 94547188bfd8685d96649b61aff555950ed1e4f6) Co-authored-by: Raffael Meyer <14891507+barredterra@users.noreply.github.com> --- .../doctype/sales_invoice/sales_invoice.js | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.js b/erpnext/accounts/doctype/sales_invoice/sales_invoice.js index ed7eb5685c1..792e1ddbdad 100644 --- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.js +++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.js @@ -922,9 +922,25 @@ frappe.ui.form.on("Sales Invoice", { } const timesheets = await frm.events.get_timesheet_data(frm, kwargs); + + if (kwargs.item_code) { + frm.events.add_timesheet_item(frm, kwargs.item_code, timesheets); + } + return frm.events.set_timesheet_data(frm, timesheets); }, + add_timesheet_item: function (frm, item_code, timesheets) { + const row = frm.add_child("items"); + frappe.model.set_value(row.doctype, row.name, "item_code", item_code); + frappe.model.set_value( + row.doctype, + row.name, + "qty", + timesheets.reduce((a, b) => a + (b["billing_hours"] || 0.0), 0.0) + ); + }, + async get_timesheet_data(frm, kwargs) { return frappe .call({ @@ -1022,6 +1038,22 @@ frappe.ui.form.on("Sales Invoice", { fieldtype: "Date", reqd: 1, }, + { + label: __("Item Code"), + fieldname: "item_code", + fieldtype: "Link", + options: "Item", + get_query: () => { + return { + query: "erpnext.controllers.queries.item_query", + filters: { + is_sales_item: 1, + customer: frm.doc.customer, + has_variants: 0, + }, + }; + }, + }, { fieldtype: "Column Break", fieldname: "col_break_1", @@ -1046,6 +1078,7 @@ frappe.ui.form.on("Sales Invoice", { from_time: data.from_time, to_time: data.to_time, project: data.project, + item_code: data.item_code, }); d.hide(); },