From 0ae1085c1e599d6049d8bc9db4ffc08c635512d7 Mon Sep 17 00:00:00 2001 From: carlo Date: Sun, 7 May 2017 15:30:54 +0200 Subject: [PATCH] fix error on Legnolandia import --- data_migration/utils/product_importer.py | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/data_migration/utils/product_importer.py b/data_migration/utils/product_importer.py index 595835bb8..6609b4035 100644 --- a/data_migration/utils/product_importer.py +++ b/data_migration/utils/product_importer.py @@ -228,6 +228,8 @@ def get_uom(self, cr, uid, name): 'N.': 'PCE', 'LT': 'Litre', 'Mt.': 'PCE', + 'pz': 'PCE', + 'copp': 'PCE', } if name and len(name) > 20 and name[:20] == 'product.product_uom_': @@ -239,7 +241,11 @@ def get_uom(self, cr, uid, name): _logger.error(error) self.error.append(error) return False - + if uom_name not in translate: + warning = "Row {0}: Can't find valid UOM {1}".format(self.processed_lines, name) + _logger.warning(warning) + self.warning.append(warning) + return self.pool['product.product'].default_get(cr, uid, ['uom_id'], context=self.context)['uom_id'] uom_ids = self.pool['product.uom'].search(cr, uid, [('name', '=ilike', translate[uom_name])], context=self.context) if len(uom_ids) == 1: return uom_ids[0] @@ -278,7 +284,7 @@ def get_suppliers(self, cr, uid, names): for name in names: name = name.strip() - partner_ids = self.pool['res.partner'].search(cr, uid, [('name', '=ilike', name), ('supplier', '=', True)]) + partner_ids = self.pool['res.partner'].search(cr, uid, [('name', '=ilike', name), ('supplier', '=', True)], context=self.context) if len(partner_ids) == 1: supplier_ids += partner_ids @@ -482,7 +488,17 @@ def import_row(self, cr, uid, row_list): self.warning.append(warning) if hasattr(record, 'supplier') and record.supplier: - partner_ids = self.get_suppliers(cr, uid, record.supplier) + if isinstance(record.supplier, unicode): + supplier = record.supplier + else: + supplier = unicode(record.supplier, 'utf-8') + try: + partner_ids = self.get_suppliers(cr, uid, supplier) + except Exception as e: + error = u"Row {0}: Supplier not valid {1}: {2}".format(self.processed_lines, record.supplier, e) + _logger.error(error) + self.warning.append(error) + partner_ids = False else: partner_ids = False @@ -582,7 +598,7 @@ def getProductTemplateID(self, product_id): # Get the product_tempalte ID # Retrive the record associated with the product id - productObject = self.pool.get('product.product').browse(self.cr, self.uid, product_id, self.context) + productObject = self.pool['product.product'].browse(self.cr, self.uid, product_id, self.context) # Retrive the template id product_template_id = productObject.product_tmpl_id.id