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 ##############################################################################
26 _logger = logging.getLogger(__name__)
28 class edi(netsvc.ExportService):
30 def __init__(self, name="edi"):
31 netsvc.ExportService.__init__(self, name)
33 def _edi_dispatch(self, db_name, method_name, *method_args):
35 registry = openerp.modules.registry.RegistryManager.get(db_name)
36 assert registry, 'Unknown database %s' % db_name
37 edi_document = registry['edi.document']
38 cr = registry.db.cursor()
40 res = getattr(edi_document, method_name)(cr, *method_args)
43 _logger.exception('Failed to execute EDI method %s with args %r', method_name, method_args)
49 def exp_get_edi_document(self, db_name, edi_token):
50 return self._edi_dispatch(db_name, 'get_document', 1, edi_token)
52 def exp_import_edi_document(self, db_name, uid, passwd, edi_document, context=None):
53 return self._edi_dispatch(db_name, 'import_edi', uid, edi_document, None)
55 def exp_import_edi_url(self, db_name, uid, passwd, edi_url, context=None):
56 return self._edi_dispatch(db_name, 'import_edi', uid, None, edi_url)
58 def dispatch(self, method, params):
59 if method in ['import_edi_document', 'import_edi_url']:
60 (db, uid, passwd ) = params[0:3]
61 openerp.service.security.check(db, uid, passwd)
62 elif method in ['get_edi_document']:
63 # No security check for these methods
66 raise KeyError("Method not found: %s" % method)
67 fn = getattr(self, 'exp_'+method)
71 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: