Skip to content

Commit

Permalink
FIX globalisation for line of type '3'
Browse files Browse the repository at this point in the history
  • Loading branch information
lmignon committed Jan 29, 2015
1 parent 5941b16 commit e535591
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 2 deletions.
4 changes: 2 additions & 2 deletions coda/parser.py
Expand Up @@ -165,7 +165,7 @@ def _parseMovementRecord(self, line, statement):
self.date_format, time.strptime(rmspaces(line[115:121]), '%d%m%y'))
record.type = MovementRecordType.NORMAL

if record.transaction_type in [1, 2]:
if record.transaction_type in [1, 2, 3]:
# here the transaction type is a globalisation
# 1 is for globalisation from the customer
# 2 is for globalisation from the bank
Expand All @@ -180,7 +180,7 @@ def _parseMovementRecord(self, line, statement):
# record.type to Normal
prev_mvmt = statement.movements and statement.movements[-1] or None
if prev_mvmt and \
record.transaction_type < 3 and \
record.transaction_type < 4 and \
prev_mvmt.type == MovementRecordType.GLOBALISATION:
prev_mvmt.type = MovementRecordType.NORMAL
record.globalisation_code = int(line[124])
Expand Down
25 changes: 25 additions & 0 deletions coda/tests/Coda_v2_3_globalisation.txt
@@ -0,0 +1,25 @@
0000002011520005D SA XXXX MARKET GEBABEBB 00847615989 00000 2
12159BE12341676096039 EUR1000000000455170091214SA XXXX MARKET CPTE A VUE / ZICHTREK 159
21000100000001400000427 0000000113135000101214001500000REDEVANCE JAN-NOV CONTRAT DE GESTION11111111901 0
2200010000 XXXXXXXXXXXX597055ISABEL GEBABEBB 1 0
2300010000BE12201702625236 XXXXXXXX-IN MARKET ZAVENTEM B 0 1
31000100010001400000427 001500001001XXXXXXXX MARKET ZAVENTEM B 1 0
3200010001STXXXXXXXXXXXXXX 163 1930 ZAVENTEM 0 0
21000200000001400000428 0000000113135000101214001500000REDEVANCE JAN-NOV CONTRAT DE GESTION11111115901 0
2200020000 XXXXXXXXXXX5306844ISABEL GEBABEBB 1 0
2300020000BE12301702624428 XXXXXXXXXXX WAVRE SPRL 0 1
31000200010001400000428 001500001001XXXXXXXX WAVRE SPRL 1 0
3200020001CH E D.XXXXXXX 500 A 1300 WAVRE 0 0
21000300000001400000429440073880000000050000000101214301500000 10121415911 0
2200030000 FT14344YP389 1 0
2300030000NL133KMG0261239759 XXXX MARKET SA 0 1
3100030001000140000042944007388301500001001XXXX MARKET SA 1 0
320003000113 RUE DEXXXXXX, 1000 BRUX XXXXX, BELGIUM 0 0
21000300020001400000429440073880000000050000000101214801501001105000000050000000000000050000000000100000000EUR 10121415911 0
2200030002 NL000000050000000 FT14344YP389 1 0
2300030002NL123KMG0261239759 XXXX MARKET SA 0 1
3100030003000140000042944007388801501001006 EUR0000000500000000100 0 0
21000400000001400000430 10000000005443001012140040300011246703330000008003 2335 17098487 1010121415901 0
22000400001214 0 0
8159BE12301676096039 EUR0000000275270530101214 0
9 000023000000000544300000000276270000 1
21 changes: 21 additions & 0 deletions coda/tests/Coda_v2_3_globalisation_2.txt
@@ -0,0 +1,21 @@
0000002011520005D SA XXXX MARKET GEBABEBB 00847615989 00000 2
12159BE12341676096039 EUR1000000000455170091214SA XXXX MARKET CPTE A VUE / ZICHTREK 159
21000100000001400000427 0000000113135000101214001500000REDEVANCE JAN-NOV CONTRAT DE GESTION11111111901 0
2200010000 XXXXXXXXXXXX597055ISABEL GEBABEBB 1 0
2300010000BE12201702625236 XXXXXXXX-IN MARKET ZAVENTEM B 0 1
31000100010001400000427 001500001001XXXXXXXX MARKET ZAVENTEM B 1 0
3200010001STXXXXXXXXXXXXXX 163 1930 ZAVENTEM 0 0
21000200000001400000428 0000000113135000101214001500000REDEVANCE JAN-NOV CONTRAT DE GESTION11111115901 0
2200020000 XXXXXXXXXXX5306844ISABEL GEBABEBB 1 0
2300020000BE12301702624428 XXXXXXXXXXX WAVRE SPRL 0 1
31000200010001400000428 001500001001XXXXXXXX WAVRE SPRL 1 0
3200020001CH E D.XXXXXXX 500 A 1300 WAVRE 0 0
21000300000001400000429440073880000000050000000101214301500000 10121415911 0
2200030000 FT14344YP389 1 0
2300030000NL133KMG0261239759 XXXX MARKET SA 0 1
3100030001000140000042944007388301500001001XXXX MARKET SA 1 0
320003000113 RUE DEXXXXXX, 1000 BRUX XXXXX, BELGIUM 0 0
21000400000001400000430 10000000005443001012140040300011246703330000008003 2335 17098487 1010121415901 0
22000400001214 0 0
8159BE12301676096039 EUR0000000275270530101214 0
9 000023000000000544300000000276270000 1
25 changes: 25 additions & 0 deletions coda/tests/test_parser.py
Expand Up @@ -141,6 +141,31 @@ def test_wrong_globalisation_2(self):
for mv in statement.movements:
eq_(mv.type, MovementRecordType.NORMAL)

def test_globalisation(self):
"""Test that a globalisation line with details is considerd as
Globalisation and its details as Normal
"""
parser = Parser()
with open(os.path.join(BASEPATH, "Coda_v2_3_globalisation.txt")) as f:
content = f.read()
statements = parser.parse(content)
assert len(statements) == 1
statement = statements[0]
eq_(len(statement.movements), 5)
for idx, mv in enumerate(statement.movements):
if idx == 2:
eq_(mv.type, MovementRecordType.GLOBALISATION)
else:
eq_(mv.type, MovementRecordType.NORMAL)
with open(os.path.join(BASEPATH, "Coda_v2_3_globalisation_2.txt")) as f:
content = f.read()
statements = parser.parse(content)
assert len(statements) == 1
statement = statements[0]
eq_(len(statement.movements), 4)
for mv in statement.movements:
eq_(mv.type, MovementRecordType.NORMAL)

def test_unsupported_version(self):
parser = Parser()
with open(os.path.join(BASEPATH, "Coda_faulty_version.txt")) as f:
Expand Down

0 comments on commit e535591

Please sign in to comment.