-
-
Notifications
You must be signed in to change notification settings - Fork 765
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
[16.0][REF][ADD] report_csv, report_format_option #864
Conversation
38e13fe
to
e09e97b
Compare
show_encoding = fields.Boolean(compute="_compute_show_encoding") | ||
line_ending = fields.Char( | ||
help="Line ending to be applied to the generated report. e.g., crlf" | ||
) |
This comment was marked as outdated.
This comment was marked as outdated.
Sorry, something went wrong.
_inherit = "ir.actions.report" | ||
|
||
encoding = fields.Char( | ||
help="Encoding to be applied to the generated CSV file. " "e.g. cp932" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
help="Encoding to be applied to the generated CSV file. " "e.g. cp932" | |
help="Encoding to be applied to the generated CSV file. e.g. cp932" |
) | ||
show_encoding = fields.Boolean(compute="_compute_show_encoding") | ||
line_ending = fields.Char( | ||
help="Line ending to be applied to the generated report. e.g., crlf" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nitpick
help="Line ending to be applied to the generated report. e.g., crlf" | |
help="Line ending to be applied to the generated report. e.g. crlf" |
@@ -0,0 +1,2 @@ | |||
This is a technical module to add encoding fields to ir.actions.report model and it does nothing by itself. | |||
The module is expected to be a dependency of other reporting modules (e.g., report_csv). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nitpick
The module is expected to be a dependency of other reporting modules (e.g., report_csv). | |
The module is expected to be a dependency of other reporting modules (e.g. report_csv). |
1dca959
to
10e001e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code review + checked presentation in runboat.
compute="_compute_show_encoding", | ||
help="Technical field to control the visibility of the encoding field.", | ||
) | ||
line_ending = fields.Char( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@AungKoKoLin1997 Can we actually make it a selection field, pre-defining 'LF', 'CRLF' and 'CR'?
I think we can also extend method _render_qweb_text()
in this module to handle the conversion of line ending and encoding.
def _compute_show_encoding(self): | ||
"""Extend this method to show the encoding field in the report form.""" | ||
for report in self: | ||
report.show_encoding = False |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
def _compute_show_line_ending(self): | ||
"""Extend this method to show the line ending field in the report form.""" | ||
for report in self: | ||
report.show_line_ending = False |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
[("LF", "LF (\\n)"), ("CRLF", "CRLF (\\r\\n)"), ("CR", "CR (\\r)")], | ||
default="LF", | ||
help="Select the type of line ending.", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[("LF", "LF (\\n)"), ("CRLF", "CRLF (\\r\\n)"), ("CR", "CR (\\r)")], | |
default="LF", | |
help="Select the type of line ending.", | |
[("crlf", "CRLF (\\r\\n)"), ("cr", "CR (\\r)")], | |
help="Select the type of line ending in case the report needs to be output with other line ending than 'LF'.", |
report = self._get_report(report_ref) | ||
# If specific encoding is set on the report, use it; otherwise, fallback to utf-8 | ||
encoding = report.encoding or "utf-8" | ||
# Decode content assuming it is 'utf-8' to work with it as a string | ||
content_str = content.decode("utf-8") | ||
# Adjust line endings if specified, while content is still a string | ||
line_ending = report.line_ending or "" | ||
if line_ending == "CRLF": | ||
content_str = content_str.replace("\n", "\r\n") | ||
elif report.line_ending == "CR": | ||
content_str = content_str.replace("\n", "\r") | ||
# Then encode with the desired encoding | ||
encode_options = {} | ||
if report.encode_error_handling: | ||
encode_options["errors"] = report.encode_error_handling | ||
# Re-encode the content with or without the errors parameter | ||
content_encoded = content_str.encode(encoding, **encode_options) | ||
return content_encoded, content_type |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
report = self._get_report(report_ref) | |
# If specific encoding is set on the report, use it; otherwise, fallback to utf-8 | |
encoding = report.encoding or "utf-8" | |
# Decode content assuming it is 'utf-8' to work with it as a string | |
content_str = content.decode("utf-8") | |
# Adjust line endings if specified, while content is still a string | |
line_ending = report.line_ending or "" | |
if line_ending == "CRLF": | |
content_str = content_str.replace("\n", "\r\n") | |
elif report.line_ending == "CR": | |
content_str = content_str.replace("\n", "\r") | |
# Then encode with the desired encoding | |
encode_options = {} | |
if report.encode_error_handling: | |
encode_options["errors"] = report.encode_error_handling | |
# Re-encode the content with or without the errors parameter | |
content_encoded = content_str.encode(encoding, **encode_options) | |
return content_encoded, content_type | |
if not report.encoding and not report.line_ending: | |
return content, content_type | |
report = self._get_report(report_ref) | |
content_str = content.decode("utf-8") | |
if report.line_ending == "crlf": | |
content_str = content_str.replace("\n", "\r\n") | |
elif report.line_ending == "cr": | |
content_str = content_str.replace("\n", "\r") | |
# If specific encoding is set on the report, use it; otherwise, fallback to utf-8 | |
encoding = report.encoding or "utf-8" | |
encode_options = {} | |
if report.encode_error_handling: | |
encode_options["errors"] = report.encode_error_handling | |
content = content_str.encode(encoding, **encode_options) | |
return content, content_type |
@AungKoKoLin1997 Can you please add tests to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please apply the suggested change, squash commits and update the commit message with rationale.
* Line Ending: Select the type of line ending—'CRLF', 'CR' or leave blank, as necessary. | ||
* 'CRLF': Stands for 'Carriage Return' + 'Line Feed'. It's used as a line ending in Windows, signifying the end of a line and the start of a new one. | ||
* 'CR': Stands for 'Carriage Return'. It's used in classic Mac OS as a line ending, moving the cursor to the beginning of the line. | ||
* Leaving this field blank will default to using 'LF' (Line Feed), which is the standard line ending in Unix/Linux systems, denoting the end of a line. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's make it less verbose (and more maintainable).
* Line Ending: Select the type of line ending—'CRLF', 'CR' or leave blank, as necessary. | |
* 'CRLF': Stands for 'Carriage Return' + 'Line Feed'. It's used as a line ending in Windows, signifying the end of a line and the start of a new one. | |
* 'CR': Stands for 'Carriage Return'. It's used in classic Mac OS as a line ending, moving the cursor to the beginning of the line. | |
* Leaving this field blank will default to using 'LF' (Line Feed), which is the standard line ending in Unix/Linux systems, denoting the end of a line. | |
* Line Ending: Select the type of line ending, 'CRLF' or 'CR', as necessary. | |
* 'CRLF': 'Carriage Return' + 'Line Feed' (Windows) | |
* 'CR': 'Carriage Return' (classic Mac OS) | |
* Leaving this field blank defaults to using 'LF' (Line Feed), the default behavior of Odoo. |
ededd9a
to
9ae9c03
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code review. LGTM.
|
||
<!-- Demo report template --> | ||
<template id="demo_report_template"> | ||
<t t-call="web.html_container"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this text report need to be html report?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. You right. We don't need it.
This commit refactors the encoding part of the report_csv module into a new module(report_format_option) to enable the use of encoding features across multiple reporting modules by adding report_format_option as a dependency.
9ae9c03
to
23fc5df
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Functinal and code review
This PR has the |
Question @pedrobaeza |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, there's no debate, as you can't do such change.
@@ -8,9 +8,8 @@ | |||
"category": "Reporting", | |||
"version": "16.0.2.0.0", | |||
"license": "AGPL-3", | |||
"depends": ["base", "web"], | |||
"depends": ["base", "web", "report_format_option"], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is incorrect, as you can't change dependencies of a merged module.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AFAIK the purpose is to split a feature to be reusable by other report modules out of the scope of the CSV.
There should be a way to achieve this change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pedrobaeza Do you mean that this goes against the stable policy and report_csv should stay as is? In that case, we will try to do this in the 17.0 migration, and we may just propose to add report_format_option in 16.0 anyway.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, you can't do it on an existing version, or you will break existing installations. I also see that the extracted code is not worth for such "reusing", but that's only my opinion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fine by me. We need report_format_option anyway for a client to apply some format conversions on text reports. That's why we proposed to split the common feature off report_csv to avoid redundancy. We will try to do this in 17.0.
@AungKoKoLin1997 Can you please close this PR and create another one just to add report_format_option?
This PR refactors the encoding part of the report_csv module into a new module to enable the use of encoding features across multiple reporting modules by adding this new module as a dependency.
@qrtl QT4120