|
1 |
| -# -*- coding: utf-8 -*- |
2 |
| -import werkzeug |
3 |
| -from werkzeug.exceptions import InternalServerError |
4 |
| -from io import BytesIO |
5 | 1 | from odoo import http
|
6 | 2 | from odoo.http import request
|
7 |
| -from odoo.tools.misc import html_escape |
8 |
| - |
9 |
| -import json |
10 | 3 |
|
11 | 4 |
|
12 | 5 | class StockCardReportController(http.Controller):
|
13 |
| - |
14 |
| - @http.route('/stock/stock_card_report/<string:output_format>', type='http', auth='user') |
15 |
| - def report(self, output_format, report_name=False, **kw): |
16 |
| - if output_format == 'pdf': |
17 |
| - report_ref = request.env.ref('stock_card_report.action_stock_card_report_pdf') |
18 |
| - method_name = '_render_qweb_pdf' |
19 |
| - report = getattr(report_ref, method_name)( |
20 |
| - report_ref, |
21 |
| - res_ids=[int(kw['active_id'])], |
22 |
| - data={ |
23 |
| - 'report_type': 'pdf' |
24 |
| - }, |
25 |
| - )[0] |
26 |
| - return request.make_response( |
27 |
| - report, |
28 |
| - headers=[ |
29 |
| - ('Content-Type', 'application/pdf'), |
30 |
| - ('Content-Disposition', f'attachment; filename= Stock_Card_Report.pdf'), |
31 |
| - ], |
32 |
| - ) |
33 |
| - else: |
34 |
| - report_ref = request.env.ref('stock_card_report.action_stock_card_report_xlsx') |
35 |
| - method_name = '_render_xlsx' |
36 |
| - report = getattr(report_ref, method_name)( |
37 |
| - report_ref, |
38 |
| - docids=[int(kw['active_id'])], |
39 |
| - data={ |
40 |
| - 'report_type': 'xlsx' |
41 |
| - }, |
42 |
| - )[0] |
43 |
| - return request.make_response( |
44 |
| - report, |
45 |
| - headers=[ |
46 |
| - ('Content-Type', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'), |
47 |
| - ('Content-Disposition', 'attachment; filename= Stock_Card_Report.xlsx'), |
48 |
| - ], |
49 |
| - ) |
| 6 | + @http.route( |
| 7 | + "/stock/stock_card_report/<string:output_format>", type="http", auth="user" |
| 8 | + ) |
| 9 | + def report(self, output_format, report_name=False, **kw): |
| 10 | + if output_format == "pdf": |
| 11 | + report_ref = request.env.ref( |
| 12 | + "stock_card_report.action_stock_card_report_pdf" |
| 13 | + ) |
| 14 | + method_name = "_render_qweb_pdf" |
| 15 | + report = getattr(report_ref, method_name)( |
| 16 | + report_ref, |
| 17 | + res_ids=[int(kw["active_id"])], |
| 18 | + data={"report_type": "pdf"}, |
| 19 | + )[0] |
| 20 | + return request.make_response( |
| 21 | + report, |
| 22 | + headers=[ |
| 23 | + ("Content-Type", "application/pdf"), |
| 24 | + ( |
| 25 | + "Content-Disposition", |
| 26 | + "attachment; filename= Stock_Card_Report.pdf", |
| 27 | + ), |
| 28 | + ], |
| 29 | + ) |
| 30 | + else: |
| 31 | + report_ref = request.env.ref( |
| 32 | + "stock_card_report.action_stock_card_report_xlsx" |
| 33 | + ) |
| 34 | + method_name = "_render_xlsx" |
| 35 | + report = getattr(report_ref, method_name)( |
| 36 | + report_ref, |
| 37 | + docids=[int(kw["active_id"])], |
| 38 | + data={"report_type": "xlsx"}, |
| 39 | + )[0] |
| 40 | + return request.make_response( |
| 41 | + report, |
| 42 | + headers=[ |
| 43 | + ( |
| 44 | + "Content-Type", |
| 45 | + "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", |
| 46 | + ), |
| 47 | + ( |
| 48 | + "Content-Disposition", |
| 49 | + "attachment; filename= Stock_Card_Report.xlsx", |
| 50 | + ), |
| 51 | + ], |
| 52 | + ) |
0 commit comments