From 2c366acbf01664c4f8d3230d402aa5f2fb46e078 Mon Sep 17 00:00:00 2001 From: Jorge Pinna Puissant Date: Wed, 8 May 2019 09:23:56 +0000 Subject: [PATCH] [FIX] hr_holidays: leave type in hours in new leave request When a new request of leave is created, some fields are computed to calculate if it's possible or not, to take the leave (virtual_remaining_leaves, leaves_taken, remaining_leaves and max_leaves). These fields are computed using the fields : allocation : hr_leave_allocation.number_of_days. and request : hr_leave.number_of_days. When a leave type is in hours, both of these fields are calculated differently: allocation: The allocation field is calculated dividing the number of hours registered by the user per the average hour per working day. (https://github.com/odoo/odoo/blob/d809b476819968837b61bdd78fbf101caac73adc/addons/hr_holidays/models/hr_leave_allocation.py#L236) request : The request field is calculated by finding the real number of requested days. (https://github.com/odoo/odoo/blob/d809b476819968837b61bdd78fbf101caac73adc/addons/hr_holidays/models/hr_leave.py#L360) If in the company each day have different working hour, then the number of days calculated with the average hours didn't represent the real number of days that the employee can take. This issue can avoid the employee to take a leave even if he has the correct number of hours to take it. Now, the fields (virtual_remaining_leaves, leaves_taken, remaining_leaves and max_leaves) are calculated using either the days fields or the hours fields depending on the leave type. opw-1972133 closes odoo/odoo#33244 Signed-off-by: Nicolas Martinelli (nim) --- addons/hr_holidays/i18n/hr_holidays.pot | 12 ++++++++++ addons/hr_holidays/models/hr_leave_type.py | 26 ++++++++++++++++------ 2 files changed, 31 insertions(+), 7 deletions(-) diff --git a/addons/hr_holidays/i18n/hr_holidays.pot b/addons/hr_holidays/i18n/hr_holidays.pot index 541bc9799c6..6d1e595132a 100644 --- a/addons/hr_holidays/i18n/hr_holidays.pot +++ b/addons/hr_holidays/i18n/hr_holidays.pot @@ -20,6 +20,18 @@ msgstr "" msgid " Fixed by HR: allocated by HR and cannot be bypassed; users can request leaves; Fixed by HR + allocation request: allocated by HR and users can request leaves and allocations; No allocation: no allocation by default, users can freely request leaves;" msgstr "" +#. module: hr_holidays +#: code:addons/hr_holidays/models/hr_leave_type.py:265 +#, python-format +msgid " days" +msgstr "" + +#. module: hr_holidays +#: code:addons/hr_holidays/models/hr_leave_type.py:265 +#, python-format +msgid " hours" +msgstr "" + #. module: hr_holidays #: model_terms:ir.ui.view,arch_db:hr_holidays.report_holidayssummary msgid "!important ></td>" diff --git a/addons/hr_holidays/models/hr_leave_type.py b/addons/hr_holidays/models/hr_leave_type.py index 318505f7108..bee9a4939fd 100644 --- a/addons/hr_holidays/models/hr_leave_type.py +++ b/addons/hr_holidays/models/hr_leave_type.py @@ -162,10 +162,16 @@ class HolidaysType(models.Model): for request in requests: status_dict = result[request.holiday_status_id.id] - status_dict['virtual_remaining_leaves'] -= request.number_of_days + status_dict['virtual_remaining_leaves'] -= (request.number_of_hours_display + if request.leave_type_request_unit == 'hour' + else request.number_of_days) if request.state == 'validate': - status_dict['leaves_taken'] += request.number_of_days - status_dict['remaining_leaves'] -= request.number_of_days + status_dict['leaves_taken'] += (request.number_of_hours_display + if request.leave_type_request_unit == 'hour' + else request.number_of_days) + status_dict['remaining_leaves'] -= (request.number_of_hours_display + if request.leave_type_request_unit == 'hour' + else request.number_of_days) for allocation in allocations: status_dict = result[allocation.holiday_status_id.id] @@ -173,9 +179,15 @@ class HolidaysType(models.Model): # note: add only validated allocation even for the virtual # count; otherwise pending then refused allocation allow # the employee to create more leaves than possible - status_dict['virtual_remaining_leaves'] += allocation.number_of_days - status_dict['max_leaves'] += allocation.number_of_days - status_dict['remaining_leaves'] += allocation.number_of_days + status_dict['virtual_remaining_leaves'] += (allocation.number_of_hours_display + if allocation.type_request_unit == 'hour' + else allocation.number_of_days) + status_dict['max_leaves'] += (allocation.number_of_hours_display + if allocation.type_request_unit == 'hour' + else allocation.number_of_days) + status_dict['remaining_leaves'] += (allocation.number_of_hours_display + if allocation.type_request_unit == 'hour' + else allocation.number_of_days) return result @@ -250,7 +262,7 @@ class HolidaysType(models.Model): 'count': _('%g remaining out of %g') % ( float_round(record.virtual_remaining_leaves, precision_digits=2) or 0.0, float_round(record.max_leaves, precision_digits=2) or 0.0, - ) + ) + (_(' hours') if record.request_unit == 'hour' else _(' days')) } res.append((record.id, name)) return res