From 94547188bfd8685d96649b61aff555950ed1e4f6 Mon Sep 17 00:00:00 2001 From: Raffael Meyer <14891507+barredterra@users.noreply.github.com> Date: Wed, 5 Mar 2025 08:51:40 +0100 Subject: [PATCH] feat(Sales Invoice): add items row via "Fetch Timesheet" (#46071) --- .../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 75b8434ac48..c6fd7d0dbb5 100644 --- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.js +++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.js @@ -920,9 +920,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({ @@ -1020,6 +1036,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", @@ -1044,6 +1076,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(); },