From 5c33ebef5f5a018f37e9c8a5c57b914699f2887c Mon Sep 17 00:00:00 2001 From: Jorge Pinna Puissant Date: Wed, 8 May 2019 08:46:46 +0000 Subject: [PATCH] [FIX] hr_holidays: allocation list with leave type in hours When a leave type is in hours, before this commit, in the allocation list the allocation is shown in days. The problem is that the number of days its calculated with the average hour per day. If in the company each day have different working hour, then the number of days calculated with the average didn't represent the actual number of days that the employee can take. Now, in the allocation list, the allocation is shown either with days or hours depending on the leave type. opw-1972133 --- addons/hr_holidays/models/hr_leave_allocation.py | 13 +++++++++++++ .../hr_holidays/views/hr_leave_allocation_views.xml | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/addons/hr_holidays/models/hr_leave_allocation.py b/addons/hr_holidays/models/hr_leave_allocation.py index 2ec46d6568b..123e47f701d 100644 --- a/addons/hr_holidays/models/hr_leave_allocation.py +++ b/addons/hr_holidays/models/hr_leave_allocation.py @@ -12,6 +12,7 @@ from odoo import api, fields, models from odoo.addons.resource.models.resource import HOURS_PER_DAY from odoo.exceptions import AccessError, UserError from odoo.tools.translate import _ +from odoo.tools.float_utils import float_round _logger = logging.getLogger(__name__) @@ -71,6 +72,8 @@ class HolidaysAllocation(models.Model): number_of_hours_display = fields.Float( 'Duration (hours)', compute='_compute_number_of_hours_display', help="UX field allowing to see and modify the allocation duration, computed in hours.") + duration_display = fields.Char('Allocated (Days/Hours)', compute='_compute_duration_display', + help="Field allowing to see the allocation duration in days or hours depending on the type_request_unit") # details parent_id = fields.Many2one('hr.leave.allocation', string='Parent') linked_request_ids = fields.One2many('hr.leave.allocation', 'parent_id', string='Linked Requests') @@ -205,6 +208,16 @@ class HolidaysAllocation(models.Model): for allocation in self: allocation.number_of_hours_display = allocation.number_of_days * (allocation.employee_id.resource_calendar_id.hours_per_day or HOURS_PER_DAY) + @api.multi + @api.depends('number_of_hours_display', 'number_of_days_display') + def _compute_duration_display(self): + for allocation in self: + allocation.duration_display = '%g %s' % ( + (float_round(allocation.number_of_hours_display, precision_digits=2) + if allocation.type_request_unit == 'hour' + else float_round(allocation.number_of_days_display, precision_digits=2)), + _('hours') if allocation.type_request_unit == 'hour' else _('days')) + @api.multi @api.depends('state', 'employee_id', 'department_id') def _compute_can_reset(self): diff --git a/addons/hr_holidays/views/hr_leave_allocation_views.xml b/addons/hr_holidays/views/hr_leave_allocation_views.xml index a9973828ab7..0304653091f 100644 --- a/addons/hr_holidays/views/hr_leave_allocation_views.xml +++ b/addons/hr_holidays/views/hr_leave_allocation_views.xml @@ -175,7 +175,7 @@ - +