diff --git a/project_forecast_line/models/hr_employee.py b/project_forecast_line/models/hr_employee.py index 2d9ef31554..451338ccd9 100644 --- a/project_forecast_line/models/hr_employee.py +++ b/project_forecast_line/models/hr_employee.py @@ -17,16 +17,14 @@ class HrEmployee(models.Model): role_ids = fields.One2many("hr.employee.forecast.role", "employee_id") main_role_id = fields.Many2one( - "forecast.role", compute="_compute_main_role_id", ondelete="restrict" + "forecast.role", compute="_compute_main_role_id", ondelete="restrict", + compute_sudo=True ) def _compute_main_role_id(self): # can"t store as it depends on current date today = fields.Date.context_today(self) for rec in self: - if not hasattr(rec, "role_ids"): - rec.main_role_id = None - continue rec.main_role_id = rec.role_ids.filtered( lambda r: r.date_start <= today and not r.date_end