From 2bd71d2c9e807267fca1ebccd9b11a0aff2f88eb Mon Sep 17 00:00:00 2001 From: Kartik Chavda Date: Wed, 16 Nov 2022 13:33:23 +0000 Subject: [PATCH] [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) --- .../models/res_config_settings.py | 25 ++++++++++++++----- .../views/res_config_settings_views.xml | 2 +- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/addons/hr_timesheet/models/res_config_settings.py b/addons/hr_timesheet/models/res_config_settings.py index fc3a7f2d02d..55dc299ed6c 100644 --- a/addons/hr_timesheet/models/res_config_settings.py +++ b/addons/hr_timesheet/models/res_config_settings.py @@ -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): diff --git a/addons/hr_timesheet/views/res_config_settings_views.xml b/addons/hr_timesheet/views/res_config_settings_views.xml index 0dde7c5106d..3b592a1af69 100644 --- a/addons/hr_timesheet/views/res_config_settings_views.xml +++ b/addons/hr_timesheet/views/res_config_settings_views.xml @@ -13,7 +13,7 @@ - +