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
7fcaee191e
commit
5d89b44e47
@@ -4,7 +4,8 @@
|
||||
import logging
|
||||
from io import StringIO
|
||||
|
||||
from odoo import models
|
||||
from odoo import _, models
|
||||
from odoo.exceptions import UserError
|
||||
|
||||
_logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -46,7 +47,18 @@ class ReportCSVAbstract(models.AbstractModel):
|
||||
file = csv.DictWriter(file_data, **self.csv_report_options())
|
||||
self.generate_csv_report(file, data, objs)
|
||||
file_data.seek(0)
|
||||
return file_data.read(), "csv"
|
||||
encoding = self._context.get("encoding")
|
||||
if not encoding:
|
||||
return file_data.read(), "csv"
|
||||
error_handling = self._context.get("encode_error_handling")
|
||||
if error_handling:
|
||||
return file_data.read().encode(encoding, errors=error_handling), "csv"
|
||||
try:
|
||||
return file_data.read().encode(encoding), "csv"
|
||||
except Exception:
|
||||
raise UserError(
|
||||
_("Failed to encode the data with the encoding set in the report.")
|
||||
)
|
||||
|
||||
def csv_report_options(self):
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user