# -*- coding: utf-8 -*- from odoo import fields, models, api, _ from odoo.exceptions import ValidationError class ResourceCalendar(models.Model): _inherit = 'resource.calendar' grace_hour_before_work = fields.Float(string="Grace Hours Before Work") grace_hour_after_work = fields.Float(string="Grace Hours After Work") @api.constrains('grace_hour_before_work', 'grace_hour_after_work') def grace_hour_constrains(self): for rec in self: if hasattr(rec, 'is_full_day') and hasattr(rec, 'noke'): if rec.is_full_day and not rec.noke: if rec.grace_hour_before_work and rec.full_min_sign_in: if rec.grace_hour_before_work > rec.full_min_sign_in: raise ValidationError(_( "Grace hours before work must be less than or equal to minimum sign-in time." )) if rec.grace_hour_after_work and rec.full_max_sign_out: if rec.grace_hour_after_work < rec.full_max_sign_out: raise ValidationError(_( "Grace hours after work must be **greater** than or equal to maximum sign-out time." ))