From 11f65f20a04ef6d7fd04eb62508a75eb729758f0 Mon Sep 17 00:00:00 2001 From: Raffael Meyer <14891507+barredterra@users.noreply.github.com> Date: Mon, 27 Jan 2025 08:50:57 +0100 Subject: [PATCH] feat(Sales Invoice): allow linking to project without adding timesheets (#44295) * feat(Sales Invoice): allow linking to project without adding timesheets * test: add timesheet data --- .../accounts/doctype/sales_invoice/sales_invoice.py | 11 +++++++---- erpnext/projects/doctype/timesheet/test_timesheet.py | 1 + 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py index e7169c23674..c85175db144 100644 --- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py +++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py @@ -1089,13 +1089,16 @@ 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: - self.add_timesheet_data() - else: + if self.timesheets: self.calculate_billing_amount_for_timesheet() - @frappe.whitelist() + @frappe.whitelist(methods=["PUT"]) def add_timesheet_data(self): + if not self.timesheets and self.project: + self._add_timesheet_data() + self.save() + + def _add_timesheet_data(self): self.set("timesheets", []) if self.project: for data in get_projectwise_timesheet_data(self.project): diff --git a/erpnext/projects/doctype/timesheet/test_timesheet.py b/erpnext/projects/doctype/timesheet/test_timesheet.py index ba2f95ba59b..cf95bd63680 100644 --- a/erpnext/projects/doctype/timesheet/test_timesheet.py +++ b/erpnext/projects/doctype/timesheet/test_timesheet.py @@ -62,6 +62,7 @@ class TestTimesheet(IntegrationTestCase): ) sales_invoice = create_sales_invoice(do_not_save=True) sales_invoice.project = project + sales_invoice._add_timesheet_data() sales_invoice.submit() ts = frappe.get_doc("Timesheet", timesheet.name)