mirror of
https://github.com/OCA/reporting-engine.git
synced 2025-02-16 16:30:38 +02:00
[IMP] report_csv: add encoding option
This commit is contained in:
committed by
Aungkokolin1997
parent
afc9fadffc
commit
c75e7d1697
@@ -11,6 +11,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, docids, data):
|
||||
@@ -18,9 +26,13 @@ class ReportAction(models.Model):
|
||||
report_model = self.env.get(report_model_name)
|
||||
if report_model is None:
|
||||
raise UserError(_("%s model was not found") % report_model_name)
|
||||
return report_model.with_context(active_model=self.model).create_csv_report(
|
||||
docids, data
|
||||
)
|
||||
return report_model.with_context(
|
||||
**{
|
||||
"active_model": self.model,
|
||||
"encoding": self.encoding,
|
||||
"encode_error_handling": self.encode_error_handling,
|
||||
}
|
||||
).create_csv_report(docids, data)
|
||||
|
||||
@api.model
|
||||
def _get_report_from_name(self, report_name):
|
||||
|
||||
Reference in New Issue
Block a user