diff options
| author | Xavier BOL (xbo) <xbo@odoo.com> | 2020-12-14 11:19:57 +0100 |
|---|---|---|
| committer | Xavier BOL (xbo) <xbo@odoo.com> | 2020-12-21 15:35:20 +0100 |
| commit | efba0148a843e35cdcdfe3228f718d8fe8634f56 (patch) | |
| tree | f1677472e3a8e1c0115cc6d4aab127370d38cd6a | |
| parent | 563c6a127c83f19ef0caa33eb392595b14924d39 (diff) | |
[FIX] sale_timesheet: determine SOL only if allow_billable=True
Before this commit, even if the allow_billable=False in the current
project, we search a SOL for task and timesheets.
This commit determines the SOL in tasks and timesheets only if the
allow_billable=True in the linked project.
task-2409761
| -rw-r--r-- | addons/sale_timesheet/models/account.py | 6 | ||||
| -rw-r--r-- | addons/sale_timesheet/models/project.py | 23 | ||||
| -rw-r--r-- | addons/sale_timesheet_edit/models/account_analytic_line.py | 2 |
3 files changed, 7 insertions, 24 deletions
diff --git a/addons/sale_timesheet/models/account.py b/addons/sale_timesheet/models/account.py index 5d2c503e9b1..74b039fa6d3 100644 --- a/addons/sale_timesheet/models/account.py +++ b/addons/sale_timesheet/models/account.py @@ -57,10 +57,10 @@ class AccountAnalyticLine(models.Model): else: self.so_line = False - @api.depends('task_id.sale_line_id', 'project_id.sale_line_id', 'employee_id') + @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._get_not_billed(): # Get only the timesheets are not yet invoiced - timesheet.so_line = timesheet._timesheet_determine_sale_line(timesheet.task_id, timesheet.employee_id, timesheet.project_id) + 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') @@ -94,8 +94,6 @@ class AccountAnalyticLine(models.Model): values = super(AccountAnalyticLine, self)._timesheet_preprocess(values) # task implies so line (at create) if any([field_name in values for field_name in ['task_id', 'project_id']]) and not values.get('so_line') and (values.get('employee_id') or self.mapped('employee_id')): - if not values.get('employee_id') and len(self.mapped('employee_id')) > 1: - raise UserError(_('You can not modify timesheets from different employees')) task = self.env['project.task'].sudo().browse(values['task_id']) if values.get('task_id') else self.env['project.task'] employee = self.env['hr.employee'].sudo().browse(values['employee_id']) if values.get('employee_id') else self.mapped('employee_id') project = self.env['project.project'].sudo().browse(values['project_id']) if values.get('project_id') else task.project_id diff --git a/addons/sale_timesheet/models/project.py b/addons/sale_timesheet/models/project.py index 597b858ded6..cf215b5dd09 100644 --- a/addons/sale_timesheet/models/project.py +++ b/addons/sale_timesheet/models/project.py @@ -294,10 +294,11 @@ class ProjectTask(models.Model): elif not task.sale_order_id: task.sale_order_id = False - @api.depends('commercial_partner_id', 'sale_line_id.order_partner_id.commercial_partner_id', 'parent_id.sale_line_id', 'project_id.sale_line_id') + @api.depends('commercial_partner_id', 'sale_line_id.order_partner_id.commercial_partner_id', 'parent_id.sale_line_id', 'project_id.sale_line_id', 'allow_billable') def _compute_sale_line(self): - super(ProjectTask, self)._compute_sale_line() - for task in self.filtered(lambda t: not t.sale_line_id): + billable_tasks = self.filtered('allow_billable') + super(ProjectTask, billable_tasks)._compute_sale_line() + for task in billable_tasks.filtered(lambda t: not t.sale_line_id): task.sale_line_id = task._get_last_sol_of_customer() @api.depends('project_id.sale_line_employee_ids') @@ -325,22 +326,6 @@ class ProjectTask(models.Model): project_dest = self.env['project.project'].browse(values['project_id']) if project_dest.bill_type == 'customer_project' and project_dest.pricing_type == 'employee_rate': self.write({'sale_line_id': False}) - if 'sale_line_id' in values and self.filtered('allow_timesheets').sudo().timesheet_ids: - so = self.env['sale.order.line'].browse(values['sale_line_id']).order_id - if so and not so.analytic_account_id: - so.analytic_account_id = self.project_id.analytic_account_id - timesheet_ids = self.filtered('allow_timesheets').timesheet_ids.filtered( - lambda t: (not t.timesheet_invoice_id or t.timesheet_invoice_id.state == 'cancel') - ) - timesheet_ids.write({'so_line': values['sale_line_id']}) - if 'project_id' in values: - - # Special case when we edit SOL an project in same time, as we edit SOL of - # timesheet lines, function '_get_timesheet' won't find the right timesheet - # to edit so we must edit those here. - project = self.env['project.project'].browse(values.get('project_id')) - if project.allow_timesheets: - timesheet_ids.write({'project_id': values.get('project_id')}) if 'non_allow_billable' in values and self.filtered('allow_timesheets').sudo().timesheet_ids: timesheet_ids = self.filtered('allow_timesheets').timesheet_ids.filtered( lambda t: (not t.timesheet_invoice_id or t.timesheet_invoice_id.state == 'cancel') diff --git a/addons/sale_timesheet_edit/models/account_analytic_line.py b/addons/sale_timesheet_edit/models/account_analytic_line.py index 69a9cc3df30..5ff797ddc34 100644 --- a/addons/sale_timesheet_edit/models/account_analytic_line.py +++ b/addons/sale_timesheet_edit/models/account_analytic_line.py @@ -10,7 +10,7 @@ class AccountAnalyticLine(models.Model): is_so_line_edited = fields.Boolean() - @api.depends('task_id.sale_line_id', 'project_id.sale_line_id', 'employee_id') + @api.depends('task_id.sale_line_id', 'project_id.sale_line_id', 'project_id.allow_billable', 'employee_id') def _compute_so_line(self): super(AccountAnalyticLine, self.filtered(lambda t: not t.is_so_line_edited))._compute_so_line() |
