details:   https://code.tryton.org/coda/commit/b106b90173dc
branch:    default
user:      Cédric Krier <[email protected]>
date:      Thu Aug 27 23:46:01 2026 +0200
description:
        Support empty CODA file

        Closes #15
diffstat:

 CHANGELOG           |   1 +
 coda/CODA-empty.txt |   3 +++
 coda/__init__.py    |   9 +++++++++
 coda/test.py        |  31 +++++++++++++++++++++++++++++++
 4 files changed, 44 insertions(+), 0 deletions(-)

diffs (73 lines):

diff -r 00244d8a2cad -r b106b90173dc CHANGELOG
--- a/CHANGELOG Sat Mar 28 00:05:38 2026 +0100
+++ b/CHANGELOG Thu Aug 27 23:46:01 2026 +0200
@@ -1,3 +1,4 @@
+* Support empty CODA file
 
 Version 0.4.1 - 2026-03-27
 --------------------------
diff -r 00244d8a2cad -r b106b90173dc coda/CODA-empty.txt
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/coda/CODA-empty.txt       Thu Aug 27 23:46:01 2026 +0200
@@ -0,0 +1,3 @@
+0000009082600000        00000000  COMPANY NAME NV           
XXXXXXXXXXX00000000000 00000                                       2
+12202BE00000000000000                  EUR0000000000000000070826COMPANY NAME 
NV           ACCOUNT DESCRIPTION                221
+9               000001000000000000000000000000000000                           
                                                1
\ No newline at end of file
diff -r 00244d8a2cad -r b106b90173dc coda/__init__.py
--- a/coda/__init__.py  Sat Mar 28 00:05:38 2026 +0100
+++ b/coda/__init__.py  Thu Aug 27 23:46:01 2026 +0200
@@ -85,6 +85,15 @@
             elif type_ == '9':
                 self._parse_statement(record, statement, TRAILER)
 
+                if statement.new_sequence is None:
+                    statement.new_sequence = statement.old_sequence
+
+                if statement.new_balance is None:
+                    statement.new_balance = statement.old_balance
+
+                if statement.new_balance_date is None:
+                    statement.new_balance_date = statement.old_balance_date
+
                 assert (statement.new_balance - statement.old_balance
                     == statement.total_credit - statement.total_debit)
                 assert statement.total_credit == total_credit
diff -r 00244d8a2cad -r b106b90173dc coda/test.py
--- a/coda/test.py      Sat Mar 28 00:05:38 2026 +0100
+++ b/coda/test.py      Thu Aug 27 23:46:01 2026 +0200
@@ -320,3 +320,34 @@
         amount = sum(m.amount for m in move.moves)
 
         self.assertEqual(amount, move.amount)
+
+
+class TestCODAEmpty(unittest.TestCase):
+
+    def setUp(self):
+        self.coda = CODA(os.path.join(here, 'CODA-empty.txt'))
+
+    @property
+    def statement(self):
+        return self.coda.statements[0]
+
+    def test_number_statements(self):
+        self.assertEqual(len(self.coda.statements), 1)
+
+    def test_statement_old_sequence(self):
+        self.assertEqual(self.statement.old_sequence, '202')
+
+    def test_statement_new_sequence(self):
+        self.assertEqual(self.statement.new_sequence, '202')
+
+    def test_statement_old_balance(self):
+        self.assertEqual(self.statement.old_balance, 0)
+
+    def test_statement_old_balance_date(self):
+        self.assertEqual(self.statement.old_balance_date, date(2026, 8, 7))
+
+    def test_statement_new_balance(self):
+        self.assertEqual(self.statement.new_balance, 0)
+
+    def test_statement_new_balance_date(self):
+        self.assertEqual(self.statement.new_balance_date, date(2026, 8, 7))

Reply via email to