From c2cee48ad1217409510716376ff16e1a38ab52b1 Mon Sep 17 00:00:00 2001 From: sbejaoui Date: Mon, 20 May 2019 11:53:49 +0200 Subject: [PATCH] [IMP] - manage multi-bank-account statement import refs: #209 --- .../models/account_bank_statement_import.py | 68 +- .../models/parser.py | 41 +- .../test_files/test-camt053-more-than-one-xml | 581 ++++++++++++++++++ .../tests/test_import_bank_statement.py | 30 + 4 files changed, 717 insertions(+), 3 deletions(-) create mode 100644 account_bank_statement_import_camt_oca/test_files/test-camt053-more-than-one-xml diff --git a/account_bank_statement_import_camt_oca/models/account_bank_statement_import.py b/account_bank_statement_import_camt_oca/models/account_bank_statement_import.py index 75f68d3..ff41cf1 100644 --- a/account_bank_statement_import_camt_oca/models/account_bank_statement_import.py +++ b/account_bank_statement_import_camt_oca/models/account_bank_statement_import.py @@ -4,6 +4,7 @@ import logging from io import BytesIO import zipfile from odoo import api, models +from odoo.addons.base.models.res_bank import sanitize_account_number _logger = logging.getLogger(__name__) @@ -11,25 +12,88 @@ _logger = logging.getLogger(__name__) class AccountBankStatementImport(models.TransientModel): _inherit = 'account.bank.statement.import' + @api.model + def _xml_split_file(self, data_file): + """BNP France is known to merge xml files""" + if not data_file.startswith(b' + + + + TESTBANK/NL/1420561226673 + 2014-01-06T16:20:26.673Z + + + 1234Test/1 + 2 + 2014-01-06T16:20:26.673Z + + 2014-01-05T00:00:00.000Z + 2014-01-05T23:59:59.999Z + + + + NL77ABNA0574908765 + + Example company + + + ABNANL2A + + + + + + + OPBD + + + 15568.27 + CRDT +
+
2014-01-05
+ +
+ + + + CLBD + + + 15121.12 + CRDT +
+
2014-01-05
+ +
+ + 754.25 + DBIT + BOOK + +
2014-01-05
+
+ +
2014-01-05
+
+ + + PMNT + + RDDT + ESDD + + + + EI + + + + + + INNDNL2U20141231000142300002844 + 435005714488-ABNO33052620 + 1880000341866 + + + + 754.25 + + + + + INSURANCE COMPANY TESTX + + TEST STREET 20 + 1234 AB TESTCITY + NL + + + + + NL46ABNA0499998748 + + + + + + + ABNANL2A + + + + + Insurance policy 857239PERIOD 01.01.2014 - 31.12.2014 + + MKB Insurance 859239PERIOD 01.01.2014 - 31.12.2014 + + +
+ + 664.05 + DBIT + true + BOOK + +
2014-01-05
+
+ +
2014-01-05
+
+ + + PMNT + + IDDT + UPDD + + + + EIST + + + + + 2014/125 + 2018/125-20141229-NORM + 2 + 664.05 + DBIT + + + + TESTBANK/NL/20141229/01206408 + TESTBANK/NL/20141229/01206408 + NL22ZZZ524885430000-C0125.1 + + + + 564.05 + + + + + Test Customer + + NL + + + + + NL46ABNA0499998748 + + + + + + + ABNANL2A + + + + + Direct Debit S14 0410 + + + + AC06 + + + Direct debit S14 0410 AC07 Rek.nummer blokkade TESTBANK/NL/20141229/01206408 + + + + TESTBANK/NL/20141229/01206407 + TESTBANK/NL/20141229/01206407 + NL22ZZZ524885430000-C0125.2 + + + + 100.00 + + + + + Test Customer + + NL + + + + + NL46ABNA0499998748 + + + + + + + ABNANL2A + + + + + Direct Debit S14 0410 + + + + AC06 + + + Direct debit S14 0410 AC07 Rek.nummer blokkade TESTBANK/NL/20141229/01206408 + + +
+ + 1405.31 + CRDT + BOOK + +
2014-01-05
+
+ +
2014-01-05
+
+ + + PMNT + + RCDT + ESCT + + + + ET + + + + + + INNDNL2U20140105000217200000708 + 115 + + + + 1405.31 + + + + + 3rd party Media + + SOMESTREET 570-A + 1276 ML HOUSCITY + NL + + + + + NL69ABNA0522123643 + + + + + + + ABNANL2A + + + + #RD PARTY MEDIA CUSNO 90782 4210773 + + +
+
+
+
+ + + + + + TESTBANK/NL/1420561226673 + 2014-01-06T16:20:26.673Z + + + 1234Test/1 + 2 + 2014-01-06T16:20:26.673Z + + 2014-01-05T00:00:00.000Z + 2014-01-05T23:59:59.999Z + + + + NL77ABNA0574908765 + + Example company + + + ABNANL2A + + + + + + + OPBD + + + 15568.27 + CRDT +
+
2014-01-05
+ +
+ + + + CLBD + + + 15121.12 + CRDT +
+
2014-01-05
+ +
+ + 754.25 + DBIT + BOOK + +
2014-01-05
+
+ +
2014-01-05
+
+ + + PMNT + + RDDT + ESDD + + + + EI + + + + + + INNDNL2U20141231000142300002844 + 435005714488-ABNO33052620 + 1880000341866 + + + + 754.25 + + + + + INSURANCE COMPANY TESTX + + TEST STREET 20 + 1234 AB TESTCITY + NL + + + + + NL46ABNA0499998748 + + + + + + + ABNANL2A + + + + + Insurance policy 857239PERIOD 01.01.2014 - 31.12.2014 + + MKB Insurance 859239PERIOD 01.01.2014 - 31.12.2014 + + +
+ + 664.05 + DBIT + true + BOOK + +
2014-01-05
+
+ +
2014-01-05
+
+ + + PMNT + + IDDT + UPDD + + + + EIST + + + + + 2014/125 + 2018/125-20141229-NORM + 2 + 664.05 + DBIT + + + + TESTBANK/NL/20141229/01206408 + TESTBANK/NL/20141229/01206408 + NL22ZZZ524885430000-C0125.1 + + + + 564.05 + + + + + Test Customer + + NL + + + + + NL46ABNA0499998748 + + + + + + + ABNANL2A + + + + + Direct Debit S14 0410 + + + + AC06 + + + Direct debit S14 0410 AC07 Rek.nummer blokkade TESTBANK/NL/20141229/01206408 + + + + TESTBANK/NL/20141229/01206407 + TESTBANK/NL/20141229/01206407 + NL22ZZZ524885430000-C0125.2 + + + + 100.00 + + + + + Test Customer + + NL + + + + + NL46ABNA0499998748 + + + + + + + ABNANL2A + + + + + Direct Debit S14 0410 + + + + AC06 + + + Direct debit S14 0410 AC07 Rek.nummer blokkade TESTBANK/NL/20141229/01206408 + + +
+ + 1405.31 + CRDT + BOOK + +
2014-01-05
+
+ +
2014-01-05
+
+ + + PMNT + + RCDT + ESCT + + + + ET + + + + + + INNDNL2U20140105000217200000708 + 115 + + + + 1405.31 + + + + + 3rd party Media + + SOMESTREET 570-A + 1276 ML HOUSCITY + NL + + + + + NL69ABNA0522123643 + + + + + + + ABNANL2A + + + + #RD PARTY MEDIA CUSNO 90782 4210773 + + +
+
+
+
diff --git a/account_bank_statement_import_camt_oca/tests/test_import_bank_statement.py b/account_bank_statement_import_camt_oca/tests/test_import_bank_statement.py index 7340845..a4a3e94 100644 --- a/account_bank_statement_import_camt_oca/tests/test_import_bank_statement.py +++ b/account_bank_statement_import_camt_oca/tests/test_import_bank_statement.py @@ -113,6 +113,35 @@ class TestImport(TransactionCase): 'bank_account_id': bank.id, }) + def test_statement_import_more_than_one_xml_tag(self): + """Test correct statements creation for more than one xml document + in import file.""" + testfile = get_module_resource( + 'account_bank_statement_import_camt_oca', + 'test_files', + 'test-camt053-more-than-one-xml', + ) + with open(testfile, 'rb') as datafile: + action = self.env['account.bank.statement.import'].create({ + 'data_file': base64.b64encode(datafile.read()) + }).import_file() + + statement_lines = self.env['account.bank.statement'].browse( + action['context']['statement_ids'] + ).mapped('line_ids') + + self.assertEqual(len(statement_lines), 8) + + self.assertTrue(any( + all( + line[key] == self.transactions[0][key] + for key in ['amount', 'date', 'ref'] + ) and + line.bank_account_id.acc_number == + self.transactions[0]['account_number'] + for line in statement_lines + )) + def test_statement_import(self): """Test correct creation of single statement.""" testfile = get_module_resource( @@ -128,6 +157,7 @@ class TestImport(TransactionCase): statement_lines = self.env['account.bank.statement'].browse( action['context']['statement_ids'] ).line_ids + self.assertEqual(len(statement_lines), 4) self.assertTrue(any( all( line[key] == self.transactions[0][key]