diff --git a/account_statement_import/wizard/account_statement_import.py b/account_statement_import/wizard/account_statement_import.py index 09e7ff7e..a815a09d 100644 --- a/account_statement_import/wizard/account_statement_import.py +++ b/account_statement_import/wizard/account_statement_import.py @@ -332,6 +332,9 @@ class AccountStatementImport(models.TransientModel): st_lines_to_create.append(lvals) if len(st_lines_to_create) > 0: + if not st_lines_to_create[0].get("sequence"): + for seq, vals in enumerate(st_lines_to_create, start=1): + vals["sequence"] = seq # Remove values that won't be used to create records st_vals.pop("transactions", None) # Create the statement with lines diff --git a/account_statement_import_camt/models/parser.py b/account_statement_import_camt/models/parser.py index 2c66b7a2..0ee3e739 100644 --- a/account_statement_import_camt/models/parser.py +++ b/account_statement_import_camt/models/parser.py @@ -65,7 +65,7 @@ class CamtParser(models.AbstractModel): "./ns:Refs/ns:InstrId", ], transaction, - "name", + "payment_ref", join_str="\n", ) # name @@ -130,12 +130,14 @@ class CamtParser(models.AbstractModel): def parse_entry(self, ns, node): """Parse an Ntry node and yield transactions""" - transaction = {"name": "/", "amount": 0} # fallback defaults + transaction = {"payment_ref": "/", "amount": 0} # fallback defaults self.add_value_from_node(ns, node, "./ns:BookgDt/ns:Dt", transaction, "date") amount = self.parse_amount(ns, node) if amount != 0.0: transaction["amount"] = amount - self.add_value_from_node(ns, node, "./ns:AddtlNtryInf", transaction, "name") + self.add_value_from_node( + ns, node, "./ns:AddtlNtryInf", transaction, "narration" + ) self.add_value_from_node( ns, node, @@ -217,6 +219,8 @@ class CamtParser(models.AbstractModel): result["date"] = sorted( transactions, key=lambda x: x["date"], reverse=True )[0]["date"] + for seq, vals in enumerate(transactions, start=1): + vals["sequence"] = seq return result def check_version(self, ns, root): diff --git a/account_statement_import_camt/test_files/golden-camt053-txdtls.pydata b/account_statement_import_camt/test_files/golden-camt053-txdtls.pydata index 6b7fc096..37b60b30 100644 --- a/account_statement_import_camt/test_files/golden-camt053-txdtls.pydata +++ b/account_statement_import_camt/test_files/golden-camt053-txdtls.pydata @@ -7,12 +7,16 @@ 'transactions': [{'account_number': 'CH2222000000123456789', 'amount': 2187.0, 'date': '2017-03-22', - 'name': 'CRÉDIT GROUPÉ BVR TRAITEMENT DU 22.03.2017 NUMÉRO CLIENT 01-70884-3 PAQUET ID: 123456CHCAFEBABE', + 'narration': 'CRÉDIT GROUPÉ BVR TRAITEMENT DU 22.03.2017 NUMÉRO CLIENT 01-70884-3 PAQUET ID: 123456CHCAFEBABE', 'partner_name': 'Banque Cantonale Vaudoise', - 'ref': '302388292000011111111111111'}, + 'payment_ref': '/', + 'ref': '302388292000011111111111111', + 'sequence': 1}, {'account_number': 'CH3333000000123456789', 'amount': 1296.0, 'date': '2017-03-22', - 'name': 'CRÉDIT GROUPÉ BVR TRAITEMENT DU 22.03.2017 NUMÉRO CLIENT 01-70884-3 PAQUET ID: 123456CHCAFEBABE', + 'narration': 'CRÉDIT GROUPÉ BVR TRAITEMENT DU 22.03.2017 NUMÉRO CLIENT 01-70884-3 PAQUET ID: 123456CHCAFEBABE', 'partner_name': 'Banque Cantonale Vaudoise', - 'ref': '302388292000022222222222222'}]}]) + 'payment_ref': '/', + 'ref': '302388292000022222222222222', + 'sequence': 2}]}]) diff --git a/account_statement_import_camt/test_files/golden-camt053.pydata b/account_statement_import_camt/test_files/golden-camt053.pydata index c51d6bb7..528f4f61 100644 --- a/account_statement_import_camt/test_files/golden-camt053.pydata +++ b/account_statement_import_camt/test_files/golden-camt053.pydata @@ -7,28 +7,28 @@ 'transactions': [{'account_number': 'NL46ABNA0499998748', 'amount': -754.25, 'date': '2014-01-05', - 'name': 'Insurance policy 857239PERIOD 01.01.2014 - 31.12.2014', 'partner_name': 'INSURANCE COMPANY TESTX', 'payment_ref': 'MKB Insurance 859239PERIOD 01.01.2014 - 31.12.2014', - 'ref': '435005714488-ABNO33052620'}, + 'ref': '435005714488-ABNO33052620', + 'sequence': 1}, {'account_number': 'NL46ABNA0499998748', 'amount': -564.05, 'date': '2014-01-05', - 'name': 'Direct Debit S14 0410', 'partner_name': 'Test Customer', 'payment_ref': 'Direct debit S14 0410 AC07 Rek.nummer blokkade TESTBANK/NL/20141229/01206408', - 'ref': 'TESTBANK/NL/20141229/01206408'}, + 'ref': 'TESTBANK/NL/20141229/01206408', + 'sequence': 2}, {'account_number': 'NL46ABNA0499998748', 'amount': -100.0, 'date': '2014-01-05', - 'name': 'Direct Debit S14 0410', 'partner_name': 'Test Customer', 'payment_ref': 'Direct debit S14 0410 AC07 Rek.nummer blokkade TESTBANK/NL/20141229/01206408', - 'ref': 'TESTBANK/NL/20141229/01206407'}, + 'ref': 'TESTBANK/NL/20141229/01206407', + 'sequence': 3}, {'account_number': 'NL69ABNA0522123643', 'amount': 1405.31, 'date': '2014-01-05', - 'name': 'INNDNL2U20140105000217200000708', 'partner_name': '3rd party Media', 'payment_ref': '#RD PARTY MEDIA CUSNO 90782 4210773', - 'ref': '115'}]}]) + 'ref': '115', + 'sequence': 4}]}]) diff --git a/account_statement_import_camt/tests/test_import_bank_statement.py b/account_statement_import_camt/tests/test_import_bank_statement.py index 0ccc1094..5e7b3a13 100644 --- a/account_statement_import_camt/tests/test_import_bank_statement.py +++ b/account_statement_import_camt/tests/test_import_bank_statement.py @@ -8,8 +8,6 @@ import pprint import tempfile from datetime import date -import mock - from odoo.modules.module import get_module_resource from odoo.tests.common import TransactionCase @@ -113,19 +111,13 @@ class TestImport(TransactionCase): } ) - @mock.patch( - "odoo.addons.account.models.sequence_mixin." - "SequenceMixin._constrains_date_sequence", - side_effect=False, - ) - def test_statement_import(self, constraint): + def test_statement_import(self): """Test correct creation of single statement.""" testfile = get_module_resource( "account_statement_import_camt", "test_files", "test-camt053" ) with open(testfile, "rb") as datafile: camt_file = base64.b64encode(datafile.read()) - self.env["account.statement.import"].create( { "statement_filename": "test import", @@ -150,12 +142,7 @@ class TestImport(TransactionCase): ) ) - @mock.patch( - "odoo.addons.account.models.sequence_mixin." - "SequenceMixin._constrains_date_sequence", - side_effect=False, - ) - def test_zip_import(self, constraint): + def test_zip_import(self): """Test import of multiple statements from zip file.""" testfile = get_module_resource( "account_statement_import_camt", "test_files", "test-camt053.zip"