[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) <yti@odoo.com>
This commit is contained in:
Kevin Baptiste
2020-12-08 15:40:49 +00:00
parent 9e487dc20e
commit fce463ca5b
+16 -5
View File
@@ -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: