[IMP] hr_timesheet: convert encoding unit in selection field
Before this commit, the encoding unit used in the timesheet app was a `Many2one` field and the user can select the UoM to use. However, only 2 units of measure are supported on the Timesheets app, the `Days` and the `Hours` records created in the data. Also, when the encoding is in `Days`, the user cannot directly know he can just set 0, a half-day or a day for a timesheet in the different views of the Timesheets App. This commit replaces the many2one field by a Selection one containing 2 choices, one for `Days / Half-Days` and another one `Hours / Minutes`, to explicitly restrict the choice to the UoMs supported in the Timesheets app. Also, the label of the both choices is more detailed to explicitly notice the user will can select a half-day or day is the encoding unit is `Days / Half-Days` and can edit the hours and minutes on a timesheet when the encoding method selected is `Hours / Minutes`. task-3067111 closes odoo/odoo#105905 Related: odoo/enterprise#34043 Related: odoo/upgrade#4040 Signed-off-by: Xavier Bol (xbo) <xbo@odoo.com>
This commit is contained in:
@@ -18,15 +18,28 @@ class ResConfigSettings(models.TransientModel):
|
||||
help="This will set the unit of measure used in projects and tasks.\n"
|
||||
"If you use the timesheet linked to projects, don't "
|
||||
"forget to setup the right unit of measure in your employees.")
|
||||
timesheet_encode_uom_id = fields.Many2one('uom.uom', string="Encoding Unit",
|
||||
related='company_id.timesheet_encode_uom_id', readonly=False)
|
||||
is_encode_uom_days = fields.Boolean(compute='_compute_is_encode_uom_days')
|
||||
timesheet_encode_method = fields.Selection([
|
||||
('hours', 'Hours / Minutes'),
|
||||
('days', 'Days / Half-Days'),
|
||||
], string='Encoding Method', compute="_compute_timesheet_encode_method", inverse="_inverse_timesheet_encode_method", required=True)
|
||||
|
||||
@api.depends('timesheet_encode_uom_id')
|
||||
def _compute_is_encode_uom_days(self):
|
||||
product_uom_day = self.env.ref('uom.product_uom_day')
|
||||
@api.depends('company_id')
|
||||
def _compute_timesheet_encode_method(self):
|
||||
uom_day = self.env.ref('uom.product_uom_day', raise_if_not_found=False)
|
||||
for settings in self:
|
||||
settings.is_encode_uom_days = settings.timesheet_encode_uom_id == product_uom_day
|
||||
settings.timesheet_encode_method = 'days' if settings.company_id.timesheet_encode_uom_id == uom_day else 'hours'
|
||||
|
||||
def _inverse_timesheet_encode_method(self):
|
||||
uom_day = self.env.ref('uom.product_uom_day', raise_if_not_found=False)
|
||||
uom_hour = self.env.ref('uom.product_uom_hour', raise_if_not_found=False)
|
||||
for settings in self:
|
||||
settings.company_id.timesheet_encode_uom_id = uom_day if settings.timesheet_encode_method == 'days' else uom_hour
|
||||
|
||||
@api.depends('timesheet_encode_method')
|
||||
def _compute_is_encode_uom_days(self):
|
||||
for settings in self:
|
||||
settings.is_encode_uom_days = settings.timesheet_encode_method == 'days'
|
||||
|
||||
@api.depends('module_hr_timesheet')
|
||||
def _compute_timesheet_modules(self):
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
<field name="project_time_mode_id" options="{'no_create': True, 'no_open': True}"/>
|
||||
</setting>
|
||||
<setting company_dependent="1" help="Time unit used to record your timesheets" id="time_unit_timesheets_setting">
|
||||
<field name="timesheet_encode_uom_id" options="{'no_create': True, 'no_open': True}" required="1" class="col-lg-5 ps-0"/>
|
||||
<field name="timesheet_encode_method" class="col-lg-5 ps-0" widget="radio"/>
|
||||
<field name="is_encode_uom_days" invisible="1"/>
|
||||
</setting>
|
||||
<setting help="Track your time from anywhere, even offline, with our web/mobile apps" id="synchronize_web_mobile_setting">
|
||||
|
||||
Reference in New Issue
Block a user