[IMP] report_csv: add encoding option

This commit is contained in:
Aungkokolin1997
2023-01-18 08:49:07 +06:30
committed by Aungkokolin1997
parent 7fcaee191e
commit 5d89b44e47
10 changed files with 127 additions and 18 deletions

View File

@@ -3,6 +3,7 @@
import logging
from io import StringIO
from odoo.exceptions import UserError
from odoo.tests import common
_logger = logging.getLogger(__name__)
@@ -55,3 +56,15 @@ class TestReport(common.TransactionCase):
# Typical call from render
objs = self.csv_report._get_objs_for_report(self.docs.ids, {})
self.assertEqual(objs, self.docs)
def test_report_with_encoding(self):
report = self.report
report.write({"encoding": "cp932"})
rep = report._render_csv(self.docs.ids, {})
str_io = StringIO(rep[0].decode())
dict_report = list(csv.DictReader(str_io, delimiter=";", quoting=csv.QUOTE_ALL))
self.assertEqual(self.docs.name, dict(dict_report[0])["name"])
report.write({"encoding": "xyz"})
with self.assertRaises(UserError):
rep = report._render_csv(self.docs.ids, {})