[IMP] report_csv: add encoding option

This commit is contained in:
Aungkokolin1997
2023-01-18 08:49:07 +06:30
committed by Aungkokolin1997
parent f5c04ca190
commit c6a50e47ff
10 changed files with 125 additions and 15 deletions

View File

@@ -10,6 +10,14 @@ class ReportAction(models.Model):
report_type = fields.Selection(
selection_add=[("csv", "csv")], ondelete={"csv": "set default"}
)
encoding = fields.Char(
help="Encoding to be applied to the generated CSV file. e.g. cp932"
)
encode_error_handling = fields.Selection(
selection=[("ignore", "Ignore"), ("replace", "Replace")],
help="If nothing is selected, CSV export will fail with an error message when "
"there is a character that fail to be encoded.",
)
@api.model
def _render_csv(self, report_ref, docids, data):
@@ -17,7 +25,11 @@ class ReportAction(models.Model):
report_model_name = "report.%s" % report_sudo.report_name
report_model = self.env[report_model_name]
return report_model.with_context(
active_model=report_sudo.model
**{
"active_model": report_sudo.model,
"encoding": self.encoding,
"encode_error_handling": self.encode_error_handling,
}
).create_csv_report(docids, data)
@api.model