From 54db503a657cd7faf7eadabd32f73fa26700b127 Mon Sep 17 00:00:00 2001 From: Alexis de Lattre Date: Wed, 24 May 2017 14:36:16 +0200 Subject: [PATCH] FIX compatibility with sale_rental (and other modules that auto-create products) --- .../intrastat_product_type.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/intrastat_product_type/intrastat_product_type.py b/intrastat_product_type/intrastat_product_type.py index cedbb42..cfaa6dc 100644 --- a/intrastat_product_type/intrastat_product_type.py +++ b/intrastat_product_type/intrastat_product_type.py @@ -41,6 +41,24 @@ class ProductTemplate(models.Model): elif self.type == 'service': self.intrastat_type = 'service' + @api.model + def create(self, vals): + if vals.get('type'): + if not vals.get('intrastat_type'): + if vals['type'] in ('product', 'consu'): + vals['intrastat_type'] = 'product' + elif vals['type'] == 'service': + vals['intrastat_type'] = 'service' + elif ( + vals.get('intrastat_type') == 'product' and + vals['type'] == 'service'): + # usefull because intrastat_type = 'product' by default and + # wizards in other modules that don't depend on this module + # (e.g. sale_rental) may create a product with only + # {'type': 'service'} and no 'intrastat_type' + vals['intrastat_type'] = 'service' + return super(ProductTemplate, self).create(vals) + class L10nFrIntrastatServiceDeclaration(models.Model): _inherit = "l10n.fr.intrastat.service.declaration"