[REF] edi: use openerp.service.rpc instead of ExportService.
bzr revid: vmt@openerp.com-20130131154515-hb2ginvg8f0fvek2
This commit is contained in:
parent
f2238e06f8
commit
d2d8779657
|
@ -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:
|
||||
|
|
Loading…
Reference in New Issue