Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[IMP] Add the possibility to use a custom name if no docids, through context #899

Open
wants to merge 1 commit into
base: 16.0
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 16 additions & 7 deletions report_xlsx/controllers/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,15 @@
return request.make_response(xlsx, headers=xlsxhttpheaders)
return super().report_routes(reportname, docids, converter, **data)

def _get_filename_response(self, report_name, extension, context, response):
filename = "%s.%s" % (report_name, extension)

Check warning on line 52 in report_xlsx/controllers/main.py

View check run for this annotation

Codecov / codecov/patch

report_xlsx/controllers/main.py#L52

Added line #L52 was not covered by tests
if not response.headers.get("Content-Disposition"):
response.headers.add("Content-Disposition", content_disposition(filename))

Check warning on line 54 in report_xlsx/controllers/main.py

View check run for this annotation

Codecov / codecov/patch

report_xlsx/controllers/main.py#L54

Added line #L54 was not covered by tests
else:
response.headers.set("Content-Disposition", content_disposition(filename))

Check warning on line 56 in report_xlsx/controllers/main.py

View check run for this annotation

Codecov / codecov/patch

report_xlsx/controllers/main.py#L56

Added line #L56 was not covered by tests

return response

Check warning on line 58 in report_xlsx/controllers/main.py

View check run for this annotation

Codecov / codecov/patch

report_xlsx/controllers/main.py#L58

Added line #L58 was not covered by tests

@route()
def report_download(self, data, context=None, token=None):
requestcontent = json.loads(data)
Expand All @@ -72,15 +81,17 @@
context, data_context = json.loads(context or "{}"), json.loads(
data.pop("context")
)
context = json.dumps({**context, **data_context})
context = json.dumps({**context, **data_context})

Check warning on line 84 in report_xlsx/controllers/main.py

View check run for this annotation

Codecov / codecov/patch

report_xlsx/controllers/main.py#L84

Added line #L84 was not covered by tests
response = self.report_routes(
reportname, converter="xlsx", context=context, **data
)

report = request.env["ir.actions.report"]._get_report_from_name(
reportname
)
filename = "%s.%s" % (report.name, "xlsx")
response = self._get_filename_response(

Check warning on line 92 in report_xlsx/controllers/main.py

View check run for this annotation

Codecov / codecov/patch

report_xlsx/controllers/main.py#L92

Added line #L92 was not covered by tests
report.name, "xlsx", context, response
)

if docids:
ids = [int(x) for x in docids.split(",")]
Expand All @@ -89,11 +100,9 @@
report_name = safe_eval(
report.print_report_name, {"object": obj, "time": time}
)
filename = "%s.%s" % (report_name, "xlsx")
if not response.headers.get("Content-Disposition"):
response.headers.add(
"Content-Disposition", content_disposition(filename)
)
response = self._get_filename_response(

Check warning on line 103 in report_xlsx/controllers/main.py

View check run for this annotation

Codecov / codecov/patch

report_xlsx/controllers/main.py#L103

Added line #L103 was not covered by tests
report_name, "xlsx", context, response
)
return response
except Exception as e:
_logger.exception("Error while generating report %s", reportname)
Expand Down
Loading