From 6e011acaea60af4e71629886845bac7ab5988ba0 Mon Sep 17 00:00:00 2001 From: Sergio Bustamante Date: Fri, 1 Aug 2025 13:14:21 +0200 Subject: [PATCH 1/2] [FIX] account_statement_import_file: Move fix to base module --- .../models/__init__.py | 1 + .../models/account_bank_statement_line.py | 0 .../tests/__init__.py | 1 + .../test_account_statement_import_file.py | 45 ++++++++++++++ .../wizard/account_statement_import.py | 4 +- .../models/__init__.py | 1 - .../models/account_statement_import.py | 5 -- .../tests/fixtures/statement_eur.csv | 2 - ...est_account_statement_import_sheet_file.py | 61 ------------------- 9 files changed, 50 insertions(+), 70 deletions(-) rename {account_statement_import_sheet_file => account_statement_import_file}/models/account_bank_statement_line.py (100%) create mode 100644 account_statement_import_file/tests/__init__.py create mode 100644 account_statement_import_file/tests/test_account_statement_import_file.py delete mode 100644 account_statement_import_sheet_file/tests/fixtures/statement_eur.csv diff --git a/account_statement_import_file/models/__init__.py b/account_statement_import_file/models/__init__.py index 2388e1196..16a78ca32 100644 --- a/account_statement_import_file/models/__init__.py +++ b/account_statement_import_file/models/__init__.py @@ -1 +1,2 @@ from . import account_journal +from . import account_bank_statement_line diff --git a/account_statement_import_sheet_file/models/account_bank_statement_line.py b/account_statement_import_file/models/account_bank_statement_line.py similarity index 100% rename from account_statement_import_sheet_file/models/account_bank_statement_line.py rename to account_statement_import_file/models/account_bank_statement_line.py diff --git a/account_statement_import_file/tests/__init__.py b/account_statement_import_file/tests/__init__.py new file mode 100644 index 000000000..2a49db2e5 --- /dev/null +++ b/account_statement_import_file/tests/__init__.py @@ -0,0 +1 @@ +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 000000000..0334b8aca --- /dev/null +++ b/account_statement_import_file/tests/test_account_statement_import_file.py @@ -0,0 +1,45 @@ +from odoo.tests import tagged + +from odoo.addons.account.tests.common import AccountTestInvoicingCommon + + +@tagged("post_install", "-at_install") +class TestAccountStatementImportFile(AccountTestInvoicingCommon): + @classmethod + def setUpClass(cls, chart_template_ref=None): + super().setUpClass(chart_template_ref=chart_template_ref) + cls.eur_currency = cls.env.ref("base.EUR") + cls.usd_currency = cls.env.ref("base.USD") + cls.company = cls.env.company + cls.bank_journal_eur = cls.env["account.journal"].create( + { + "name": "Bank EUR Test", + "type": "bank", + "code": "BNK_T", + "currency_id": cls.eur_currency.id, + } + ) + + def test_eur_journal_usd_foreign(self): + statement_line = ( + self.env["account.bank.statement.line"] + .with_context(from_stmt_import=True) + .create( + { + "journal_id": self.bank_journal_eur.id, + "amount": 100.00, + "foreign_currency_id": self.usd_currency.id, + "amount_currency": 110.00, + } + ) + ) + move = statement_line.move_id + self.assertTrue(move) + bank_line = move.line_ids.filtered( + lambda line: line.account_id.account_type == "asset_cash" + ) + counterpart_line = move.line_ids - bank_line + self.assertEqual(counterpart_line.credit, 110.0) + self.assertEqual(counterpart_line.amount_currency, -100.0) + self.assertEqual(bank_line.debit, 110.0) + self.assertEqual(bank_line.amount_currency, 100.0) diff --git a/account_statement_import_file/wizard/account_statement_import.py b/account_statement_import_file/wizard/account_statement_import.py index 3e5ef76f8..26f013c7e 100644 --- a/account_statement_import_file/wizard/account_statement_import.py +++ b/account_statement_import_file/wizard/account_statement_import.py @@ -117,7 +117,9 @@ def import_single_statement(self, single_statement_data, result): # Prepare statement data to be used for bank statements creation stmts_vals = self._complete_stmts_vals(stmts_vals, journal, account_number) # Create the bank statements - self._create_bank_statements(stmts_vals, result) + self.with_context(from_stmt_import=True)._create_bank_statements( + stmts_vals, result + ) # Now that the import worked out, set it as the bank_statements_source # of the journal if journal.bank_statements_source != "file_import_oca": diff --git a/account_statement_import_sheet_file/models/__init__.py b/account_statement_import_sheet_file/models/__init__.py index 380e8bfa0..af86f7c78 100644 --- a/account_statement_import_sheet_file/models/__init__.py +++ b/account_statement_import_sheet_file/models/__init__.py @@ -2,6 +2,5 @@ from . import account_statement_import_sheet_mapping from . import account_statement_import_sheet_parser -from . import account_bank_statement_line from . import account_statement_import from . import account_journal diff --git a/account_statement_import_sheet_file/models/account_statement_import.py b/account_statement_import_sheet_file/models/account_statement_import.py index fe4e65aa6..4ad3ef42a 100644 --- a/account_statement_import_sheet_file/models/account_statement_import.py +++ b/account_statement_import_sheet_file/models/account_statement_import.py @@ -49,8 +49,3 @@ def _create_bank_statements(self, stmts_vals, result): amount = sum(statement.line_ids.mapped("amount")) statement.balance_end_real = statement.balance_start + amount return res - - def import_single_statement(self, single_statement_data, result): - return super( - AccountStatementImport, self.with_context(from_stmt_import=True) - ).import_single_statement(single_statement_data, result) diff --git a/account_statement_import_sheet_file/tests/fixtures/statement_eur.csv b/account_statement_import_sheet_file/tests/fixtures/statement_eur.csv deleted file mode 100644 index 82740a41b..000000000 --- a/account_statement_import_sheet_file/tests/fixtures/statement_eur.csv +++ /dev/null @@ -1,2 +0,0 @@ -Transaction Date,Type,Order,Card Brand,Card Source,Payout Status,Payout Date,Available On,Amount,Fee,Net,Checkout,Payment Method Name,Presentment Amount,Presentment Currency,Currency,VAT -2025-05-25 16:15:43 +0200,charge,#35919,visa,online,paid,2025-05-28,2025-05-28,100,5,95,#CHG123,card,95,EUR,USD,0.00 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 e44f55558..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 @@ -780,64 +780,3 @@ def test_skip_empty_lines(self): self.assertEqual(statement.balance_start, 0.0) self.assertEqual(statement.balance_end_real, 2291.5) self.assertEqual(statement.balance_end, 2291.5) - - def test_eur_journal_usd_foreign(self): - statement_map = self.AccountStatementImportSheetMapping.create( - { - "name": "Test Only - Foreign Currency CSV Mapping", - "timestamp_format": "%Y-%m-%d", - "debit_value": "refund", - "credit_value": "charge", - "timestamp_column": "Payout Date", - "currency_column": "Presentment Currency", - "amount_type": "simple_value", - "amount_column": "Presentment Amount", - "original_currency_column": "Currency", - "original_amount_column": "Amount", - "description_column": "Checkout", - "reference_column": "Order", - "float_thousands_sep": "none", - "float_decimal_sep": "dot", - } - ) - bank_journal_eur = self.AccountJournal.create( - { - "name": "Bank eur", - "type": "bank", - "code": "BNK_eur", - "currency_id": self.currency_eur.id, - "company_id": self.company.id, - } - ) - file_name = "fixtures/statement_eur.csv" - file_data = self._data_file(file_name) - wizard = ( - self.env["account.statement.import"] - .with_context(journal_id=bank_journal_eur.id) - .create( - { - "statement_file": file_data, - "statement_filename": "statement.csv", - "sheet_mapping_id": statement_map.id, - } - ) - ) - wizard.with_context( - account_statement_import_sheet_file_test=True - ).import_file_button() - statement = self.env["account.bank.statement"].search( - [("journal_id", "=", bank_journal_eur.id)], limit=1 - ) - self.assertTrue(statement) - self.assertEqual(len(statement.line_ids), 1) - line = statement.line_ids - move = line.move_id - self.assertTrue(move) - bank_line = move.line_ids.filtered( - lambda line: line.account_id.account_type == "asset_cash" - ) - counterpart_line = move.line_ids - bank_line - self.assertEqual(counterpart_line.credit, 100) - self.assertEqual(counterpart_line.amount_currency, -95.0) - self.assertEqual(bank_line.debit, 100.00) - self.assertEqual(bank_line.amount_currency, 95.0) From 02f20decf02188b64ce79f03f521e25a5a98aace Mon Sep 17 00:00:00 2001 From: Sergio Bustamante Date: Mon, 4 Aug 2025 11:42:33 +0200 Subject: [PATCH 2/2] [IMP] account_statement_import_file: Control when journal_currency == company_currency --- .../models/account_bank_statement_line.py | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/account_statement_import_file/models/account_bank_statement_line.py b/account_statement_import_file/models/account_bank_statement_line.py index 5f133eb89..0bc23dd9c 100644 --- a/account_statement_import_file/models/account_bank_statement_line.py +++ b/account_statement_import_file/models/account_bank_statement_line.py @@ -13,16 +13,16 @@ def _get_amounts_with_currencies(self): transaction_amount, foreign_currency, ) = super()._get_amounts_with_currencies() - if ( - self.env.context.get("from_stmt_import", False) - and self.foreign_currency_id - and self.foreign_currency_id == company_currency - ): - company_currency = self.journal_id.company_id.currency_id - journal_currency = self.journal_id.currency_id or company_currency - company_amount = self.amount_currency - foreign_currency = journal_currency - transaction_amount = self.amount + if self.env.context.get("from_stmt_import", False) and self.foreign_currency_id: + if self.foreign_currency_id == company_currency: + company_currency = self.journal_id.company_id.currency_id + journal_currency = self.journal_id.currency_id or company_currency + company_amount = self.amount_currency + foreign_currency = journal_currency + transaction_amount = self.amount + elif journal_currency == company_currency: + journal_amount = self.amount_currency + journal_currency = foreign_currency return ( company_amount, company_currency,