Hello , in this blog we will learn the definition of @api.constrains in Odoo and it’s use cases.
To enforce date integrity Odoo support tow type of constraints : SQL and Python we are going to talk about the Pythonic way @api.constrains.
In our daily usage of Odoo we face some condition that should be checked before using theme in our functions ,for example : check start_date is below end_date , make sure the marks do not underpass 20 (which will be our case in this post).
Here we have declared a marks class and it’s corresponding fields , we want to check that the marks Float exam 1,exam 2,average does not exceed 20.
So we’re going to loop on our record using @api.one (which we are going to explain on next posts). then declare @api.constraints containing the fields which we are going to check. if one or all the fields exceed 20 we trigger an exception and we got a popup we the defined message.
Note : for @api.depends() you can check the previous post http://wp.me/p8qqyC-4i
if you want to try this you can find the code source under our OdooForBeginners github repositories on this link :