Open floriskruisselbrink opened 2 years ago
I have a solution that works for me (find transaction used for balance not only by highest date, but also by highest lineno), but this obviously woudn’t work if the csv file is sorted backwards.
diff --git a/beangulp/importers/csvbase.py b/beangulp/importers/csvbase.py
index 38213af..b02e27a 100644
--- a/beangulp/importers/csvbase.py
+++ b/beangulp/importers/csvbase.py
@@ -329,7 +329,7 @@ class Importer(beangulp.Importer, CSVReader):
# Append balances.
for currency, balances in balances.items():
- entries.append(max(balances, key=lambda x: x.date))
+ entries.append(max(balances, key=lambda x: (x.date, x.meta['lineno'])))
return entries
Thank you for the bug report. It is a known limitation I haven't found the time to address. As you write, looking at the line number does not work without taking into account also the sorting (ascending vs descending) of the entries in the CSV. Also I plan to get rid of the "lineno" metadata entry, see #101. Auto detecting the sorting breaks down where there are transactions spanning only one day. The robust solution involves adding one class parameter to configure whether the sorting is ascending or descending and looking at the last or first entry for the balance.
The new csvbase importer has the option to automatically insert a balance assertion based on a balance column in the input data.
Right now it adds a balance assertion one day after the last transaction, but if there are multiple transactions on that day it incorrectly picks the wrong transaction to take the balance from.
With this input (let’s call it
test.csv
)And this configuration (
config.py
)The result of executing
python3 config.py extract test.csv
is:The last line is incorrect and should read
(There is another issue, my bank actually adds the balance before the current transaction in the csv, but I can work around that using a custom column definition that combines the amount and the balance columns to come up with the balance after. For the bug here this is not relevant)