From fce463ca5b4f79e5798a8da2cadb5dbad8bfee6d Mon Sep 17 00:00:00 2001 From: Kevin Baptiste Date: Fri, 20 Nov 2020 09:59:20 +0000 Subject: [PATCH] [FIX] hr_timesheet: trigger compute on project_id / task_id Before this commit the fields project_id and task_id on account.analytic.line were sharing the same compute method which was not triggered when one of those fields were changed. Here the fields get their very own compute method. closes odoo/odoo#63043 Taskid: 2389727 X-original-commit: bb1611fef1d1e78b3c38e92d40c31fa915128295 Related: odoo/enterprise#15192 Signed-off-by: Yannick Tivisse (yti) --- addons/hr_timesheet/models/hr_timesheet.py | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/addons/hr_timesheet/models/hr_timesheet.py b/addons/hr_timesheet/models/hr_timesheet.py index bdb6a2fd2b5..17d4a613371 100644 --- a/addons/hr_timesheet/models/hr_timesheet.py +++ b/addons/hr_timesheet/models/hr_timesheet.py @@ -39,10 +39,10 @@ class AccountAnalyticLine(models.Model): return [] task_id = fields.Many2one( - 'project.task', 'Task', compute='_compute_project_task_id', store=True, readonly=False, index=True, + 'project.task', 'Task', compute='_compute_task_id', store=True, readonly=False, index=True, domain="[('company_id', '=', company_id), ('project_id.allow_timesheets', '=', True), ('project_id', '=?', project_id)]") project_id = fields.Many2one( - 'project.project', 'Project', compute='_compute_project_task_id', store=True, readonly=False, + 'project.project', 'Project', compute='_compute_project_id', store=True, readonly=False, domain=_domain_project_id) user_id = fields.Many2one(compute='_compute_user_id', store=True, readonly=False) employee_id = fields.Many2one('hr.employee', "Employee", domain=_domain_employee_id) @@ -53,13 +53,24 @@ class AccountAnalyticLine(models.Model): for analytic_line in self: analytic_line.encoding_uom_id = analytic_line.company_id.timesheet_encode_uom_id - @api.depends('task_id', 'task_id.project_id', 'project_id') - def _compute_project_task_id(self): + @api.depends('task_id', 'task_id.project_id') + def _compute_project_id(self): for line in self.filtered(lambda line: not line.project_id): line.project_id = line.task_id.project_id - for line in self.filtered(lambda line: not line.project_id and line.project_id != line.task_id.project_id): + + @api.depends('project_id') + def _compute_task_id(self): + for line in self.filtered(lambda line: not line.project_id): line.task_id = False + @api.onchange('project_id') + def _onchange_project_id(self): + # TODO KBA in master - check to do it "properly", currently: + # This onchange is used to reset the task_id when the project changes. + # Doing it in the compute will remove the task_id when the project of a task changes. + if self.project_id != self.task_id.project_id: + self.task_id = False + @api.depends('employee_id') def _compute_user_id(self): for line in self: