|
@@ -0,0 +1,34 @@
|
|
|
+# -*- coding: utf-8 -*-
|
|
|
+##############################################################################
|
|
|
+# For copyright and license notices, see __openerp__.py file in module root
|
|
|
+# directory
|
|
|
+##############################################################################
|
|
|
+from openerp import models, api, _
|
|
|
+from openerp.exceptions import Warning
|
|
|
+
|
|
|
+
|
|
|
+class product_template(models.Model):
|
|
|
+ _inherit = "product.template"
|
|
|
+
|
|
|
+ @api.one
|
|
|
+ @api.constrains('company_id', 'factory_reference', 'active')
|
|
|
+ def check_unique_company_and_factory_reference(self):
|
|
|
+ if self.active and self.factory_reference and self.company_id:
|
|
|
+ filters = [('company_id', '=', self.company_id.id),
|
|
|
+ ('factory_reference', '=', self.factory_reference),
|
|
|
+ ('active', '=', True)]
|
|
|
+ prod_ids = self.search(filters)
|
|
|
+ if len(prod_ids) > 1:
|
|
|
+ raise Warning(
|
|
|
+ _('There can not be two active products with the same Reference in the same company.'))
|
|
|
+
|
|
|
+ @api.one
|
|
|
+ @api.constrains('company_id', 'ean13', 'active')
|
|
|
+ def check_unique_company_and_ean13(self):
|
|
|
+ if self.active and self.ean13 and self.company_id:
|
|
|
+ filters = [('company_id', '=', self.company_id.id),
|
|
|
+ ('ean13', '=', self.ean13), ('active', '=', True)]
|
|
|
+ prod_ids = self.search(filters)
|
|
|
+ if len(prod_ids) > 1:
|
|
|
+ raise Warning(
|
|
|
+ _('There can not be two active products with the same EAN code in the same company'))
|