From 4cc00d44d647fe4b09bb7530782fed1853d71025 Mon Sep 17 00:00:00 2001 From: Kevin Baptiste Date: Thu, 9 Sep 2021 07:17:19 +0000 Subject: [PATCH] [FIX] hr_holidays: correctly compute Time Off type statbuttons The stat buttons were showing incorrect values, the accrual action was not returning, archiving an employee was no longer possible because an incorrect state was used. closes odoo/odoo#76468 Taskid: 2641596 X-original-commit: cc75a1233ed40cb1a4812a5f4a377b8859795b26 Signed-off-by: Kevin Baptiste --- addons/hr_holidays/models/hr_leave_type.py | 16 ++++++++++------ addons/hr_holidays/views/hr_leave_type_views.xml | 2 +- addons/hr_holidays/wizard/hr_departure_wizard.py | 4 ++-- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/addons/hr_holidays/models/hr_leave_type.py b/addons/hr_holidays/models/hr_leave_type.py index 212b8ca832c..43f89924158 100644 --- a/addons/hr_holidays/models/hr_leave_type.py +++ b/addons/hr_holidays/models/hr_leave_type.py @@ -67,6 +67,7 @@ class HolidaysType(models.Model): virtual_leaves_taken = fields.Float( compute='_compute_leaves', string='Virtual Time Off Already Taken', help='Sum of validated and non validated time off requests.') + # KBA TODO in master: rename, change to int group_days_allocation = fields.Float( compute='_compute_group_days_allocation', string='Days Allocated') group_days_leave = fields.Float( @@ -322,23 +323,22 @@ class HolidaysType(models.Model): date_from = fields.Datetime.to_string(datetime.datetime.now().replace(month=1, day=1, hour=0, minute=0, second=0, microsecond=0)) domain = [ ('holiday_status_id', 'in', self.ids), - ('state', '=', 'validate'), '|', ('date_from', '>=', date_from), ('date_from', '=', False), ] grouped_res = self.env['hr.leave.allocation'].read_group( domain, - ['holiday_status_id', 'number_of_days'], + ['holiday_status_id'], ['holiday_status_id'], ) - grouped_dict = dict((data['holiday_status_id'][0], data['number_of_days']) for data in grouped_res) + grouped_dict = dict((data['holiday_status_id'][0], data['holiday_status_id_count']) for data in grouped_res) for allocation in self: allocation.group_days_allocation = grouped_dict.get(allocation.id, 0) def _compute_group_days_leave(self): grouped_res = self.env['hr.leave'].read_group( - [('holiday_status_id', 'in', self.ids), ('state', '=', 'validate'), + [('holiday_status_id', 'in', self.ids), ('date_from', '>=', fields.Datetime.to_string(datetime.datetime.now().replace(month=1, day=1, hour=0, minute=0, second=0, microsecond=0)))], ['holiday_status_id'], ['holiday_status_id'], @@ -348,8 +348,8 @@ class HolidaysType(models.Model): allocation.group_days_leave = grouped_dict.get(allocation.id, 0) def _compute_accrual_count(self): - accrual_allocations = self.env['hr.leave.allocation'].read_group([('employee_id', '!=', False), ('accrual_plan_id', '!=', False), ('state', '=', 'validate')], ['id'], ['holiday_status_id']) - mapped_data = dict((data['holiday_status_id'][0], data['holiday_status_id_count']) for data in accrual_allocations) + accrual_allocations = self.env['hr.leave.accrual.plan'].read_group([('time_off_type_id', 'in', self.ids)], ['time_off_type_id'], ['time_off_type_id']) + mapped_data = dict((data['time_off_type_id'][0], data['time_off_type_id_count']) for data in accrual_allocations) for leave_type in self: leave_type.accrual_count = mapped_data.get(leave_type.id, 0) @@ -424,6 +424,10 @@ class HolidaysType(models.Model): def action_see_accrual_plans(self): self.ensure_one() action = self.env["ir.actions.actions"]._for_xml_id("hr_holidays.open_view_accrual_plans") + action['domain'] = [ + ('time_off_type_id', '=', self.id), + ] action['context'] = { 'default_time_off_type_id': self.id, } + return action diff --git a/addons/hr_holidays/views/hr_leave_type_views.xml b/addons/hr_holidays/views/hr_leave_type_views.xml index e5d61e974c3..4ae2b7b6767 100644 --- a/addons/hr_holidays/views/hr_leave_type_views.xml +++ b/addons/hr_holidays/views/hr_leave_type_views.xml @@ -33,7 +33,7 @@ Time Off -