refactor: move code for unlinking sales invoice to Timesheet
diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py
index 77cc53a..40262c6 100644
--- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py
+++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py
@@ -652,13 +652,8 @@
def unlink_sales_invoice_from_timesheets(self):
for row in self.timesheets:
timesheet = frappe.get_doc("Timesheet", row.time_sheet)
- for time_log in timesheet.time_logs:
- if time_log.sales_invoice == self.name:
- time_log.sales_invoice = None
- timesheet.calculate_total_amounts()
- timesheet.calculate_percentage_billed()
+ timesheet.unlink_sales_invoice(self.name)
timesheet.flags.ignore_validate_update_after_submit = True
- timesheet.set_status()
timesheet.db_update_all()
@frappe.whitelist()
diff --git a/erpnext/projects/doctype/timesheet/timesheet.py b/erpnext/projects/doctype/timesheet/timesheet.py
index b9d801c..b1694cb 100644
--- a/erpnext/projects/doctype/timesheet/timesheet.py
+++ b/erpnext/projects/doctype/timesheet/timesheet.py
@@ -256,6 +256,16 @@
if not ts_detail.is_billable:
ts_detail.billing_rate = 0.0
+ def unlink_sales_invoice(self, sales_invoice: str):
+ """Remove link to Sales Invoice from all time logs."""
+ for time_log in self.time_logs:
+ if time_log.sales_invoice == sales_invoice:
+ time_log.sales_invoice = None
+
+ self.calculate_total_amounts()
+ self.calculate_percentage_billed()
+ self.set_status()
+
@frappe.whitelist()
def get_projectwise_timesheet_data(project=None, parent=None, from_time=None, to_time=None):