Files
tryton/modules/edocument_peppol_peppyrus/routes.py
T
Cédric Krier 566cd48cd6 Use request data property to parse form data as json
Closes #14984
(grafted from a9624e36e318273942bb1eed3e0258497d7d9f15)

--HG--
branch : 8.0
2026-08-04 07:49:57 +02:00

65 lines
1.9 KiB
Python

# This file is part of Tryton. The COPYRIGHT file at the top level of
# this repository contains the full copyright notices and license terms.
import json
import logging
from trytond import config
from trytond.protocols.wrappers import (
HTTPStatus, Response, abort, set_max_request_size, with_pool,
with_transaction)
from trytond.wsgi import app
logger = logging.getLogger(__name__)
@app.route(
'/<database_name>/edocument_peppol_peppyrus/<identifier>/in',
methods={'POST'})
@set_max_request_size(config.getint(
'edocument_peppol_peppyrus', 'max_size',
default=config.getint('request', 'max_size')))
@with_pool
@with_transaction()
def incoming(request, pool, identifier):
Service = pool.get('edocument.peppol.service')
try:
service, = Service.search([
('peppyrus_identifier', '=', identifier),
])
except ValueError:
abort(HTTPStatus.NOT_FOUND)
message = json.loads(request.data)
Service.peppyrus_store(message)
return Response(status=HTTPStatus.NO_CONTENT)
@app.route(
'/<database_name>/edocument_peppol_peppyrus/<identifier>/out',
methods={'POST'})
@set_max_request_size(config.getint(
'edocument_peppol_peppyrus', 'max_size',
default=config.getint('request', 'max_size')))
@with_pool
@with_transaction()
def outgoing(request, pool, identifier):
Service = pool.get('edocument.peppol.service')
Document = pool.get('edocument.peppol')
try:
service, = Service.search([
('peppyrus_identifier', '=', identifier),
])
except ValueError:
abort(HTTPStatus.NOT_FOUND)
message = json.loads(request.data)
document, = Document.search([
('service', '=', service),
('transmission_id', '=', message['id']),
])
service.peppyrus_update(document, message)
return Response(status=HTTPStatus.NO_CONTENT)