[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
This commit is contained in:
William Braeckman
2021-07-26 12:43:50 +00:00
parent 25f8554426
commit e4a4d498ef
2 changed files with 12 additions and 6 deletions
@@ -10,5 +10,8 @@
<field name="active" eval="False"/>
<field name="company_id" eval="False"/>
</record>
<!-- The record above should be archived if no company has overtime counting enabled, otherwise enabled -->
<function model="res.company" name="_check_extra_hours_time_off"/>
</data>
</odoo>
@@ -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