Skip to content

Commit

Permalink
[IMP] report_csv: allow to evaluate print_report_name for multiple re…
Browse files Browse the repository at this point in the history
…cords
  • Loading branch information
JordiBForgeFlow authored and etobella committed Feb 12, 2019
1 parent cd3816b commit 4cd3676
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
17 changes: 16 additions & 1 deletion report_csv/controllers/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@

from odoo.addons.web.controllers import main as report
from odoo.http import content_disposition, route, request
from odoo.tools.safe_eval import safe_eval

import json
import time


class ReportController(report.ReportController):
Expand All @@ -29,12 +31,25 @@ def report_routes(self, reportname, docids=None, converter=None, **data):
csv = report.with_context(context).render_csv(
docids, data=data
)[0]
filename = "%s.%s" % (report.name, "csv")
if docids:
obj = request.env[report.model].browse(docids)
if report.print_report_name and not len(obj) > 1:
report_name = safe_eval(report.print_report_name,
{'object': obj, 'time': time})
filename = "%s.%s" % (report_name, "csv")
# When we print multiple records we still allow a custom
# filename.
elif report.print_report_name and len(obj) > 1:
report_name = safe_eval(report.print_report_name,
{'objects': obj, 'time': time})
filename = "%s.%s" % (report_name, "csv")
csvhttpheaders = [
('Content-Type', 'text/csv'),
('Content-Length', len(csv)),
(
'Content-Disposition',
content_disposition(report.report_file + '.csv')
content_disposition(filename)
)
]
return request.make_response(csv, headers=csvhttpheaders)
Expand Down
2 changes: 1 addition & 1 deletion report_csv/demo/report.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8" ?>
<odoo>
<!--
© 2017 Creu Blanca
Copyright 2019 Creu Blanca
License AGPL-3.0 or later (https://www.gnuorg/licenses/agpl.html).
-->
<report
Expand Down

0 comments on commit 4cd3676

Please sign in to comment.