67 lines
2.5 KiB
Python
67 lines
2.5 KiB
Python
# -*- coding: utf-8 -*-
|
|
##############################################################################
|
|
#
|
|
# OpenERP, Open Source Business Applications
|
|
# Copyright (c) 2011 OpenERP S.A. <http://openerp.com>
|
|
#
|
|
# This program is free software: you can redistribute it and/or modify
|
|
# it under the terms of the GNU Affero General Public License as
|
|
# published by the Free Software Foundation, either version 3 of the
|
|
# License, or (at your option) any later version.
|
|
#
|
|
# This program is distributed in the hope that it will be useful,
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
# GNU Affero General Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU Affero General Public License
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
#
|
|
##############################################################################
|
|
import logging
|
|
|
|
import openerp
|
|
|
|
_logger = logging.getLogger(__name__)
|
|
|
|
# TODO this is not needed anymore:
|
|
# - the exposed new service just forward to the model service
|
|
# - the service is called by the web controller, which can
|
|
# now directly call into openerp as the web server is always
|
|
# embedded in openerp.
|
|
|
|
def _edi_dispatch(db_name, method_name, *method_args):
|
|
try:
|
|
registry = openerp.modules.registry.RegistryManager.get(db_name)
|
|
assert registry, 'Unknown database %s' % db_name
|
|
edi = registry['edi.edi']
|
|
cr = registry.db.cursor()
|
|
res = None
|
|
res = getattr(edi, method_name)(cr, *method_args)
|
|
cr.commit()
|
|
except Exception, e:
|
|
_logger.exception('Failed to execute EDI method %s with args %r.',
|
|
method_name, method_args)
|
|
raise
|
|
finally:
|
|
cr.close()
|
|
return res
|
|
|
|
def exp_import_edi_document(db_name, uid, passwd, edi_document, context=None):
|
|
return _edi_dispatch(db_name, 'import_edi', uid, edi_document, None)
|
|
|
|
def exp_import_edi_url(db_name, uid, passwd, edi_url, context=None):
|
|
return _edi_dispatch(db_name, 'import_edi', uid, None, edi_url)
|
|
|
|
@openerp.http.rpc('edi')
|
|
def dispatch(method, params):
|
|
if method in ['import_edi_document', 'import_edi_url']:
|
|
(db, uid, passwd) = params[0:3]
|
|
openerp.service.security.check(db, uid, passwd)
|
|
else:
|
|
raise KeyError("Method not found: %s." % method)
|
|
fn = globals()['exp_' + method]
|
|
return fn(*params)
|
|
|
|
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|