Hello,
I am new to Odoo and try to study some Odoo Framework 101 (the estate model) I cam across chapter 10 and play around with constraint. The api.constrains works ok but the _sql_constraints/_sql_constrains does not work at all.
from odoo import fields, models, api, exceptions
class EstatePropertyTag(models.Model):
_name = "estate.property.tag"
_description = "Real Estate Tag"
name = fields.Char("Tag Name", required=True)
'''@api.constrains('name')
def _check_tag(self):
for record in self:
# Search for any OTHER record ('id', '!=', record.id)
# that has the SAME name ('name', '=', record.name)
domain = [('name', '=', record.name), ('id', '!=', record.id)]
count = self.search_count(domain)
if count > 0:
raise exceptions.UserError("Tag name must be unique")'''
_sql_constraints = [('unique_name', 'UNIQUE(name)', 'name must be unique!'),]
I try to restart, delete record, update module but nothing work, Does anyone have any insights ? Thanks in advance.
Which version?