[FIX] mail: no_auto_thread default True if the model has no mail.thread
[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         with registry.cursor() as cr:
38             edi = registry['edi.edi']
39             return getattr(edi, method_name)(cr, *method_args)
40
41     except Exception, e:
42         _logger.exception('Failed to execute EDI method %s with args %r.',
43             method_name, method_args)
44         raise
45
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)
48
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)
51
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)
56     else:
57         raise KeyError("Method not found: %s." % method)
58     fn = globals()['exp_' + method]
59     return fn(*params)
60
61 openerp.service.wsgi_server.register_rpc_endpoint('edi', dispatch)
62
63 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: