Odoo is the world's easiest all-in-one management software. It includes hundreds of business apps:
CRM | e-Commerce | Accounting | Inventory | PoS | Project management | MRP | etc.
Is there a way how to validate on a model level? Let say I have integer field:
comp_min = fields.Integer(string='Min. component item')
comp_max = fields.Integer(string='Max. component item')
How do I set that comp_min have to be greater than 0 and lower than comp_max at the same time?
I know I can set min in template, but it would make sence to define this on model level, other wise I have to add check in template in model on change and possibly other places so I am sure that I do not have mismatched data.
Unfortunately I cant comment on @Axel answer.
According documentation _constraints is deprecated and I shall use constraints decorator, so the right way in odoo 9.x would be something like this?
if 0 < self.comp_min < self.comp_max:
self.comp_min = None # this is not ideal, as value before modification should be here.
if not self._check_comp_min():
'message': 'You have entered wrong value for component'
validation_result = self._check_comp_min()
if validation_result != True:
raise ValidationError('You have entered wrong value for component')
This way I would have just one validation function, but it have to be called twice for onchange (to validate immediatelly) and also on constraint so it is validated when saving. Or is there something similar like Django models have? Seems too much code for simple validation to be executed on change and constraint as well...
About This Community
This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.Register
Odoo Training Center
Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.Test it now
|Asked: 3/9/16, 11:32 AM|
|Seen: 1247 times|
|Last updated: 3/14/16, 6:34 AM|