From 1475138e682530cc13244d43fecce37cc2c0f95f Mon Sep 17 00:00:00 2001 From: "Xavier BOL (xbo)" Date: Thu, 14 Jan 2021 08:17:28 +0100 Subject: [PATCH] [IMP] sale_timesheet: change _get_not_billed to _is_not_billed method Before this commit, we use the _get_not_billed method to get all timesheets not billed. But in each using, we call the method after a filtered method. This commit changes the method to use this method wiht only one recordset in the self and rename the method to _is_not_billed. This change allows to avoid the succesive filtered to get the timesheets that we want. Now, we can use the _is_not_billed method in the first filtered rathan than realize another filter. task-2424382 --- addons/sale_timesheet/models/account.py | 7 ++++--- addons/sale_timesheet/models/project.py | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) 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: