From 3afe152c02b1e9bdf3c51c0bfc171eb8c485142b Mon Sep 17 00:00:00 2001 From: Ronald Portier Date: Wed, 17 Mar 2021 13:28:41 +0100 Subject: [PATCH] [FIX] absi- _transfer_move. Correct test and duplicate class name --- .../models/account_bank_statement_import.py | 33 ++++++++- .../models/account_journal.py | 2 +- .../tests/test_statement.py | 69 ++++--------------- 3 files changed, 46 insertions(+), 58 deletions(-) diff --git a/account_bank_statement_import_transfer_move/models/account_bank_statement_import.py b/account_bank_statement_import_transfer_move/models/account_bank_statement_import.py index af145c46..e2ae6739 100644 --- a/account_bank_statement_import_transfer_move/models/account_bank_statement_import.py +++ b/account_bank_statement_import_transfer_move/models/account_bank_statement_import.py @@ -1,13 +1,44 @@ # Copyright 2020 Camptocamp SA # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -from odoo import models +from odoo import api, models class AccountBankStatementImport(models.TransientModel): _inherit = "account.bank.statement.import" + @api.model + def _parse_file(self, data_file): + """Enable testing of this functionality.""" + if self.env.context.get("account_bank_statement_import_transfer_move", False): + return ( + None, + "NL77ABNA0574908765", + [ + { + "balance_end_real": 15121.12, + "balance_start": 15568.27, + "date": "2014-01-05", + "name": "1234Test/1", + "transactions": [ + { + "account_number": "NL46ABNA0499998748", + "amount": -754.25, + "date": "2014-01-05", + "name": "Insurance policy 857239PERIOD 01.01.2014 - " + "31.12.2014", + "note": "MKB Insurance 859239PERIOD 01.01.2014 - " + "31.12.2014", + "partner_name": "INSURANCE COMPANY TESTX", + "ref": "435005714488-ABNO33052620", + }, + ], + } + ], + ) + return super()._parse_file(data_file) + def _create_bank_statements(self, stmts_vals): """ Create additional line in statement to set bank statement statement to 0 balance""" diff --git a/account_bank_statement_import_transfer_move/models/account_journal.py b/account_bank_statement_import_transfer_move/models/account_journal.py index 6bd9612a..92bcd270 100644 --- a/account_bank_statement_import_transfer_move/models/account_journal.py +++ b/account_bank_statement_import_transfer_move/models/account_journal.py @@ -4,7 +4,7 @@ from odoo import fields, models -class AccountBankStatementImport(models.Model): +class AccountJournal(models.Model): _inherit = "account.journal" diff --git a/account_bank_statement_import_transfer_move/tests/test_statement.py b/account_bank_statement_import_transfer_move/tests/test_statement.py index e81b7856..1c6ba3d8 100644 --- a/account_bank_statement_import_transfer_move/tests/test_statement.py +++ b/account_bank_statement_import_transfer_move/tests/test_statement.py @@ -1,8 +1,6 @@ # Copyright 2020 Camptocamp SA # Copyright 2020 Tecnativa - Pedro M. Baeza -# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -from unittest.mock import patch - +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). from odoo.tests.common import SavepointCase @@ -35,60 +33,19 @@ class TestGenerateBankStatement(SavepointCase): } ) - def _parse_file(self, data_file): - """Fake method for returning valuable data. Extracted from CAMT demo""" - return ( - None, - "NL77ABNA0574908765", - [ - { - "balance_end_real": 15121.12, - "balance_start": 15568.27, - "date": "2014-01-05", - "name": "1234Test/1", - "transactions": [ - { - "account_number": "NL46ABNA0499998748", - "amount": -754.25, - "date": "2014-01-05", - "name": "Insurance policy 857239PERIOD 01.01.2014 - " - "31.12.2014", - "note": "MKB Insurance 859239PERIOD 01.01.2014 - " - "31.12.2014", - "partner_name": "INSURANCE COMPANY TESTX", - "ref": "435005714488-ABNO33052620", - }, - ], - } - ], - ) - - def _get_bank_statements_available_import_formats(self): - """Fake method for returning a fake importer for not having errors.""" - return ["test"] - def _load_statement(self): - module = "odoo.addons.account_bank_statement_import" - with patch( - module - + ".account_journal.AccountJournal" - + "._get_bank_statements_available_import_formats", - self._get_bank_statements_available_import_formats, - ): - with patch( - module - + ".account_bank_statement_import" - + ".AccountBankStatementImport._parse_file", - self._parse_file, - ): - self.env["account.bank.statement.import"].create( - {"attachment_ids": [(0, 0, {"name": "test file", "datas": b""})]} - ).import_file() - bank_st_record = self.env["account.bank.statement"].search( - [("name", "=", "1234Test/1")], limit=1 - ) - statement_lines = bank_st_record.line_ids - return statement_lines + """Load fake statements, to test creation of extra line.""" + absi = self.env["account.bank.statement.import"].create( + {"attachment_ids": [(0, 0, {"name": "test file", "datas": b""})]} + ) + absi.with_context( + {"account_bank_statement_import_transfer_move": True} + ).import_file() + bank_st_record = self.env["account.bank.statement"].search( + [("name", "=", "1234Test/1")], limit=1 + ) + statement_lines = bank_st_record.line_ids + return statement_lines def test_statement_import(self): self.journal.transfer_line = True