diff --git a/addons/hr_timesheet/models/hr_timesheet.py b/addons/hr_timesheet/models/hr_timesheet.py index 18990346547..ed64d3ab209 100644 --- a/addons/hr_timesheet/models/hr_timesheet.py +++ b/addons/hr_timesheet/models/hr_timesheet.py @@ -50,7 +50,7 @@ class AccountAnalyticLine(models.Model): task_id = fields.Many2one( 'project.task', 'Task', index='btree_not_null', compute='_compute_task_id', store=True, readonly=False, - domain="[('project_id.allow_timesheets', '=', True), ('project_id', '=?', project_id)]") + domain="[('allow_timesheets', '=', True), ('project_id', '=?', project_id)]") parent_task_id = fields.Many2one('project.task', related='task_id.parent_id', store=True) project_id = fields.Many2one( 'project.project', 'Project', domain=_domain_project_id, index=True, diff --git a/addons/hr_timesheet/models/project_task.py b/addons/hr_timesheet/models/project_task.py index b8d6fee61fa..80b48d43fab 100644 --- a/addons/hr_timesheet/models/project_task.py +++ b/addons/hr_timesheet/models/project_task.py @@ -27,7 +27,11 @@ class Task(models.Model): project_id = fields.Many2one(domain="['|', ('company_id', '=', False), ('company_id', '=?', company_id), ('is_internal_project', '=', False)]") analytic_account_active = fields.Boolean("Active Analytic Account", compute='_compute_analytic_account_active', compute_sudo=True, recursive=True) - allow_timesheets = fields.Boolean("Allow timesheets", related="project_id.allow_timesheets", help="Timesheets can be logged on this task.", readonly=True, recursive=True) + allow_timesheets = fields.Boolean( + "Allow timesheets", + compute='_compute_allow_timesheets', search='_search_allow_timesheets', + compute_sudo=True, readonly=True, + help="Timesheets can be logged on this task.") remaining_hours = fields.Float("Remaining Hours", compute='_compute_remaining_hours', store=True, readonly=True, help="Number of allocated hours minus the number of hours spent.") remaining_hours_percentage = fields.Float(compute='_compute_remaining_hours_percentage', search='_search_remaining_hours_percentage') effective_hours = fields.Float("Hours Spent", compute='_compute_effective_hours', compute_sudo=True, store=True) @@ -60,6 +64,17 @@ class Task(models.Model): def _compute_encode_uom_in_days(self): self.encode_uom_in_days = self._uom_in_days() + @api.depends('project_id.allow_timesheets') + def _compute_allow_timesheets(self): + for task in self: + task.allow_timesheets = task.project_id.allow_timesheets + + def _search_allow_timesheets(self, operator, value): + query = self.env['project.project'].sudo()._search([ + ('allow_timesheets', operator, value), + ]) + return [('project_id', 'in', query)] + @api.depends('analytic_account_id.active', 'project_id.analytic_account_id.active') def _compute_analytic_account_active(self): """ Overridden in sale_timesheet """ diff --git a/addons/project_timesheet_holidays/models/account_analytic.py b/addons/project_timesheet_holidays/models/account_analytic.py index bb7a5b2f2bb..258cbda1d09 100644 --- a/addons/project_timesheet_holidays/models/account_analytic.py +++ b/addons/project_timesheet_holidays/models/account_analytic.py @@ -10,7 +10,7 @@ class AccountAnalyticLine(models.Model): holiday_id = fields.Many2one("hr.leave", string='Time Off Request', copy=False) global_leave_id = fields.Many2one("resource.calendar.leaves", string="Global Time Off", ondelete='cascade') - task_id = fields.Many2one(domain="[('project_id.allow_timesheets', '=', True), ('project_id', '=?', project_id), ('is_timeoff_task', '=', False)]") + task_id = fields.Many2one(domain="[('allow_timesheets', '=', True), ('project_id', '=?', project_id), ('is_timeoff_task', '=', False)]") def _get_redirect_action(self): leave_form_view_id = self.env.ref('hr_holidays.hr_leave_view_form').id