From d2d87796576923f35cecdcc49c0a7525a441be20 Mon Sep 17 00:00:00 2001 From: Vo Minh Thu Date: Thu, 31 Jan 2013 16:45:15 +0100 Subject: [PATCH] [REF] edi: use openerp.service.rpc instead of ExportService. bzr revid: vmt@openerp.com-20130131154515-hb2ginvg8f0fvek2 --- addons/edi/edi_service.py | 57 ++++++++++++++++++++------------------- 1 file changed, 29 insertions(+), 28 deletions(-) diff --git a/addons/edi/edi_service.py b/addons/edi/edi_service.py index 0de44537f55..3bd562ac0bb 100644 --- a/addons/edi/edi_service.py +++ b/addons/edi/edi_service.py @@ -29,37 +29,38 @@ _logger = logging.getLogger(__name__) # - the service is called by the web controller, which can # now directly call into openerp as the web server is always # embedded in openerp. -class edi(): - def _edi_dispatch(self, db_name, method_name, *method_args): - try: - registry = openerp.modules.registry.RegistryManager.get(db_name) - assert registry, 'Unknown database %s' % db_name - edi = registry['edi.edi'] - cr = registry.db.cursor() - res = None - res = getattr(edi, method_name)(cr, *method_args) - cr.commit() - except Exception: - _logger.exception('Failed to execute EDI method %s with args %r.', method_name, method_args) - raise - finally: - cr.close() - return res +def _edi_dispatch(db_name, method_name, *method_args): + try: + registry = openerp.modules.registry.RegistryManager.get(db_name) + assert registry, 'Unknown database %s' % db_name + edi = registry['edi.edi'] + cr = registry.db.cursor() + res = None + res = getattr(edi, method_name)(cr, *method_args) + cr.commit() + except Exception, e: + _logger.exception('Failed to execute EDI method %s with args %r.', + method_name, method_args) + raise + finally: + cr.close() + return res - def exp_import_edi_document(self, db_name, uid, passwd, edi_document, context=None): - return self._edi_dispatch(db_name, 'import_edi', uid, edi_document, None) +def exp_import_edi_document(db_name, uid, passwd, edi_document, context=None): + return _edi_dispatch(db_name, 'import_edi', uid, edi_document, None) - def exp_import_edi_url(self, db_name, uid, passwd, edi_url, context=None): - return self._edi_dispatch(db_name, 'import_edi', uid, None, edi_url) +def exp_import_edi_url(db_name, uid, passwd, edi_url, context=None): + return _edi_dispatch(db_name, 'import_edi', uid, None, edi_url) - def dispatch(self, method, params): - if method in ['import_edi_document', 'import_edi_url']: - (db, uid, passwd ) = params[0:3] - openerp.service.security.check(db, uid, passwd) - else: - raise KeyError("Method not found: %s." % method) - fn = getattr(self, 'exp_'+method) - return fn(*params) +@openerp.service.rpc('edi') +def dispatch(method, params): + if method in ['import_edi_document', 'import_edi_url']: + (db, uid, passwd) = params[0:3] + openerp.service.security.check(db, uid, passwd) + else: + raise KeyError("Method not found: %s." % method) + fn = globals()['exp_' + method] + return fn(*params) # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: