diff options
| author | stephanchrst <stephanchrst@gmail.com> | 2022-05-10 21:51:50 +0700 |
|---|---|---|
| committer | stephanchrst <stephanchrst@gmail.com> | 2022-05-10 21:51:50 +0700 |
| commit | 3751379f1e9a4c215fb6eb898b4ccc67659b9ace (patch) | |
| tree | a44932296ef4a9b71d5f010906253d8c53727726 /addons/stock/controllers/main.py | |
| parent | 0a15094050bfde69a06d6eff798e9a8ddf2b8c21 (diff) | |
initial commit 2
Diffstat (limited to 'addons/stock/controllers/main.py')
| -rw-r--r-- | addons/stock/controllers/main.py | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/addons/stock/controllers/main.py b/addons/stock/controllers/main.py new file mode 100644 index 00000000..02e170e5 --- /dev/null +++ b/addons/stock/controllers/main.py @@ -0,0 +1,37 @@ +# -*- coding: utf-8 -*- + +from odoo import http +from odoo.http import request +from odoo.addons.web.controllers.main import _serialize_exception +from odoo.tools import html_escape + +import json + + +class StockReportController(http.Controller): + + @http.route('/stock/<string:output_format>/<string:report_name>/<int:report_id>', type='http', auth='user') + def report(self, output_format, report_name, token, report_id=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=report_id).get_pdf(line_data), + headers=[ + ('Content-Type', 'application/pdf'), + ('Content-Disposition', 'attachment; filename=' + 'stock_traceability' + '.pdf;') + ] + ) + response.set_cookie('fileToken', token) + return response + except Exception as e: + se = _serialize_exception(e) + error = { + 'code': 200, + 'message': 'Odoo Server Error', + 'data': se + } + return request.make_response(html_escape(json.dumps(error))) |
