[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
This commit is contained in:
Xavier BOL (xbo)
2021-01-15 15:59:59 +01:00
parent 82a0422df5
commit 1475138e68
2 changed files with 5 additions and 4 deletions
+4 -3
View File
@@ -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
+1 -1
View File
@@ -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: