From e47fbc56ea6e29620ecb9c6bd6df024565d1e7a5 Mon Sep 17 00:00:00 2001 From: Olivier Dony Date: Thu, 6 Oct 2011 13:33:19 +0200 Subject: [PATCH] [IMP] edi: support for __import_module and __import_model metadata This is useful for transtyping documents, for example a sale.order must be converted to a purchase.order when it is imported via EDI. bzr revid: odo@openerp.com-20111006113319-ll5rfavzwzftkydb --- addons/edi/models/edi.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/addons/edi/models/edi.py b/addons/edi/models/edi.py index 2394dd7012e..2cc83eb3483 100644 --- a/addons/edi/models/edi.py +++ b/addons/edi/models/edi.py @@ -141,13 +141,14 @@ class edi_document(osv.osv): ir_module = self.pool.get('ir.module.module') res = [] for edi_document in edi_documents: - module = edi_document.get('__module') + module = edi_document.get('__import_module') or edi_document.get('__module') + assert module, 'a `__module` or `__import_module` attribute is required in each EDI document' if module != 'base' and not ir_module.search(cr, uid, [('name','=',module),('state','=','installed')]): raise osv.except_osv(_('Missing Application'), _("The document you are trying to import requires the OpenERP `%s` application. " - "The OpenERP configuration assistant will help with this if you are connected as an administrator.")%(module,)) - model = edi_document.get('__model') - assert model, '__model attribute is required in each EDI document' + "You can install it by connecting as the administrator and opening the configuration assistant.")%(module,)) + model = edi_document.get('__import_model') or edi_document.get('__model') + assert model, 'a `__model` or `__import_model` attribute is required in each EDI document' model_obj = self.pool.get(model) record_id = model_obj.edi_import(cr, uid, edi_document, context=context) res.append((model, record_id)) @@ -538,9 +539,10 @@ class EDIMixin(object): * After finding the database ID of the final record in the database, connect it to the parent record. """ - assert self._name == edi_document['__model'],\ - "EDI Document Model and current model do not match: '%s' (EDI) vs '%s' (current)" % \ - (edi_document['__model'], self._name) + assert self._name == edi_document.get('__import_model') or \ + ('__import_model' not in edi_document and self._name == edi_document.get('__model')), \ + "EDI Document Model and current model do not match: '%s' (EDI) vs '%s' (current)" % \ + (edi_document['__model'], self._name) # First check the record is now already known in the database, in which case it is ignored ext_id_members = split_external_id(edi_document['__id'])