Odoo Constraints Using Tutorials

Source: Internet
Author: User

In the daily development of Odoo, we will inevitably use the constraints, Chinese is the constraint .
First, let's introduce two kinds of constraints in Odoo.

SQL Constraints: Is a constraint that adds a database.
_sql_constraints is the property of Odoo and is a list of the meta-ancestors, each of which is a database constraint. The first element of the Ganso is the constraint name, the second element is the constraint rule (postgresql constraint rule), and the third parameter is the warning message if the constraint is violated.

_sql_constraints = [        ('Name_description_check',         'CHECK (Name! = description)',         "The title of the course should not being the description"),        ('Name_unique',         'UNIQUE (name)',         "The course title must be unique"),    ]

Note that in the use of SQL Constraints, you need to ensure that the current database does not violate the constraint of the data, if there is a violation of the constraint of the data in the update module when the system log will have a warning message, you should pay attention to this.

Constraints:

@api. Constrains ('instructor_id','Attendee_ids')    def_check_instructor_not_in_attendees (self): forRinchSelf :ifr.instructor_id andr.instructor_idinchR.attendee_ids:RaiseExceptions. ValidationError ("A Session ' s instructor can ' t be an attendee")

Odoo's constraints, is through the adorner @api.constrains (field), each time the record changes, if the inclusion of the adorner definition of the field will trigger the following method, so you need to determine in the method whether the constraint is violated, if violated, The raise exception is passed to pop up the warning box and prevent the record from being saved. When using Odoo constraints, it is possible that a record in the system that has violated the constraint can take effect on the new record.

Odoo Constraints Using Tutorials

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.