upstream/2025.2.0 #2

Merged
simon merged 100 commits from upstream/2025.2.0 into master 2025-03-07 22:45:06 +00:00
3 changed files with 42 additions and 1 deletions
Showing only changes of commit 5d4b218aa6 - Show all commits
+14 -1
View File
@@ -30,6 +30,19 @@ class HintMismatchError(Exception):
pass
def check_row_length(data, hint, row):
valid_lengths = [hint['cols']]
header = data[0]
for i in range(len(header) - 1, 0, -1):
if header[i]:
break
else:
valid_lengths.append(hint['cols'] - (len(header) - i))
return None not in row and len(row) in valid_lengths
def parse(data, hint):
result = []
if 'cols' not in hint:
@@ -39,7 +52,7 @@ def parse(data, hint):
good_hint = False
for row in data:
resrow = {}
if None in row or len(row) != hint['cols']:
if not check_row_length(data, hint, row):
# Wrong column count
continue
if hint.get('payer') is not None:
@@ -0,0 +1,3 @@
Transaction Date,Transaction Type,Sort Code,Account Number,Transaction Description,Debit Amount,Credit Amount,Balance,
27/01/2025,FPI,'99-99-99,11111111,SMITH J ABCDE 111111111111111111 111111 10 25JAN25 13:34,,214,500
25/01/2025,FPI,'99-99-99,11111111,JONES A FGHIJ 111111111111111112 111112 10 25JAN25 10:34,,213,286
1 Transaction Date,Transaction Type,Sort Code,Account Number,Transaction Description,Debit Amount,Credit Amount,Balance,
2 27/01/2025,FPI,'99-99-99,11111111,SMITH J ABCDE 111111111111111111 111111 10 25JAN25 13:34,,214,500
3 25/01/2025,FPI,'99-99-99,11111111,JONES A FGHIJ 111111111111111112 111112 10 25JAN25 10:34,,213,286
@@ -166,3 +166,28 @@ class CsvImportTest(TestCase):
]
filename = "csvimport_data_de_postbank.csv"
self._test_from_sample_file(filename, expected, hint, expected_parsed)
def test_sample_file_lloyds(self):
expected = [
# Lloyds Bank includes a trailing comma at the end of the header row, making the header one column longer than the data rows.
['Transaction Date', 'Transaction Type', 'Sort Code', 'Account Number', 'Transaction Description', 'Debit Amount',
'Credit Amount', 'Balance', ''],
["27/01/2025", "FPI", "'99-99-99", "11111111", "SMITH J ABCDE 111111111111111111 111111 10 25JAN25 13:34",
"", "214", "500"],
["25/01/2025", "FPI", "'99-99-99", "11111111", "JONES A FGHIJ 111111111111111112 111112 10 25JAN25 10:34",
"", "213", "286"],
]
hint = {
'reference': [4],
'date': 0,
'amount': 6,
'cols': 9,
}
expected_parsed = [
{'reference': 'SMITH J ABCDE 111111111111111111 111111 10 25JAN25 13:34', 'amount': '214',
'date': '27/01/2025'},
{'reference': 'JONES A FGHIJ 111111111111111112 111112 10 25JAN25 10:34', 'amount': '213',
'date': '25/01/2025'},
]
filename = "csvimport_data_gb_lloyds.csv"
self._test_from_sample_file(filename, expected, hint, expected_parsed)