1 # -*- coding: utf-8 -*-
2 ##############################################################################
4 # OpenERP, Open Source Business Applications
5 # Copyright (c) 2011 OpenERP S.A. <http://openerp.com>
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU Affero General Public License as
9 # published by the Free Software Foundation, either version 3 of the
10 # License, or (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU Affero General Public License for more details.
17 # You should have received a copy of the GNU Affero General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
20 ##############################################################################
25 _logger = logging.getLogger(__name__)
27 # TODO this is not needed anymore:
28 # - the exposed new service just forward to the model service
29 # - the service is called by the web controller, which can
30 # now directly call into openerp as the web server is always
31 # embedded in openerp.
33 def _edi_dispatch(db_name, method_name, *method_args):
35 registry = openerp.modules.registry.RegistryManager.get(db_name)
36 assert registry, 'Unknown database %s' % db_name
37 with registry.cursor() as cr:
38 edi = registry['edi.edi']
39 return getattr(edi, method_name)(cr, *method_args)
42 _logger.exception('Failed to execute EDI method %s with args %r.',
43 method_name, method_args)
46 def exp_import_edi_document(db_name, uid, passwd, edi_document, context=None):
47 return _edi_dispatch(db_name, 'import_edi', uid, edi_document, None)
49 def exp_import_edi_url(db_name, uid, passwd, edi_url, context=None):
50 return _edi_dispatch(db_name, 'import_edi', uid, None, edi_url)
52 def dispatch(method, params):
53 if method in ['import_edi_document', 'import_edi_url']:
54 (db, uid, passwd) = params[0:3]
55 openerp.service.security.check(db, uid, passwd)
57 raise KeyError("Method not found: %s." % method)
58 fn = globals()['exp_' + method]
61 openerp.service.wsgi_server.register_rpc_endpoint('edi', dispatch)
63 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: