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
@@ -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, {})
|
||||
|
||||
Reference in New Issue
Block a user