summaryrefslogtreecommitdiff
path: root/fixco_custom/models/product_supplierinfo.py
diff options
context:
space:
mode:
Diffstat (limited to 'fixco_custom/models/product_supplierinfo.py')
-rw-r--r--fixco_custom/models/product_supplierinfo.py37
1 files changed, 37 insertions, 0 deletions
diff --git a/fixco_custom/models/product_supplierinfo.py b/fixco_custom/models/product_supplierinfo.py
new file mode 100644
index 0000000..2ff911f
--- /dev/null
+++ b/fixco_custom/models/product_supplierinfo.py
@@ -0,0 +1,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