diff --git a/addons/hr_timesheet/models/project.py b/addons/hr_timesheet/models/project.py index fdd3b0210ec..554948b69f5 100644 --- a/addons/hr_timesheet/models/project.py +++ b/addons/hr_timesheet/models/project.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- # Part of Odoo. See LICENSE file for full copyright and licensing details. - +import re from lxml import etree from odoo import models, fields, api, _ @@ -222,13 +222,10 @@ class Task(models.Model): def _apply_time_label(self, view_arch): doc = etree.XML(view_arch) 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) + node.set('string', name_with_uom) - for node in doc.xpath("//field[@name='planned_hours'][@widget='timesheet_uom'][not(@string)]"): - node.set('string', _('Planned %s') % encoding_uom.name or '') - for node in doc.xpath("//field[@name='effective_hours'][@widget='timesheet_uom'][not(@string)]"): - node.set('string', _('%s Spent') % encoding_uom.name or '') - for node in doc.xpath("//field[@name='remaining_hours'][@widget='timesheet_uom'][not(@string)]"): - node.set('string', _('Remaining %s') % encoding_uom.name or '') return etree.tostring(doc, encoding='unicode') def unlink(self): diff --git a/addons/hr_timesheet/static/src/js/timesheet_uom.js b/addons/hr_timesheet/static/src/js/timesheet_uom.js index 45979121bfa..982caa462ab 100644 --- a/addons/hr_timesheet/static/src/js/timesheet_uom.js +++ b/addons/hr_timesheet/static/src/js/timesheet_uom.js @@ -111,6 +111,16 @@ if (widgetName === 'float_toggle') { } fieldRegistry.add('timesheet_uom', FieldTimesheetUom); +// widget timesheet_uom_no_toggle is the same as timesheet_uom but without toggle. +// We can modify easly huge amount of days. +let FieldTimesheetUomWithoutToggle = null; +if (widgetName === 'float_toggle') { + FieldTimesheetUomWithoutToggle = FieldTimesheetFactor; +} else { + FieldTimesheetUomWithoutToggle = FieldTimesheetTime; +} +fieldRegistry.add('timesheet_uom_no_toggle', FieldTimesheetUomWithoutToggle); + // bind the formatter and parser method, and tweak the options const _tweak_options = function(options) { @@ -132,6 +142,18 @@ fieldUtils.parse.timesheet_uom = function(value, field, options) { return parser(value, field, options); }; +fieldUtils.format.timesheet_uom_no_toggle = function(value, field, options) { + options = _tweak_options(options || {}); + const formatter = fieldUtils.format[FieldTimesheetUom.prototype.formatType]; + return formatter(value, field, options); +}; + +fieldUtils.parse.timesheet_uom_no_toggle = function(value, field, options) { + options = _tweak_options(options || {}); + const parser = fieldUtils.parse[FieldTimesheetUom.prototype.formatType]; + return parser(value, field, options); +}; + return { FieldTimesheetUom, FieldTimesheetFactor, diff --git a/addons/hr_timesheet/views/project_views.xml b/addons/hr_timesheet/views/project_views.xml index fd79f6d28b5..9d2fc6a4845 100644 --- a/addons/hr_timesheet/views/project_views.xml +++ b/addons/hr_timesheet/views/project_views.xml @@ -83,22 +83,16 @@ -