diff --git a/addons/hr_timesheet/models/project.py b/addons/hr_timesheet/models/project.py index a79273a59bf..ed6ba246bcf 100644 --- a/addons/hr_timesheet/models/project.py +++ b/addons/hr_timesheet/models/project.py @@ -38,6 +38,7 @@ class Project(models.Model): ) timesheet_ids = fields.One2many('account.analytic.line', 'project_id', 'Associated Timesheets') + timesheet_count = fields.Boolean(compute="_compute_timesheet_count") timesheet_encode_uom_id = fields.Many2one('uom.uom', related='company_id.timesheet_encode_uom_id') total_timesheet_time = fields.Integer( compute='_compute_total_timesheet_time', @@ -130,6 +131,17 @@ class Project(models.Model): total_time *= project.timesheet_encode_uom_id.factor project.total_timesheet_time = int(round(total_time)) + @api.depends('timesheet_ids') + def _compute_timesheet_count(self): + timesheet_read_group = self.env['account.analytic.line'].read_group( + [('project_id', 'in', self.ids)], + ['project_id'], + ['project_id'] + ) + timesheet_project_map = {project_info['project_id'][0]: project_info['project_id_count'] for project_info in timesheet_read_group} + for project in self: + project.timesheet_count = timesheet_project_map.get(project.id, 0) + @api.model_create_multi def create(self, vals_list): """ Create an analytic account if project allow timesheet and don't provide one diff --git a/addons/hr_timesheet/views/project_views.xml b/addons/hr_timesheet/views/project_views.xml index 8210a9ed4b3..4998ecadc77 100644 --- a/addons/hr_timesheet/views/project_views.xml +++ b/addons/hr_timesheet/views/project_views.xml @@ -274,13 +274,13 @@ - + -