summaryrefslogtreecommitdiff
path: root/addons/hr_timesheet
diff options
context:
space:
mode:
authorjbm-odoo <jbm@odoo.com>2020-08-28 07:31:13 +0000
committerjbm-odoo <jbm@odoo.com>2020-09-02 13:17:55 +0000
commit5b3804402b3ebee5abe7004b8f8caccadaabfe1e (patch)
tree69bca5700824ae3e8cf35e8a2242689dc3d72bd5 /addons/hr_timesheet
parent9cae18b055f5eaf6de02c25bafc42cb541376830 (diff)
[FIX] hr_timesheet: Widget for planned hours
Before this commit: The field `planned_hours` and `subtask_planned_hours` are present twice. This causes problems with widget: different widgets are put on different fields, but only the last on was put on all of them. Code to edit label with hours/days is not flexible, we need to write each possibilities. After this commit: All fields are present only once in the view. A new widget is created to manage days with a factor. In this new widget, instead of having a toggle button, we can insert a float. When the widget timesheet_uom is set on a field, we modify his string with hours/days. closes odoo/odoo#56702 Taskid: 2326216 Signed-off-by: Yannick Tivisse (yti) <yti@odoo.com>
Diffstat (limited to 'addons/hr_timesheet')
-rw-r--r--addons/hr_timesheet/models/project.py11
-rw-r--r--addons/hr_timesheet/static/src/js/timesheet_uom.js22
-rw-r--r--addons/hr_timesheet/views/project_views.xml26
3 files changed, 36 insertions, 23 deletions
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 @@
<page string="Timesheets" id="timesheets_tab" attrs="{'invisible': [('allow_timesheets', '=', False)]}">
<group>
<group>
- <label for="planned_hours" string="Initially Planned Hours" attrs="{'invisible': [('encode_uom_in_days', '=', True)]}"/>
- <field name="planned_hours" widget="float_time" attrs="{'invisible': [('encode_uom_in_days', '=', True)]}" nolabel="1" />
- <label for="planned_hours" string="Initially Planned Days" attrs="{'invisible': [('encode_uom_in_days', '=', False)]}"/>
- <field name="planned_hours" widget="timesheet_factor" attrs="{'invisible': [('encode_uom_in_days', '=', False)]}" nolabel="1" />
- <label for="subtask_planned_hours" groups="project.group_subtask_project" string="Sub-tasks Planned Hours"
- attrs="{'invisible': ['|', '|', ('allow_subtasks', '=', False), ('subtask_count', '=', 0), ('encode_uom_in_days', '=', True)]}"/>
- <span class="o_row" groups="project.group_subtask_project"
- attrs="{'invisible': ['|', '|', ('allow_subtasks', '=', False), ('subtask_count', '=', 0), ('encode_uom_in_days', '=', True)]}">
- <field name="subtask_planned_hours" widget="float_time"/>
- </span>
- <label for="subtask_planned_hours" groups="project.group_subtask_project" string="Sub-tasks Planned Days"
- attrs="{'invisible': ['|', '|', ('allow_subtasks', '=', False), ('subtask_count', '=', 0), ('encode_uom_in_days', '=', False)]}"/>
- <div class="o_row" groups="project.group_subtask_project"
- attrs="{'invisible': ['|', '|', ('allow_subtasks', '=', False), ('subtask_count', '=', 0), ('encode_uom_in_days', '=', False)]}">
- <field name="subtask_planned_hours" widget="timesheet_uom"/>
+ <div class="o_td_label">
+ <label for="planned_hours" string="Initially Planned Hours" attrs="{'invisible': [('encode_uom_in_days', '=', True)]}"/>
+ <label for="planned_hours" string="Initially Planned Days" attrs="{'invisible': [('encode_uom_in_days', '=', False)]}"/>
+ </div>
+ <field name="planned_hours" widget="timesheet_uom_no_toggle" nolabel="1"/>
+ <div class="o_td_label" groups="project.group_subtask_project" attrs="{'invisible': ['|', ('allow_subtasks', '=', False), ('subtask_count', '=', 0)]}">
+ <label for="subtask_planned_hours" string="Sub-tasks Planned Hours" attrs="{'invisible': [('encode_uom_in_days', '=', True)]}"/>
+ <label for="subtask_planned_hours" string="Sub-tasks Planned Days" attrs="{'invisible': [('encode_uom_in_days', '=', False)]}"/>
</div>
+ <field name="subtask_planned_hours" widget="timesheet_uom_no_toggle" nolabel="1" groups="project.group_subtask_project" attrs="{'invisible': ['|', ('allow_subtasks', '=', False), ('subtask_count', '=', 0)]}"/>
</group>
<group>
<field name="progress" widget="progressbar"/>
@@ -213,7 +207,7 @@
<field name="arch" type="xml">
<field name="company_id" position="after">
<field name="allow_subtasks" invisible="1"/>
- <field name="planned_hours" widget="timesheet_uom" sum="Initially Planned Hours" optional="hide"/>
+ <field name="planned_hours" widget="timesheet_uom_no_toggle" sum="Initially Planned Hours" optional="hide"/>
<field name="effective_hours" widget="timesheet_uom" sum="Effective Hours" optional="show"/>
<field name="remaining_hours" widget="timesheet_uom" sum="Remaining Hours" optional="hide" decoration-danger="progress &gt;= 100" decoration-warning="progress &gt;= 80 and progress &lt; 100"/>
<field name="subtask_effective_hours" widget="timesheet_uom" attrs="{'invisible' : [('allow_subtasks', '=', False)]}" optional="hide"/>