From d4252825f52a3172420dcda0ea394e42da9f8853 Mon Sep 17 00:00:00 2001 From: Anjali Date: Wed, 17 Nov 2021 06:41:03 +0000 Subject: [PATCH] [IMP] project,hr,sale(_timesheet): generic improvement for project The purpose of this commit, is to make generic improvements in project. In this commit, following changes are made: - add allocated hours field in project form and list view - remaining hour widget in project kanban view displays allocated hours (-) timesheeted hours on task - hide progress bar in project list view if planned hours is zero - hide task stages if user is set - move company field below tags field - project list view: rename 'Activities' to 'Next Activity' task-2692856 closes odoo/odoo#82019 Related: odoo/upgrade#3149 Related: odoo/enterprise#23148 Signed-off-by: Laurent Stukkens (ltu) Co-authored-by: Krina Oza --- addons/hr_timesheet/models/project.py | 29 ++++++++------- addons/hr_timesheet/views/project_views.xml | 20 +++++++++-- addons/project/views/project_views.xml | 6 ++-- addons/sale_timesheet/models/project.py | 40 +++++++++++++++++++++ 4 files changed, 77 insertions(+), 18 deletions(-) diff --git a/addons/hr_timesheet/models/project.py b/addons/hr_timesheet/models/project.py index 7892580d380..65624d415fd 100644 --- a/addons/hr_timesheet/models/project.py +++ b/addons/hr_timesheet/models/project.py @@ -46,9 +46,8 @@ class Project(models.Model): encode_uom_in_days = fields.Boolean(compute='_compute_encode_uom_in_days') is_internal_project = fields.Boolean(compute='_compute_is_internal_project', search='_search_is_internal_project') remaining_hours = fields.Float(compute='_compute_remaining_hours', string='Remaining Invoiced Time', compute_sudo=True) - has_planned_hours_tasks = fields.Boolean(compute='_compute_remaining_hours', compute_sudo=True, - help="True if any of the project's task has a set planned hours") is_project_overtime = fields.Boolean('Project in Overtime', compute='_compute_remaining_hours', search='_search_is_project_overtime', compute_sudo=True) + allocated_hours = fields.Float(string='Allocated Hours') def _compute_encode_uom_in_days(self): self.encode_uom_in_days = self.env.company.timesheet_encode_uom_id == self.env.ref('uom.product_uom_day') @@ -81,18 +80,24 @@ class Project(models.Model): operator_new = 'not inselect' return [('id', operator_new, (query, ()))] - @api.depends('allow_timesheets', 'task_ids.planned_hours', 'task_ids.remaining_hours') + @api.model + def _fields_view_get(self, view_id=None, view_type='form', toolbar=False, submenu=False): + result = super()._fields_view_get(view_id=view_id, view_type=view_type, toolbar=toolbar, submenu=submenu) + if view_type in ['tree', 'form'] and self.env.company.timesheet_encode_uom_id == self.env.ref('uom.product_uom_day'): + result['arch'] = self.env['account.analytic.line']._apply_time_label(result['arch'], related_model=self._name) + return result + + @api.depends('allow_timesheets', 'timesheet_ids') def _compute_remaining_hours(self): - group_read = self.env['project.task']._read_group( - domain=[('planned_hours', '!=', False), ('project_id', 'in', self.filtered('allow_timesheets').ids), - '|', ('stage_id.fold', '=', False), ('stage_id', '=', False)], - fields=['planned_hours:sum', 'remaining_hours:sum'], groupby='project_id') - group_per_project_id = {group['project_id'][0]: group for group in group_read} + timesheets_read_group = self.env['account.analytic.line']._read_group( + [('project_id', 'in', self.ids)], + ['project_id', 'unit_amount'], + ['project_id'], + lazy=False) + timesheet_time_dict = {res['project_id'][0]: res['unit_amount'] for res in timesheets_read_group} for project in self: - group = group_per_project_id.get(project.id, {}) - project.remaining_hours = group.get('remaining_hours', 0) - project.has_planned_hours_tasks = bool(group.get('planned_hours', False)) - project.is_project_overtime = group.get('remaining_hours', 0) < 0 + project.remaining_hours = project.allocated_hours - timesheet_time_dict.get(project.id, 0) + project.is_project_overtime = project.remaining_hours < 0 @api.model def _search_is_project_overtime(self, operator, value): diff --git a/addons/hr_timesheet/views/project_views.xml b/addons/hr_timesheet/views/project_views.xml index c50bb6e97f2..c92138fe29a 100644 --- a/addons/hr_timesheet/views/project_views.xml +++ b/addons/hr_timesheet/views/project_views.xml @@ -86,6 +86,9 @@ + + +
@@ -250,6 +253,17 @@ + + project.project.tree.inherit.sale.timesheet + project.project + + + + + + + + project.task.tree.inherited project.task @@ -263,7 +277,7 @@ - + @@ -278,8 +292,8 @@ - +
@@ -291,7 +305,7 @@ -
diff --git a/addons/project/views/project_views.xml b/addons/project/views/project_views.xml index d4744a159b3..9bce666a9c1 100644 --- a/addons/project/views/project_views.xml +++ b/addons/project/views/project_views.xml @@ -213,7 +213,6 @@ - @@ -252,6 +251,7 @@ project.task.type tree,kanban,form + [('user_id', '=', False)]

No stages found. Let's create one! @@ -380,6 +380,7 @@ + @@ -391,7 +392,6 @@

- @@ -1204,7 +1204,7 @@ - +