This commit is the 14th commit of a comprehensive refactor of our HTTP framework. See odoo/odoo#78857 for complete historic, discussions and rationnals. * `request.uid = x` => `request.update_env(user=x)`. * `request.context = x` => `request.update_env(context=x)`. * `request.context = dict(request.context, x=y)` => `request.update_context(x=y)`. * `request.cr = None` => `request.cr.close()`. * `http.mono_db()` => `request.db`. * `http.dispatch_rpc()` => `service.dispatch_rpc()`. * `@service.model.check` => `service.model.retrying()`. * `request.endpoint` => `env['ir.http']._match(request.httprequest.path)[0].endpoint`. * `request.routing_iteration `=> `removed`. * `request.jsonrequest` => `request.dispatcher.jsonrequest`. Note that `request.params` is now set much later in the process. If you are in a situation where you values from the query string or the http body you can use `request.get_http_params()`. Note that using the new `request.future_response`, it is possible to add headers and cookies on the response object before the response object is initialized. Please note that headers/cookies saved on the future response will NOT be injected in case of error. PR: odoo#78857 Task: 2571224
36 lines
1.3 KiB
Python
36 lines
1.3 KiB
Python
# -*- coding: utf-8 -*-
|
|
|
|
from odoo import http
|
|
from odoo.http import request
|
|
from odoo.tools import html_escape
|
|
|
|
import json
|
|
|
|
|
|
class StockReportController(http.Controller):
|
|
|
|
@http.route('/stock/<string:output_format>/<string:report_name>', type='http', auth='user')
|
|
def report(self, output_format, report_name=False, **kw):
|
|
uid = request.session.uid
|
|
domain = [('create_uid', '=', uid)]
|
|
stock_traceability = request.env['stock.traceability.report'].with_user(uid).search(domain, limit=1)
|
|
line_data = json.loads(kw['data'])
|
|
try:
|
|
if output_format == 'pdf':
|
|
response = request.make_response(
|
|
stock_traceability.with_context(active_id=kw['active_id'], active_model=kw['active_model']).get_pdf(line_data),
|
|
headers=[
|
|
('Content-Type', 'application/pdf'),
|
|
('Content-Disposition', 'attachment; filename=' + 'stock_traceability' + '.pdf;')
|
|
]
|
|
)
|
|
return response
|
|
except Exception as e:
|
|
se = http.serialize_exception(e)
|
|
error = {
|
|
'code': 200,
|
|
'message': 'Odoo Server Error',
|
|
'data': se
|
|
}
|
|
return request.make_response(html_escape(json.dumps(error)))
|