From e159698b96bb95c5d99f5c0c94010d1b77034904 Mon Sep 17 00:00:00 2001 From: Nidhi Patel Date: Wed, 28 Apr 2021 13:21:20 +0000 Subject: [PATCH] [IMP] hr,sale(_timesheet): clean duration in days The purpose of this task is there are several places where the duration is expressed in hours even though the encoding unit is in Days. This creates inconsistencies. In this commit, we convert hours into days when the encoding unit is in Days. Also, we changed the string of the fields according to the encoding unit. closes odoo/odoo#70512 Task-id: 2512950 Related: odoo/enterprise#18197 Signed-off-by: LTU-Odoo --- addons/hr_timesheet/__manifest__.py | 1 + addons/hr_timesheet/models/project.py | 7 ++-- addons/hr_timesheet/report/project_report.py | 9 ++++- .../report/project_report_view.xml | 27 ++++++++++---- .../static/src/js/timesheet_graph.js | 4 ++- .../views/project_portal_templates.xml | 9 ++++- addons/hr_timesheet/views/project_views.xml | 35 +++++++++++++++++++ ...ct_profitability_report_analysis_views.xml | 4 ++- .../views/sale_timesheet_portal_templates.xml | 9 ++++- 9 files changed, 91 insertions(+), 14 deletions(-) diff --git a/addons/hr_timesheet/__manifest__.py b/addons/hr_timesheet/__manifest__.py index 80b82ee6e29..3c59da30ae4 100644 --- a/addons/hr_timesheet/__manifest__.py +++ b/addons/hr_timesheet/__manifest__.py @@ -32,6 +32,7 @@ up a management by affair. 'views/project_update_templates.xml', 'views/hr_timesheet_portal_templates.xml', 'report/hr_timesheet_report_view.xml', + 'report/project_report_view.xml', 'report/report_timesheet_templates.xml', 'views/hr_views.xml', 'data/hr_timesheet_data.xml', diff --git a/addons/hr_timesheet/models/project.py b/addons/hr_timesheet/models/project.py index 4198b3a0639..18f510038f5 100644 --- a/addons/hr_timesheet/models/project.py +++ b/addons/hr_timesheet/models/project.py @@ -218,16 +218,17 @@ class Task(models.Model): result = super(Task, self)._fields_view_get(view_id=view_id, view_type=view_type, toolbar=toolbar, submenu=submenu) result['arch'] = self.env['account.analytic.line']._apply_timesheet_label(result['arch']) - if view_type == 'tree' and self.env.company.timesheet_encode_uom_id == self.env.ref('uom.product_uom_day'): + if view_type in ['tree', 'pivot', 'graph'] and self.env.company.timesheet_encode_uom_id == self.env.ref('uom.product_uom_day'): result['arch'] = self._apply_time_label(result['arch']) return result @api.model - def _apply_time_label(self, view_arch): + def _apply_time_label(self, view_arch, related_model=None): doc = etree.XML(view_arch) + Model = self.env[related_model or self._name] encoding_uom = self.env.company.timesheet_encode_uom_id for node in doc.xpath("//field[@widget='timesheet_uom'][not(@string)] | //field[@widget='timesheet_uom_no_toggle'][not(@string)]"): - name_with_uom = re.sub(_('Hours') + "|Hours", encoding_uom.name or '', self._fields[node.get('name')]._description_string(self.env), flags=re.IGNORECASE) + name_with_uom = re.sub(_('Hours') + "|Hours", encoding_uom.name or '', Model._fields[node.get('name')]._description_string(self.env), flags=re.IGNORECASE) node.set('string', name_with_uom) return etree.tostring(doc, encoding='unicode') diff --git a/addons/hr_timesheet/report/project_report.py b/addons/hr_timesheet/report/project_report.py index 367a0a59436..f8c33eb7423 100644 --- a/addons/hr_timesheet/report/project_report.py +++ b/addons/hr_timesheet/report/project_report.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- # Part of Odoo. See LICENSE file for full copyright and licensing details. -from odoo import fields, models +from odoo import fields, models, api class ReportProjectTaskUser(models.Model): @@ -25,3 +25,10 @@ class ReportProjectTaskUser(models.Model): t.effective_hours, planned_hours """ + + @api.model + def _fields_view_get(self, view_id=None, view_type='form', toolbar=False, submenu=False): + result = super(ReportProjectTaskUser, self)._fields_view_get(view_id=view_id, view_type=view_type, toolbar=toolbar, submenu=submenu) + if view_type in ['pivot', 'graph'] and self.env.company.timesheet_encode_uom_id == self.env.ref('uom.product_uom_day'): + result['arch'] = self.env['project.task']._apply_time_label(result['arch'], related_model=self._name) + return result diff --git a/addons/hr_timesheet/report/project_report_view.xml b/addons/hr_timesheet/report/project_report_view.xml index d62fb501592..0fd45d1c9df 100644 --- a/addons/hr_timesheet/report/project_report_view.xml +++ b/addons/hr_timesheet/report/project_report_view.xml @@ -6,12 +6,27 @@ report.project.task.user - - - - - - + + hr_timesheet_graphview + + + + + + + + + + + report.project.task.user.pivot.inherited + report.project.task.user + + + + + + + diff --git a/addons/hr_timesheet/static/src/js/timesheet_graph.js b/addons/hr_timesheet/static/src/js/timesheet_graph.js index ca09fefb9dc..d4c87383151 100644 --- a/addons/hr_timesheet/static/src/js/timesheet_graph.js +++ b/addons/hr_timesheet/static/src/js/timesheet_graph.js @@ -15,8 +15,10 @@ odoo.define('hr_timesheet.GraphView', function (require) { const currentCompanyId = session.user_context.allowed_company_ids[0]; const currentCompany = session.user_companies.allowed_companies[currentCompanyId]; const currentCompanyTimesheetUOMFactor = currentCompany.timesheet_uom_factor || 1; + const fields = ['unit_amount', 'effective_hours', 'planned_hours', 'remaining_hours', 'total_hours_spent', 'subtask_effective_hours', + 'overtime', 'number_hours', 'difference', 'hours_effective', 'hours_planned', 'timesheet_unit_amount']; - if (this.chart.measure === 'unit_amount' && currentCompanyTimesheetUOMFactor !== 1) { + if (fields.includes(this.chart.measure) && currentCompanyTimesheetUOMFactor !== 1) { // recalculate the Duration values according to the timesheet_uom_factor this.chart.dataPoints.forEach(function (dataPt) { dataPt.value *= currentCompanyTimesheetUOMFactor; diff --git a/addons/hr_timesheet/views/project_portal_templates.xml b/addons/hr_timesheet/views/project_portal_templates.xml index 8f6a10e821c..627d482389f 100644 --- a/addons/hr_timesheet/views/project_portal_templates.xml +++ b/addons/hr_timesheet/views/project_portal_templates.xml @@ -37,7 +37,14 @@ - Total Hours: + + + Total Days: + + + Total Hours: + + diff --git a/addons/hr_timesheet/views/project_views.xml b/addons/hr_timesheet/views/project_views.xml index d4896b7c0e7..4318fce9238 100644 --- a/addons/hr_timesheet/views/project_views.xml +++ b/addons/hr_timesheet/views/project_views.xml @@ -287,5 +287,40 @@ + + project.task.view.graph.inherited + project.task + + + + hr_timesheet_graphview + + + + + + + + + + + + + + project.task.view.pivot.inherited + project.task + + + + + + + + + + + + + diff --git a/addons/sale_timesheet/report/project_profitability_report_analysis_views.xml b/addons/sale_timesheet/report/project_profitability_report_analysis_views.xml index 5e3ed1202a7..55f49521fec 100644 --- a/addons/sale_timesheet/report/project_profitability_report_analysis_views.xml +++ b/addons/sale_timesheet/report/project_profitability_report_analysis_views.xml @@ -11,6 +11,7 @@ + @@ -19,7 +20,7 @@ project.profitability.report.graph project.profitability.report - + @@ -27,6 +28,7 @@ + diff --git a/addons/sale_timesheet/views/sale_timesheet_portal_templates.xml b/addons/sale_timesheet/views/sale_timesheet_portal_templates.xml index b45011bedb1..28d6f333181 100644 --- a/addons/sale_timesheet/views/sale_timesheet_portal_templates.xml +++ b/addons/sale_timesheet/views/sale_timesheet_portal_templates.xml @@ -22,7 +22,14 @@ Timesheets for sales order item: - ( Ordered, Remaining) + + + ( Days Ordered, Days Remaining) + + + ( Ordered, Remaining) + +