diff --git a/account_statement_import_file/README.rst b/account_statement_import_file/README.rst index 67f17528..6b3dd7d7 100644 --- a/account_statement_import_file/README.rst +++ b/account_statement_import_file/README.rst @@ -100,6 +100,7 @@ Contributors - Odoo S.A. - Alexis de Lattre - Tecnativa - Pedro M. Baeza +- Sygel - Manuel Regidor Maintainers ----------- diff --git a/account_statement_import_file/__manifest__.py b/account_statement_import_file/__manifest__.py index 6f510dfe..c0e5bc2a 100644 --- a/account_statement_import_file/__manifest__.py +++ b/account_statement_import_file/__manifest__.py @@ -6,7 +6,7 @@ { "name": "Import Statement Files", "category": "Accounting", - "version": "16.0.1.0.2", + "version": "17.0.1.0.0", "license": "LGPL-3", "depends": ["account_statement_import_base"], "author": "Odoo SA, Akretion, Odoo Community Association (OCA)", diff --git a/account_statement_import_file/demo/partner_bank.xml b/account_statement_import_file/demo/partner_bank.xml index fcf2fbc4..f22a791a 100644 --- a/account_statement_import_file/demo/partner_bank.xml +++ b/account_statement_import_file/demo/partner_bank.xml @@ -4,7 +4,7 @@ Copyright 2022 Moduon Team Licence LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl-3.0). --> - + BE02631118262640 diff --git a/account_statement_import_file/migrations/16.0.1.0.1/post-migration.py b/account_statement_import_file/migrations/16.0.1.0.1/post-migration.py deleted file mode 100644 index dd18c381..00000000 --- a/account_statement_import_file/migrations/16.0.1.0.1/post-migration.py +++ /dev/null @@ -1,16 +0,0 @@ -# Copyright 2023 Landoo Sistemas de Informacion SL -# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). - -from openupgradelib import openupgrade - - -@openupgrade.migrate() -def migrate(env, version): - openupgrade.logged_query( - env.cr, - """ - UPDATE account_journal - SET bank_statements_source = 'file_import_oca' - WHERE bank_statements_source = 'file_import' - """, - ) diff --git a/account_statement_import_file/readme/CONTRIBUTORS.md b/account_statement_import_file/readme/CONTRIBUTORS.md index 653f9dc7..44935e2a 100644 --- a/account_statement_import_file/readme/CONTRIBUTORS.md +++ b/account_statement_import_file/readme/CONTRIBUTORS.md @@ -1,3 +1,4 @@ - Odoo S.A. - Alexis de Lattre \<\> - Tecnativa - Pedro M. Baeza +- Sygel - Manuel Regidor diff --git a/account_statement_import_file/static/description/index.html b/account_statement_import_file/static/description/index.html index 1e7a31b2..57f7c67b 100644 --- a/account_statement_import_file/static/description/index.html +++ b/account_statement_import_file/static/description/index.html @@ -442,6 +442,7 @@ If you spotted it first, help us to smash it by providing a detailed and welcome
  • Odoo S.A.
  • Alexis de Lattre <alexis.delattre@akretion.com>
  • Tecnativa - Pedro M. Baeza
  • +
  • Sygel - Manuel Regidor
  • diff --git a/account_statement_import_file/tests/__init__.py b/account_statement_import_file/tests/__init__.py new file mode 100644 index 00000000..cc662eb7 --- /dev/null +++ b/account_statement_import_file/tests/__init__.py @@ -0,0 +1,4 @@ +# Copyright 2024 Sygel - Manuel Regidor +# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html + +from . import test_account_statement_import_file diff --git a/account_statement_import_file/tests/test_account_statement_import_file.py b/account_statement_import_file/tests/test_account_statement_import_file.py new file mode 100644 index 00000000..b5ccd0ae --- /dev/null +++ b/account_statement_import_file/tests/test_account_statement_import_file.py @@ -0,0 +1,148 @@ +# Copyright 2024 Sygel - Manuel Regidor +# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html + +import base64 + +import odoo.tests.common as common +from odoo.exceptions import UserError +from odoo.tools.misc import file_path + + +class TestAccountStatementImportFile(common.TransactionCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.eur_currency = cls.env["res.currency"].search( + [("name", "=", "EUR"), ("active", "=", False)], limit=1 + ) + cls.eur_currency.write({"active": True}) + cls.bank_account = cls.env["res.partner.bank"].create( + {"acc_number": "1111111111", "partner_id": cls.env.company.partner_id.id} + ) + cls.bank_account_2 = cls.env["res.partner.bank"].create( + {"acc_number": "3333333333", "partner_id": cls.env.company.partner_id.id} + ) + cls.journal_1 = cls.env["account.journal"].create( + { + "name": "Test asset journal-1", + "code": "AST-1", + "type": "bank", + "bank_account_id": cls.bank_account.id, + } + ) + cls.journal_2 = cls.env["account.journal"].create( + { + "name": "Test asset journal-2", + "code": "AST-2", + "type": "bank", + "bank_account_id": cls.bank_account.id, + } + ) + f_path = file_path("account_statement_import_file/tests/test_file.txt") + file = base64.b64encode(open(f_path, "rb").read()) + cls.import_wizard = ( + cls.env["account.statement.import"] + .with_context(journal_id=cls.journal_1.id) + .create({"statement_file": file, "statement_filename": "Test"}) + ) + + def test_complete_stmts_vals(self): + # ERROR: Missing payment_ref on a transaction. + import_wizard = self.import_wizard + stmts_vals = [{"transactions": [{"payment_ref": ""}]}] + with self.assertRaises(UserError): + import_wizard._complete_stmts_vals(stmts_vals, self.journal_1, "1111111111") + + def test_match_journal(self): + import_wizard = self.import_wizard + + # ERROR: The format of this bank statement file doesn't " + # contain the bank account number, so you must + # start the wizard from the right bank journal + # in the dashboard. + with self.assertRaises(UserError): + import_wizard.with_context(journal_id=False)._match_journal( + False, self.eur_currency + ) + + # ERROR: The journal found for the file (%(journal_match)s) is " + # "different from the selected journal (%(journal_selected)s). + with self.assertRaises(UserError): + import_wizard.with_context(journal_id=self.journal_2.id)._match_journal( + "1111111111", self.eur_currency + ) + + # ERROR: The bank account with number '%(account_number)s' exists in Odoo + # but it is not set on any bank journal. You should + # set it on the related bank journal. If the related + # bank journal doesn't exist yet, you should create + # a new one. + self.journal_1.write({"type": "general"}) + self.journal_2.write({"type": "general"}) + with self.assertRaises(UserError): + import_wizard.with_context(journal_id=self.journal_2.id)._match_journal( + "1111111111", self.eur_currency + ) + + # ERROR: Could not find any bank account with number '%(account_number)s' + # linked to partner '%(partner_name)s'. You should create the bank + # account and set it on the related bank journal. + # If the related bank journal doesn't exist yet, you + # should create a new one." + with self.assertRaises(UserError): + import_wizard.with_context(journal_id=self.journal_2.id)._match_journal( + "2222222222", self.eur_currency + ) + + def test_import_single_statement(self): + import_wizard = self.import_wizard + # ERROR: The parsing of the statement file returned an invalid result. + vals = [1, 1, {"val1: 1"}] + result = {"statement_ids": [], "notifications": []} + with self.assertRaises(UserError): + import_wizard.import_single_statement(vals, result) + + # ERROR: Missing currency code in the bank statement file. + vals = ( + False, + "2910907154", + [ + { + "transactions": [ + { + "payment_ref": "PAYMENT REF", + "ref": "REF", + "amount": -1, + "partner_name": "PARTNER", + }, + ], + "balance_start": 10, + "balance_end_real": 9, + } + ], + ) + with self.assertRaises(UserError): + import_wizard.import_single_statement(vals, result) + + # ERROR: The bank statement file uses currency '%s' but there is no + # such currency in Odoo." + vals = ( + "NOK", + "2910907154", + [ + { + "transactions": [ + { + "payment_ref": "PAYMENT REF", + "ref": "REF", + "amount": -1, + "partner_name": "PARTNER", + }, + ], + "balance_start": 10, + "balance_end_real": 9, + } + ], + ) + with self.assertRaises(UserError): + import_wizard.import_single_statement(vals, result) diff --git a/account_statement_import_file/tests/test_file.txt b/account_statement_import_file/tests/test_file.txt new file mode 100644 index 00000000..db13e09f --- /dev/null +++ b/account_statement_import_file/tests/test_file.txt @@ -0,0 +1 @@ +TEST_STATEMENT_IMPORT diff --git a/account_statement_import_file/views/account_journal.xml b/account_statement_import_file/views/account_journal.xml index 86e832f7..e91ead74 100644 --- a/account_statement_import_file/views/account_journal.xml +++ b/account_statement_import_file/views/account_journal.xml @@ -12,7 +12,7 @@ diff --git a/account_statement_import_file/wizard/account_statement_import.py b/account_statement_import_file/wizard/account_statement_import.py index c18693ce..fc2b3c4d 100644 --- a/account_statement_import_file/wizard/account_statement_import.py +++ b/account_statement_import_file/wizard/account_statement_import.py @@ -230,13 +230,13 @@ class AccountStatementImport(models.TransientModel): ctx_journal = journal_obj.browse(ctx_journal_id) raise UserError( _( - "The journal found for the file (%(journal_match)s) is " - "different from the selected journal (%(journal_selected)s).", + "The journal found for the file (%(journal_match)s) is" + " different from the selected journal " + "(%(journal_selected)s).", journal_match=journal.display_name, journal_selected=ctx_journal.display_name, ) ) - if not journal: bank_accounts = self.env["res.partner.bank"].search( [ @@ -248,22 +248,23 @@ class AccountStatementImport(models.TransientModel): if bank_accounts: raise UserError( _( - "The bank account with number '%(account_number)s' exists in Odoo " - "but it is not set on any bank journal. You should " - "set it on the related bank journal. If the related " - "bank journal doesn't exist yet, you should create " - "a new one.", + "The bank account with number '%(account_number)s'" + " exists in Odoo but it is not set on any bank " + "journal. You should set it on the related bank " + "journal. If the related bank journal doesn't " + " exist yet, you should create a new one.", account_number=account_number, ) ) else: raise UserError( _( - "Could not find any bank account with number '%(account_number)s' " - "linked to partner '%(partner_name)s'. You should create the bank " + "Could not find any bank account with number " + "'%(account_number)s' linked to partner '" + "%(partner_name)s'. You should create the bank " "account and set it on the related bank journal. " - "If the related bank journal doesn't exist yet, you " - "should create a new one.", + "If the related bank journal doesn't exist yet, " + "you should create a new one.", account_number=account_number, partner_name=company.partner_id.display_name, )