From e4a4d498ef226c969ddd968de759f31547b64bec Mon Sep 17 00:00:00 2001 From: William Braeckman Date: Mon, 26 Jul 2021 12:40:33 +0000 Subject: [PATCH] [FIX] hr_holidays_attendance: fix archived time off When installing the `hr_holidays_attendance` module without demo data, and having the count extra hours options enabled, the extra hours time off type would remain archived instead of being enabled. This commit fixes that behaviour and will now start in sync with the company option(s). Closes odoo/odoo#74241 Task ID: 2607436 --- .../data/hr_holidays_attendance_data.xml | 3 +++ .../hr_holidays_attendance/models/res_company.py | 15 +++++++++------ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/addons/hr_holidays_attendance/data/hr_holidays_attendance_data.xml b/addons/hr_holidays_attendance/data/hr_holidays_attendance_data.xml index 963a07053fa..7bcbded3984 100644 --- a/addons/hr_holidays_attendance/data/hr_holidays_attendance_data.xml +++ b/addons/hr_holidays_attendance/data/hr_holidays_attendance_data.xml @@ -10,5 +10,8 @@ + + + diff --git a/addons/hr_holidays_attendance/models/res_company.py b/addons/hr_holidays_attendance/models/res_company.py index 1e13e416b15..ce44045cdf3 100644 --- a/addons/hr_holidays_attendance/models/res_company.py +++ b/addons/hr_holidays_attendance/models/res_company.py @@ -1,19 +1,17 @@ # -*- coding: utf-8 -*- # Part of Odoo. See LICENSE file for full copyright and licensing details. -from odoo import models +from odoo import api, models class ResCompany(models.Model): _inherit = 'res.company' - def write(self, vals): - res = super().write(vals) - if 'hr_attendance_overtime' not in vals: - return res + @api.model + def _check_extra_hours_time_off(self): extra_hours_time_off_type = self.env.ref('hr_holidays_attendance.holiday_status_extra_hours', raise_if_not_found=False) if not extra_hours_time_off_type: - return res + return all_companies = self.env['res.company'].sudo().search([]) # Unarchive time of type if the feature is enabled if any(company.hr_attendance_overtime and not extra_hours_time_off_type.active for company in all_companies): @@ -21,4 +19,9 @@ class ResCompany(models.Model): # Archive time of type if the feature is disabled for all the company if all(not company.hr_attendance_overtime and extra_hours_time_off_type.active for company in all_companies): extra_hours_time_off_type.toggle_active() + + def write(self, vals): + res = super().write(vals) + if 'hr_attendance_overtime' in vals: + self._check_extra_hours_time_off() return res