Add constraint

This commit is contained in:
Alexis de Lattre
2016-05-18 15:08:51 +02:00
parent e3793989c0
commit 64e08b93de

View File

@@ -5,6 +5,7 @@
from openerp.osv import orm, fields
from openerp.tools.translate import _
class ProductTemplate(orm.Model):
@@ -24,6 +25,28 @@ class ProductTemplate(orm.Model):
'intrastat_type': 'product',
}
def _check_intrastat_product(self, cr, uid, ids):
for pt in self.browse(cr, uid, ids):
if pt.intrastat_type == 'product' and pt.type == 'service':
raise orm.except_orm(
_("Error"),
_("On the product %s, you cannot set Product Type to "
"'Service' and Intrastat Type to 'Product'.") % pt.name)
if pt.intrastat_type == 'service' and pt.type == 'product':
raise orm.except_orm(
_("Error"),
_("On the product %s, you cannot set Intrastat Type to "
"'Service' and Product Type to 'Stockable product' "
"(but you can set Product Type to 'Consumable' or "
"'Service').") % pt.name)
return True
_constraints = [(
_check_intrastat_product,
'error msg in raise',
['type', 'intrastat_type'],
)]
class ReportIntrastatCommon(orm.Model):
_inherit = "report.intrastat.common"