From 64e08b93de7dd6360f5c08572547763ed58bb085 Mon Sep 17 00:00:00 2001 From: Alexis de Lattre Date: Wed, 18 May 2016 15:08:51 +0200 Subject: [PATCH] Add constraint --- .../intrastat_product_type.py | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/intrastat_product_type/intrastat_product_type.py b/intrastat_product_type/intrastat_product_type.py index a5753df..91a4953 100644 --- a/intrastat_product_type/intrastat_product_type.py +++ b/intrastat_product_type/intrastat_product_type.py @@ -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"