refactor: move code for unlinking sales invoice to Timesheet

This commit is contained in:
barredterra
2024-02-16 23:14:50 +01:00
parent 76023f1fdc
commit cc83af0dd4
2 changed files with 11 additions and 6 deletions

View File

@@ -652,13 +652,8 @@ class SalesInvoice(SellingController):
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()

View File

@@ -256,6 +256,16 @@ class Timesheet(Document):
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):