From 2fe81d35676f06d671e1acc1dd8308b21adf0aba Mon Sep 17 00:00:00 2001 From: Olivier Dony Date: Thu, 6 Oct 2011 18:33:42 +0200 Subject: [PATCH] [IMP] edi: better user feedback for import errors bzr revid: odo@openerp.com-20111006163342-4ah7fh7dwamegt6z --- addons/edi/models/edi.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/addons/edi/models/edi.py b/addons/edi/models/edi.py index 2cc83eb3483..6f8a7d32e31 100644 --- a/addons/edi/models/edi.py +++ b/addons/edi/models/edi.py @@ -208,9 +208,10 @@ class EDIMixin(object): specific behavior, based on the primitives provided by this mixin.""" def _edi_requires_attributes(self, attributes, edi_document): + model_name = edi_document.get('__imported_model') or edi_document.get('__model') or self._name for attribute in attributes: assert edi_document.get(attribute),\ - 'Attribute `%s` is required in %s EDI documents' % (attribute, self._name) + 'Attribute `%s` is required in %s EDI documents' % (attribute, model_name) # private method, not RPC-exposed as it creates ir.model.data entries as # SUPERUSER based on its parameters @@ -263,8 +264,12 @@ class EDIMixin(object): module, ext_id = ext_id.split('.') if not ':' in module: # this record was not previously EDI-imported - assert module == record._original_module,\ - 'Mismatching module: expected %s, got %s' % (module, record._original_module) + if not module == record._original_module: + # this could happen for data records defined in a module that depends + # on the module that owns the model, e.g. purchase defines + # product.pricelist records. + _logger.debug('Mismatching module: expected %s, got %s, for %s', + module, record._original_module, record) # ID is unique cross-db thanks to db_uuid module = "%s:%s" % (module, db_uuid) @@ -557,7 +562,11 @@ class EDIMixin(object): # skip metadata and empty fields if field_name.startswith('__') or field_value is None or field_value is False: continue - field = self._all_columns[field_name].column + field_info = self._all_columns.get(field_name) + if not field_info: + _logger.warning('Ignoring unknown field `%s` when importing `%s` EDI document', field_name, self._name) + continue + field = field_info.column # skip function/related fields if isinstance(field, fields.function): _logger.warning("Unexpected function field value found in '%s' EDI document: '%s'" % (self._name, field_name))