[FIX] account_payment: the amount_residual field is not searchable so it cannot be...
[odoo/odoo.git] / addons / edi / edi_service.py
1 # -*- coding: utf-8 -*-
2 ##############################################################################
3 #
4 #    OpenERP, Open Source Business Applications
5 #    Copyright (c) 2011 OpenERP S.A. <http://openerp.com>
6 #
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.
11 #
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.
16 #
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/>.
19 #
20 ##############################################################################
21 import logging
22
23 import openerp
24
25 _logger = logging.getLogger(__name__)
26
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.
32
33 def _edi_dispatch(db_name, method_name, *method_args):
34     try:
35         registry = openerp.modules.registry.RegistryManager.get(db_name)
36         assert registry, 'Unknown database %s' % db_name
37         edi = registry['edi.edi']
38         cr = registry.db.cursor()
39         res = None
40         res = getattr(edi, method_name)(cr, *method_args)
41         cr.commit()
42     except Exception, e:
43         _logger.exception('Failed to execute EDI method %s with args %r.',
44             method_name, method_args)
45         raise
46     finally:
47         cr.close()
48     return res
49
50 def exp_import_edi_document(db_name, uid, passwd, edi_document, context=None):
51     return _edi_dispatch(db_name, 'import_edi', uid, edi_document, None)
52
53 def exp_import_edi_url(db_name, uid, passwd, edi_url, context=None):
54     return _edi_dispatch(db_name, 'import_edi', uid, None, edi_url)
55
56 def dispatch(method, params):
57     if method in ['import_edi_document',  'import_edi_url']:
58         (db, uid, passwd) = params[0:3]
59         openerp.service.security.check(db, uid, passwd)
60     else:
61         raise KeyError("Method not found: %s." % method)
62     fn = globals()['exp_' + method]
63     return fn(*params)
64
65 openerp.service.wsgi_server.register_rpc_endpoint('edi', dispatch)
66
67 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: