diff options
| author | Kevin Baptiste <kba@odoo.com> | 2020-11-20 09:59:20 +0000 |
|---|---|---|
| committer | Kevin Baptiste <kba@odoo.com> | 2020-11-30 12:51:37 +0000 |
| commit | bb1611fef1d1e78b3c38e92d40c31fa915128295 (patch) | |
| tree | dba20b4f7ff7a6747cb298bb5fb515ccca2cabf4 /addons | |
| parent | e542c4121af098372c250a081635a44829e50406 (diff) | |
[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#62071
Taskid: 2389727
Related: odoo/enterprise#14880
Signed-off-by: Yannick Tivisse (yti) <yti@odoo.com>
Diffstat (limited to 'addons')
| -rw-r--r-- | addons/hr_timesheet/models/hr_timesheet.py | 21 |
1 files 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: |
