From 4a04127c7c67be3c2a764913a17325386fda7602 Mon Sep 17 00:00:00 2001 From: David Beal Date: Thu, 25 Jun 2020 16:57:01 +0200 Subject: [PATCH 1/2] IMP acc_export_csv: test the number of lines of the file --- account_export_csv/tests/test_account_export_csv.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/account_export_csv/tests/test_account_export_csv.py b/account_export_csv/tests/test_account_export_csv.py index 92ed402b..e7e90220 100644 --- a/account_export_csv/tests/test_account_export_csv.py +++ b/account_export_csv/tests/test_account_export_csv.py @@ -3,6 +3,7 @@ from datetime import date from dateutil import relativedelta +import base64 from odoo.tests.common import TransactionCase from odoo import fields @@ -38,3 +39,14 @@ class TestAccountExportCsv(TransactionCase): 'date_end': self.report_date_end }) report_wizard.action_manual_export_journal_entries() + + def test_file_content(self): + report_wizard = self.report_wizard.create({ + "date_start": "2000-01-01", + "date_end": "2200-01-01", + }) + report_wizard.action_manual_export_journal_entries() + res = base64.decodestring(report_wizard.data) + line_number = self.env["account.move.line"].search_count([]) + # check the number of lines in file: include header + EOF line + self.assertEqual(len(res.decode().split("\r\n")), line_number + 2) From ee30d1d729e150386d3200dc9536a1eacec1aab8 Mon Sep 17 00:00:00 2001 From: David Beal Date: Thu, 25 Jun 2020 18:36:05 +0200 Subject: [PATCH 2/2] FIX acc_export_csv: use truncate/seek instead of StringIO() --- account_export_csv/wizard/account_export_csv.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/account_export_csv/wizard/account_export_csv.py b/account_export_csv/wizard/account_export_csv.py index bab4118e..eaef93f5 100644 --- a/account_export_csv/wizard/account_export_csv.py +++ b/account_export_csv/wizard/account_export_csv.py @@ -38,9 +38,11 @@ class AccountingWriter(object): data = self.encoder.encode(data) # write to the target stream self.stream.write(data) - # seek() or truncate() have side effect then we reinitialize StringIO + # seek() or truncate() have side effect if not used combinated + self.queue.truncate(0) + self.queue.seek(0) # https://stackoverflow.com/questions/4330812/how-do-i-clear-a-stringio-object - self.queue = StringIO() + # It fails when you use `self.queue = StringIO()` only add one line def writerows(self, rows): for row in rows: