In the wizard "Post Journal Entries", we can now select multiple journals and multipl...
[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 import openerp.netsvc as netsvc
25
26 _logger = logging.getLogger(__name__)
27
28 class edi(netsvc.ExportService):
29
30     def __init__(self, name="edi"):
31         netsvc.ExportService.__init__(self, name)
32
33     def _edi_dispatch(self, 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:
43             _logger.exception('Failed to execute EDI method %s with args %r.', method_name, method_args)
44             raise
45         finally:
46             cr.close()
47         return res
48
49     def exp_import_edi_document(self, db_name, uid, passwd, edi_document, context=None):
50         return self._edi_dispatch(db_name, 'import_edi', uid, edi_document, None)
51
52     def exp_import_edi_url(self, db_name, uid, passwd, edi_url, context=None):
53         return self._edi_dispatch(db_name, 'import_edi', uid, None, edi_url)
54
55     def dispatch(self, method, params):
56         if method in ['import_edi_document',  'import_edi_url']:
57             (db, uid, passwd ) = params[0:3]
58             openerp.service.security.check(db, uid, passwd)
59         else:
60             raise KeyError("Method not found: %s." % method)
61         fn = getattr(self, 'exp_'+method)
62         return fn(*params)
63
64 edi()
65 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: