from decimal import DefaultContext from odoo import models, fields, api from odoo import tools from odoo.exceptions import UserError class ProductSupplierinfo(models.Model): _inherit = "product.supplierinfo" @api.constrains('name', 'product_tmpl_id') def _check_unique_supplierinfo(self): for record in self: if not record.name or not record.product_tmpl_id: continue domain = [ ('name', '=', record.name.id), ('product_tmpl_id', '=', record.product_tmpl_id.id), ('id', '!=', record.id), ] if self.search_count(domain): raise UserError( "A Vendor Pricelist with the same supplier and product already exists." ) # @api.model # def create(self, vals): # record = super(ProductSupplierinfo, self).create(vals) # self._check_unique_supplierinfo_on_vals(record) # return record # def write(self, vals): # res = super(ProductSupplierinfo, self).write(vals) # for record in self: # self._check_unique_supplierinfo_on_vals(record) # return res