From 1ac39f6ef86f0bb7ac1cd407562c8a913617a82b Mon Sep 17 00:00:00 2001 From: William Braeckman Date: Tue, 27 Jul 2021 08:19:56 +0000 Subject: [PATCH] [FIX] hr_holidays_attendance: fix deduct extra hours not showing Fixes the deduct extra hours option not showing in time off type form views if no company is linked, it will now use the current company to fetch the setting if no company is linked. Task ID: 2607436 --- .../hr_holidays_attendance/models/hr_leave_type.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/addons/hr_holidays_attendance/models/hr_leave_type.py b/addons/hr_holidays_attendance/models/hr_leave_type.py index ea6b5accac5..020322cc2f1 100644 --- a/addons/hr_holidays_attendance/models/hr_leave_type.py +++ b/addons/hr_holidays_attendance/models/hr_leave_type.py @@ -1,13 +1,13 @@ # -*- coding: utf-8 -*- # Part of Odoo. See LICENSE file for full copyright and licensing details. -from odoo import fields, models +from odoo import api, fields, models class HRLeaveType(models.Model): _inherit = 'hr.leave.type' - hr_attendance_overtime = fields.Boolean(related='company_id.hr_attendance_overtime') + hr_attendance_overtime = fields.Boolean(compute='_compute_hr_attendance_overtime') overtime_deductible = fields.Boolean( "Deduct Extra Hours", default=False, help="Once a time off of this type is approved, extra hours in attendances will be deducted.") @@ -30,3 +30,12 @@ class HRLeaveType(models.Model): res = super()._get_days_request() res[1]['overtime_deductible'] = self.overtime_deductible return res + + @api.depends('company_id.hr_attendance_overtime') + def _compute_hr_attendance_overtime(self): + # If no company is linked to the time off type, use the current company's setting + for leave_type in self: + if leave_type.company_id: + leave_type.hr_attendance_overtime = leave_type.company_id.hr_attendance_overtime + else: + leave_type.hr_attendance_overtime = self.env.company.hr_attendance_overtime