Friday, 12 January 2018

Odoo Constrains & Odoo _sql_constraints

Implementing Constrain in Odoo (With Method)

@api.constrains('name')
def validate_email(self):
for obj in self:
if len(obj.name) < 2:
raise ValidationError("Please Provide valid Name: %s" % obj.name)
return True


Implementing sql_constraint in Odoo

_sql_constraints = [
('email_uniq', 'unique(email)', 'Email id is unique change your custom email id'),
('phone_uniq','unique(phone)','Phone number is unique so change your phone number ')
]

No comments:

Post a Comment