1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
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
|