diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.js b/erpnext/accounts/doctype/sales_invoice/sales_invoice.js index d1c295eaf5f..ed7eb5685c1 100644 --- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.js +++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.js @@ -897,12 +897,16 @@ frappe.ui.form.on("Sales Invoice", { project: function (frm) { if (frm.doc.project) { - frappe.db.get_value("Projects Settings", {}, "fetch_timesheet_in_sales_invoice", (r) => { - if (cint(r.fetch_timesheet_in_sales_invoice)) { - frm.events.add_timesheet_data(frm, { - project: frm.doc.project, - }); - } + frappe.call({ + method: "is_auto_fetch_timesheet_enabled", + doc: frm.doc, + callback: function (r) { + if (cint(r.message)) { + frm.events.add_timesheet_data(frm, { + project: frm.doc.project, + }); + } + }, }); } }, diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py index 3c0689a7da9..c860fe41a66 100644 --- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py +++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py @@ -1090,15 +1090,15 @@ class SalesInvoice(SellingController): timesheet.billing_amount = ts_doc.total_billable_amount def update_timesheet_billing_for_project(self): - if ( - not self.timesheets - and self.project - and frappe.db.get_single_value("Projects Settings", "fetch_timesheet_in_sales_invoice") - ): + if not self.timesheets and self.project and self.is_auto_fetch_timesheet_enabled(): self.add_timesheet_data() else: self.calculate_billing_amount_for_timesheet() + @frappe.whitelist() + def is_auto_fetch_timesheet_enabled(self): + return frappe.db.get_single_value("Projects Settings", "fetch_timesheet_in_sales_invoice") + @frappe.whitelist() def add_timesheet_data(self): self.set("timesheets", [])