Я создаю метод _sql_constraints в Odoo 12, чтобы сделать имя продукта, который является вычисляемым полем, уникальным, и я не получил никакой проверки для дублированных имен?
вот код
from odoo import api, fields, models, _
from odoo.exceptions import UserError, Warning, ValidationError
from statistics import mean
class autopart(models.Model):
_inherit = 'product.template'
@api.multi
@api.depends('item','dsc', 'drc', 'org','car','model', 'manf','year')
def naming(self):
for rec in self:
if rec.year:
rec.name = " ".join(
[rec.item or "", rec.drc or "", rec.dsc or "",
rec.org or "", rec.manf or "", rec.car or "",
rec.model or "", rec.year or ""
])
else:
rec.name = " ".join(
[rec.item and rec.item or "", rec.drc and rec.drc or "", rec.dsc and rec.dsc or "",
rec.org and rec.org or "", rec.manf and rec.manf or "", rec.car and rec.car or "",
rec.model or "",
])
_sql_constraints = [
('model', 'unique(model)', ' model must be unique'),]
name = fields.Char(string="Name", compute=naming, store=True, required=True,)
item = fields.Char( store=True, string="Item", ondelete='restrict', required=False, )
dsc = fields.Char(store=True, string="Description", ondelete='restrict', required=False)
drc = fields.Char(store=True, string="Direction", ondelete='restrict', required=False)
org = fields.Char(store=True, string="Origin", ondelete='restrict', required=True)
manf = fields.Char(store=True, string="Origin manufacture", ondelete='restrict', required=False)
car = fields.Char(store=True, string="Car", ondelete='restrict', required=False,)
year = fields.Char(store=True, string="Year", required=False, ondelete='restrict')
model = fields.Char(string="Model", ondelete='restrict', required=True, default='')