From 940435482633a29ecbc467e00eaba42020bf1af8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Mart=C3=ADnez?= Date: Tue, 25 Feb 2025 12:47:32 +0100 Subject: [PATCH 1/2] [FIX] account_statement_import_sheet_file: Post-install test + fallback to load CoA Since odoo/odoo@d0342c8, the default existing company is not getting a CoA automatically, provoking than the current tests fail with the error: odoo.exceptions.UserError: No journal could be found in company My Company (San Francisco) for any of those types: sale Thus, we put tests post-install for being sure localization modules are installed, the same as AccountTestInvoicingCommon does, but we don't inherit from it, as it creates an overhead creating 2 new companies and loading their CoA and some more stuff, while we don't need all of that. Besides, if you don't have `l10n_generic_coa` installed, you can't use another CoA (like `l10n_es`) easily, so we put little code to select the first available CoA. --- ...est_account_statement_import_sheet_file.py | 58 +++++++++++-------- 1 file changed, 34 insertions(+), 24 deletions(-) diff --git a/account_statement_import_sheet_file/tests/test_account_statement_import_sheet_file.py b/account_statement_import_sheet_file/tests/test_account_statement_import_sheet_file.py index de38578d0..9918d1d4f 100644 --- a/account_statement_import_sheet_file/tests/test_account_statement_import_sheet_file.py +++ b/account_statement_import_sheet_file/tests/test_account_statement_import_sheet_file.py @@ -9,50 +9,60 @@ from odoo import fields from odoo.exceptions import UserError -from odoo.tests import common +from odoo.tests import common, tagged from odoo.tools import float_round +@tagged("post_install", "-at_install") class TestAccountStatementImportSheetFile(common.TransactionCase): - def setUp(self): - super().setUp() - - self.now = fields.Datetime.now() - self.currency_eur = self.env.ref("base.EUR") - self.currency_usd = self.env.ref("base.USD") - self.currency_usd.active = True + @classmethod + def setUpClass(cls): + super().setUpClass() + if not cls.env.company.chart_template_id: + # Load a CoA if there's none in current company + coa = cls.env.ref("l10n_generic_coa.configurable_chart_template", False) + if not coa: + # Load the first available CoA + coa = cls.env["account.chart.template"].search( + [("visible", "=", True)], limit=1 + ) + coa.try_loading(company=cls.env.company, install_demo=False) + cls.now = fields.Datetime.now() + cls.currency_eur = cls.env.ref("base.EUR") + cls.currency_usd = cls.env.ref("base.USD") + cls.currency_usd.active = True # Make sure the currency of the company is USD, as this not always happens # To be removed in V17: https://github.com/odoo/odoo/pull/107113 - self.company = self.env.company - self.env.cr.execute( + cls.company = cls.env.company + cls.env.cr.execute( "UPDATE res_company SET currency_id = %s WHERE id = %s", - (self.env.ref("base.USD").id, self.company.id), + (cls.env.ref("base.USD").id, cls.company.id), ) # Activate EUR for unit test, by default is not active - self.currency_eur.active = True - self.sample_statement_map = self.env.ref( + cls.currency_eur.active = True + cls.sample_statement_map = cls.env.ref( "account_statement_import_sheet_file.sample_statement_map" ) - self.AccountJournal = self.env["account.journal"] - self.AccountBankStatement = self.env["account.bank.statement"] - self.AccountStatementImport = self.env["account.statement.import"] - self.AccountStatementImportSheetMapping = self.env[ + cls.AccountJournal = cls.env["account.journal"] + cls.AccountBankStatement = cls.env["account.bank.statement"] + cls.AccountStatementImport = cls.env["account.statement.import"] + cls.AccountStatementImportSheetMapping = cls.env[ "account.statement.import.sheet.mapping" ] - self.AccountStatementImportWizard = self.env["account.statement.import"] - self.suspense_account = self.env["account.account"].create( + cls.AccountStatementImportWizard = cls.env["account.statement.import"] + cls.suspense_account = cls.env["account.account"].create( { "code": "987654", "name": "Suspense Account", "account_type": "asset_current", } ) - self.parser = self.env["account.statement.import.sheet.parser"] + cls.parser = cls.env["account.statement.import.sheet.parser"] # Mock the mapping object to return predefined separators - self.mock_mapping_comma_dot = Mock() - self.mock_mapping_comma_dot._get_float_separators.return_value = (",", ".") - self.mock_mapping_dot_comma = Mock() - self.mock_mapping_dot_comma._get_float_separators.return_value = (".", ",") + cls.mock_mapping_comma_dot = Mock() + cls.mock_mapping_comma_dot._get_float_separators.return_value = (",", ".") + cls.mock_mapping_dot_comma = Mock() + cls.mock_mapping_dot_comma._get_float_separators.return_value = (".", ",") def _data_file(self, filename, encoding=None): mode = "rt" if encoding else "rb" From a4a0dec37ae5680eb46c22d93d5ab266a29832e0 Mon Sep 17 00:00:00 2001 From: OCA-git-bot Date: Tue, 25 Feb 2025 12:09:13 +0000 Subject: [PATCH 2/2] [BOT] post-merge updates --- README.md | 2 +- account_statement_import_sheet_file/README.rst | 2 +- account_statement_import_sheet_file/__manifest__.py | 2 +- .../static/description/index.html | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 3db063a14..27bc87b4e 100644 --- a/README.md +++ b/README.md @@ -34,7 +34,7 @@ addon | version | maintainers | summary [account_statement_import_online_ponto](account_statement_import_online_ponto/) | 16.0.1.1.1 | | Online Bank Statements: MyPonto.com [account_statement_import_online_qonto](account_statement_import_online_qonto/) | 16.0.1.0.1 | | Online Bank Statements: Qonto [account_statement_import_qif](account_statement_import_qif/) | 16.0.1.0.0 | | Import QIF Bank Statements -[account_statement_import_sheet_file](account_statement_import_sheet_file/) | 16.0.1.2.1 | [![alexey-pelykh](https://github.com/alexey-pelykh.png?size=30px)](https://github.com/alexey-pelykh) | Import TXT/CSV or XLSX files as Bank Statements in Odoo +[account_statement_import_sheet_file](account_statement_import_sheet_file/) | 16.0.1.2.2 | [![alexey-pelykh](https://github.com/alexey-pelykh.png?size=30px)](https://github.com/alexey-pelykh) | Import TXT/CSV or XLSX files as Bank Statements in Odoo [//]: # (end addons) diff --git a/account_statement_import_sheet_file/README.rst b/account_statement_import_sheet_file/README.rst index 02f4446ac..d5efa214c 100644 --- a/account_statement_import_sheet_file/README.rst +++ b/account_statement_import_sheet_file/README.rst @@ -7,7 +7,7 @@ Bank Statement TXT/CSV/XLSX Import !! This file is generated by oca-gen-addon-readme !! !! changes will be overwritten. !! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - !! source digest: sha256:aecd5a898a45f817bf55c788227ec5c5ef53661ae47b83630a5ebcb97d5dc663 + !! source digest: sha256:0f0aed661702d10a70818bb7e032653813de99c96c429c20b39f661e15b5ae8f !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! .. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png diff --git a/account_statement_import_sheet_file/__manifest__.py b/account_statement_import_sheet_file/__manifest__.py index ced18e13e..19071888f 100644 --- a/account_statement_import_sheet_file/__manifest__.py +++ b/account_statement_import_sheet_file/__manifest__.py @@ -5,7 +5,7 @@ { "name": "Bank Statement TXT/CSV/XLSX Import", "summary": "Import TXT/CSV or XLSX files as Bank Statements in Odoo", - "version": "16.0.1.2.1", + "version": "16.0.1.2.2", "category": "Accounting", "website": "https://github.com/OCA/bank-statement-import", "author": "ForgeFlow, CorporateHub, Odoo Community Association (OCA)", diff --git a/account_statement_import_sheet_file/static/description/index.html b/account_statement_import_sheet_file/static/description/index.html index c7e9ae06e..5d9d09bf8 100644 --- a/account_statement_import_sheet_file/static/description/index.html +++ b/account_statement_import_sheet_file/static/description/index.html @@ -367,7 +367,7 @@

Bank Statement TXT/CSV/XLSX Import

!! This file is generated by oca-gen-addon-readme !! !! changes will be overwritten. !! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -!! source digest: sha256:aecd5a898a45f817bf55c788227ec5c5ef53661ae47b83630a5ebcb97d5dc663 +!! source digest: sha256:0f0aed661702d10a70818bb7e032653813de99c96c429c20b39f661e15b5ae8f !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->

Beta License: AGPL-3 OCA/bank-statement-import Translate me on Weblate Try me on Runboat

This module allows you to import any TXT/CSV or XLSX file in Odoo as bank