From 2ec367387e743f3aa406662784b65f13b95d1294 Mon Sep 17 00:00:00 2001 From: David Beal Date: Sat, 27 Jul 2019 11:56:12 +0200 Subject: [PATCH] FIX account_export_csv: use flush() instead of truncate() --- account_export_csv/wizard/account_export_csv.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/account_export_csv/wizard/account_export_csv.py b/account_export_csv/wizard/account_export_csv.py index 1433cde9..cf6bda7a 100644 --- a/account_export_csv/wizard/account_export_csv.py +++ b/account_export_csv/wizard/account_export_csv.py @@ -38,12 +38,17 @@ class AccountingWriter(object): data = self.encoder.encode(data) # write to the target stream self.stream.write(data) - # empty queue - self.queue.truncate(0) + # empty queue with seek() instead of truncate() + # see https://stackoverflow.com/a/9729516 + # also problems with seek() if next line is shorter than previous + # chars of previous line are kept in the new one + self.queue.flush() def writerows(self, rows): for row in rows: self.writerow(row) + # https://docs.python.org/3/library/io.html#io.IOBase.close + self.queue.close() class AccountCSVExport(models.TransientModel):