diff --git a/addons/sale_timesheet/models/account.py b/addons/sale_timesheet/models/account.py index 7ddb90ac72e..f6e27a113de 100644 --- a/addons/sale_timesheet/models/account.py +++ b/addons/sale_timesheet/models/account.py @@ -43,11 +43,12 @@ class AccountAnalyticLine(models.Model): @api.depends('task_id.sale_line_id', 'project_id.sale_line_id', 'employee_id', 'project_id.allow_billable') def _compute_so_line(self): - for timesheet in self.filtered(lambda t: not t.is_so_line_edited)._get_not_billed(): # Get only the timesheets are not yet invoiced + for timesheet in self.filtered(lambda t: not t.is_so_line_edited and t._is_not_billed()): # Get only the timesheets are not yet invoiced timesheet.so_line = timesheet.project_id.allow_billable and timesheet._timesheet_determine_sale_line(timesheet.task_id, timesheet.employee_id, timesheet.project_id) - def _get_not_billed(self): - return self.filtered(lambda t: not t.timesheet_invoice_id or t.timesheet_invoice_id.state == 'cancel') + def _is_not_billed(self): + self.ensure_one() + return not self.timesheet_invoice_id or self.timesheet_invoice_id.state == 'cancel' def _check_timesheet_can_be_billed(self): return self.so_line in self.project_id.mapped('sale_line_employee_ids.sale_line_id') | self.task_id.sale_line_id | self.project_id.sale_line_id diff --git a/addons/sale_timesheet/models/project.py b/addons/sale_timesheet/models/project.py index a0a151ba62a..3eb8a054974 100644 --- a/addons/sale_timesheet/models/project.py +++ b/addons/sale_timesheet/models/project.py @@ -110,7 +110,7 @@ class Project(models.Model): def _update_timesheets_sale_line_id(self): for project in self.filtered(lambda p: p.allow_billable and p.allow_timesheets): - timesheet_ids = project.sudo(False).mapped('timesheet_ids').filtered(lambda t: not t.is_so_line_edited)._get_not_billed() + timesheet_ids = project.sudo(False).mapped('timesheet_ids').filtered(lambda t: not t.is_so_line_edited and t._is_not_billed()) if not timesheet_ids: continue for employee_id in project.sale_line_employee_ids.filtered(lambda l: l.project_id == project).employee_id: