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.
I want to check _sql_constraints of a model using function
Example , I have a function
# CODE TO CHECK
return True # If ok
return False # If not ok
The below constraint must raise an error if the function returns False
_sql_constraints = [ .................]
I know It is possible by overriding the create method. But I forgot the correct way
Thanks in advance
you have two ways.
std_id = fields.Char(string="Student ID", required=True)
_sql_constraints = [('std_id_uniq', 'unique(std_id)', 'This ID already exists !')]
Another way using api:
mark1 = fields.Integer(string="Total Mark")
if self.mark1 == 0:
raise ValidationError("Please enter the marks !")
Also you can check any logical operations inside the constrains function.
Hope this may help you
Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!
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: 11/4/16, 8:02 AM|
|Seen: 271 times|
|Last updated: 11/5/16, 7:02 AM|