I’m working on an Odoo model where I need to ensure that the allocated_hours field does not exceed 24 hours. I’ve implemented a constraint method to raise a ValidationError when the value exceeds 24 hours.
The validation works correctly, and the error message is displayed in the Odoo interface when navigating away from the view. However, when I update a record and the allocated_hours value exceeds 24, the error message is logged in the console, but the pop-up is not shown in the Odoo interface.And when creating a new record the method is not invoked at all…
Here’s my code:
allocated_hours = fields.Integer('Estimation', compute='_compute_allocated_hours') @api.constrains('allocated_hours') def _check_allocated_hours(self): max_hours = 24.0 # Maximum allowed hours for record in self: if record.allocated_hours > max_hours: raise ValidationError("le max est 24h!!")
Rahma Begag is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.