[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#57557 Taskid: 2326216 X-original-commit: 5b3804402b3ebee5abe7004b8f8caccadaabfe1e Signed-off-by: Yannick Tivisse (yti) <yti@odoo.com>
This commit is contained in:
@@ -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):
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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 >= 100" decoration-warning="progress >= 80 and progress < 100"/>
|
||||
<field name="subtask_effective_hours" widget="timesheet_uom" attrs="{'invisible' : [('allow_subtasks', '=', False)]}" optional="hide"/>
|
||||
|
||||
@@ -586,7 +586,7 @@ class Task(models.Model):
|
||||
compute='_compute_project_id', store=True, readonly=False,
|
||||
index=True, tracking=True, check_company=True, change_default=True)
|
||||
planned_hours = fields.Float("Initially Planned Hours", help='Time planned to achieve this task (including its sub-tasks).', tracking=True)
|
||||
subtask_planned_hours = fields.Float("Sub-tasks Planned Hours", compute='_compute_subtask_planned_hours', help="Sum of the planned hours of all the sub-tasks linked to this task. Usually less or equal to the initially planned hours of this task.")
|
||||
subtask_planned_hours = fields.Float("Sub-tasks Planned Hours", compute='_compute_subtask_planned_hours', help="Sum of the time planned of all the sub-tasks linked to this task. Usually less or equal to the initially time planned of this task.")
|
||||
user_id = fields.Many2one('res.users',
|
||||
string='Assigned to',
|
||||
default=lambda self: self.env.uid,
|
||||
|
||||
Reference in New Issue
Block a user