diff --git a/bank_statement_parse_mt940/mt940.py b/bank_statement_parse_mt940/mt940.py index a58d221..a4ef580 100644 --- a/bank_statement_parse_mt940/mt940.py +++ b/bank_statement_parse_mt940/mt940.py @@ -112,7 +112,7 @@ class MT940(object): This in fact uses the ING syntax, override in others.""" self.mt940_type = 'General' self.header_lines = 3 # Number of lines to skip - self.header_regex = '^{1:[0-9A-Z]{25,25}}' # Start of relevant data + self.header_regex = '^0000 01INGBNL2AXXXX|^{1' # Start of relevant data self.footer_regex = '^-}$|^-XXX$' # Stop processing on seeing this self.tag_regex = '^:[0-9]{2}[A-Z]*:' # Start of new tag self.current_statement = None diff --git a/bank_statement_parse_nl_ing_mt940/test_files/test-ing-old.940 b/bank_statement_parse_nl_ing_mt940/test_files/test-ing-old.940 new file mode 100644 index 0000000..19ac72c --- /dev/null +++ b/bank_statement_parse_nl_ing_mt940/test_files/test-ing-old.940 @@ -0,0 +1,61 @@ +0000 01INGBNL2AXXXX00001 +0000 01INGBNL2AXXXX00001 +940 00 +:20:P140120000000001 +:25:NL77INGB0574908765EUR +:28C:0000 +0 +:60F:C140119EUR662,23 +:61:1401200220C1,56NTRFEREF//00000000001 +005 +/TRCD/00100/ +:86:/EREF/EV12341REP1231456T1234//CNTP/NL32INGB0000012345/INGBNL2 +A/ING BANK NV INZAKE WEB///REMI/USTD//EV10001REP1000000T1000/ +:61:1401200220D1,57NTRFPREF//00000000001006 +/TRCD/00200/ +:86:/PREF/M000000003333333//REMI/USTD//TOTAAL 1 VZ/ +:61:1401200220C1,57NRTIEREF//00000000001007 +/TRCD/00190/ +:86:/RTRN/MS03//EREF/20120123456789//CNTP/NL32INGB0000012345/INGB +NL2A/J.Janssen///REMI/USTD//Factuurnr 123456 Klantnr 00123/ +:61:1401200220D1,14NDDTEREF//00000000001009 +/TRCD/010 +16 +/ +:86:/EREF/EV123R +EP123412T1234//MARF/MND +- +EV01//CSID/NL32ZZZ9999999 +91234//CNTP/NL32INGB0000012345/INGBNL2A/ING Bank N.V. inzake WeB/ +//REMI/USTD//EV123REP123412T1234/ +:61:1401200220C1,45NDDTPREF//00000000001008 +/TRCD/01000/ +:86:/PREF/M000000001111111/ +/CSID/ +NL32ZZZ999999991234 +/ +/REMI/USTD// +TOTAAL 1 POSTEN/ +:61:1401200220D12,75NRTIEREF//00000000001010 +/TRCD/01315/ +:86:/RTRN/MS03//EREF/20120501P0123478//MARF/MND +- +120123//CSID/NL32 +ZZZ999999991234//CNTP/NL32INGB0000012345/INGBNL2A/J.Janssen///REM +I/USTD//CO +NTRIBUTIE FEB 2014/ +:61:1401200220C32,00NTRF9001123412341234//00000000001011 +/TRCD/00108/ +:86:/EREF/15814016000676480//CNTP/NL32INGB0000012345/INGBNL2A/J.J +anssen///REMI/STRD/CUR/9001123412341234/ +:61:1401200220D119,00NTRF1070123412341234//00000000001012 +/ +TRCD/00108/ +:86:/EREF/15614016000384600//CNTP/NL32INGB0000012345/INGBNL2A/ING +BANK NV///REMI/STRD/CUR/1070123412341234/ +:62F:C140120EUR564,35 +:64:C140120EUR564,35 +:65:C140121EUR564,35 +:65:C140124EUR564,35 +:86:/SUM/4/4/134,46/36,58/ +-XXX diff --git a/bank_statement_parse_nl_ing_mt940/tests/test_import_bank_statement.py b/bank_statement_parse_nl_ing_mt940/tests/test_import_bank_statement.py index 914b9a8..7ecabfc 100644 --- a/bank_statement_parse_nl_ing_mt940/tests/test_import_bank_statement.py +++ b/bank_statement_parse_nl_ing_mt940/tests/test_import_bank_statement.py @@ -29,7 +29,8 @@ from openerp.modules.module import get_module_resource class TestStatementFile(TransactionCase): """Run test to import MT940 ING import.""" - def test_statement_import(self): + def _test_statement_import( + self, file_name, statement_name, start_balance, end_balance): """Test correct creation of single statement.""" import_model = self.registry('account.bank.statement.import') statement_model = self.registry('account.bank.statement') @@ -37,7 +38,7 @@ class TestStatementFile(TransactionCase): statement_path = get_module_resource( 'bank_statement_parse_nl_ing_mt940', 'test_files', - 'test-ing.940' + file_name ) statement_file = open( statement_path, 'rb').read().encode('base64') @@ -50,20 +51,37 @@ class TestStatementFile(TransactionCase): import_model.import_file(cr, uid, [bank_statement_id]) # statement name is account number + '-' + date of last 62F line: ids = statement_model.search( - cr, uid, [('name', '=', 'NL77INGB0574908765-2014-02-20')]) - self.assertTrue(ids, 'Statement not found after parse.') + cr, uid, [('name', '=', statement_name)]) + self.assertTrue( + ids, + 'Statement %s not found after parse.' % statement_name + ) statement_id = ids[0] statement_obj = statement_model.browse( cr, uid, statement_id) self.assertTrue( - abs(statement_obj.balance_start - 662.23) < 0.00001, - 'Start balance %f not equal to 662.23' % - statement_obj.balance_start + abs(statement_obj.balance_start - start_balance) < 0.00001, + 'Start balance %f not equal to expected %f' % + (statement_obj.balance_start, start_balance) ) self.assertTrue( - abs(statement_obj.balance_end_real - 564.35) < 0.00001, - 'Real end balance %f not equal to 564.35' % - statement_obj.balance_end_real + abs(statement_obj.balance_end - end_balance) < 0.00001, + 'Start balance %f not equal to expected %f' % + (statement_obj.balance_end_real, end_balance) + ) + + def test_old_statement_import(self): + """Test correct creation of single statement from old format.""" + self._test_statement_import( + 'test-ing-old.940', 'NL77INGB0574908765-2014-01-20', + 662.23, 564.35 + ) + + def test_statement_import(self): + """Test correct creation of single statement.""" + self._test_statement_import( + 'test-ing.940', 'NL77INGB0574908765-2014-02-20', + 662.23, 564.35 ) # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: