Odoo helps you to set constraints to variants which we can perform using python and model constraints. In odoo python constraints are specified along with methods. This Slide will provide an insight on python and model constraints in Odoo 15. In python, constraints are defined along with a method decorated with constraints().
2. INTRODUCTION
Odoo helps you to set constraints to variants which we can perform using python and
model constraints. In odoo python constraints are specified along with methods.
This Slide will provide an insight on python and model constraints in Odoo 15.
In python, constraints are defined along with a method decorated with constraints().
3. Python Constraints
Add a constraint while saving a record you can use the following code which restricts the user from entering a
negative value for the amount.
4. The field for which constraint is to be applied is specified along with the decorator constraints().
provide multiple field values as arguments in the function. Therefore, the function gets invoked
each time the value in the field gets modified/changed
6. There are certain limitations for using constraints()
1. constrains() are not supported along with related fields. They can only be applied to simple fields. For
example related fields like partner_id.phone.
2. constrains() can only be applied to fields that are included in the create and write call because if the
field is which is not contained in the view will not trigger a call to python function.
7. SQL constraints
The SQL constraints are applied on models using _sql_constraints.
In odoo _sql_constraints consist of three parts they are name, definition, and message.
8. name - Name for the sql constraint
definition - Constraint to be applied on the table.
message - Validation message to be displayed.
9. Unique Constraint:
It is used along with a ‘unique’ keyword.
The unique constraint helps you to check whether a specified column in rows
satisfies the unique constraint.
10. For More
Details
Check our company website for related blogs and Odoo
book.
Odoo Book V15
Check our YouTube channel for functional and technical
videos in Odoo.
Model Constraints & Python Constraints in Odoo15