From c532ff915ac685226b2a77a3775a9a404592b6ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Didderen?= Date: Tue, 27 Oct 2026 21:27:17 +0100 Subject: [PATCH] [IMP] account_ebics - Add unit tests Forward-port of the 18.0 tests. Add 108 tests (101 in the Community job): - account_ebics: order numbers, camt and CFONB split per account, journal lookup, duplicate statements, download and upload wizards, client setup with real keys, key initialisation (INI/HIA/HPB), passphrase change, admin orders. - account_ebics_batch: scheduled import, import log, reprocess. - account_ebics_payment_order / account_ebics_batch_payment: upload of the payment file and link to the payment document. - account_ebics_statement_import_test (new, test-only, not to install in production): installs the OCA camt and CFONB parsers in CI and runs the end-to-end statement import. - account_ebics_oe_statement_import_test (new, test-only, Enterprise job only): same through the Odoo Enterprise camt import. The bank is simulated by patching the EBICS transport; keys, certificates and the INI letter are real, created in a temporary directory. 19.0 differences: no account_ebics_oca_statement_import module (its glue-specific tests are dropped), res.users.group_ids. --- account_ebics_batch_payment/__manifest__.py | 2 +- account_ebics_batch_payment/tests/__init__.py | 1 + .../tests/test_batch_payment_upload.py | 77 +++++++++++++++++++ 3 files changed, 79 insertions(+), 1 deletion(-) create mode 100644 account_ebics_batch_payment/tests/__init__.py create mode 100644 account_ebics_batch_payment/tests/test_batch_payment_upload.py diff --git a/account_ebics_batch_payment/__manifest__.py b/account_ebics_batch_payment/__manifest__.py index 2888320..22e5bea 100644 --- a/account_ebics_batch_payment/__manifest__.py +++ b/account_ebics_batch_payment/__manifest__.py @@ -4,7 +4,7 @@ { "name": "EBICS - Batch Payments (Odoo Enterprise)", "summary": "Send an Odoo Enterprise batch payment to the bank over EBICS", - "version": "19.0.1.3.0", + "version": "19.0.1.3.1", "license": "LGPL-3", "author": "Noviat", "website": "https://www.noviat.com/", diff --git a/account_ebics_batch_payment/tests/__init__.py b/account_ebics_batch_payment/tests/__init__.py new file mode 100644 index 0000000..2684399 --- /dev/null +++ b/account_ebics_batch_payment/tests/__init__.py @@ -0,0 +1 @@ +from . import test_batch_payment_upload diff --git a/account_ebics_batch_payment/tests/test_batch_payment_upload.py b/account_ebics_batch_payment/tests/test_batch_payment_upload.py new file mode 100644 index 0000000..87cbd6d --- /dev/null +++ b/account_ebics_batch_payment/tests/test_batch_payment_upload.py @@ -0,0 +1,77 @@ +# Copyright 2026 Noviat. +# License LGPL-3 or later (https://www.gnu.org/licenses/lgpl). + +import base64 +from unittest.mock import patch + +from odoo.exceptions import UserError +from odoo.tests import tagged + +from odoo.addons.account_ebics.tests.common import EbicsTestCommon, FakeEbicsClient + + +@tagged("post_install", "-at_install") +class TestBatchPaymentUpload(EbicsTestCommon): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.journal = cls._create_bank_journal("TBP", "FR7630004000031234567890143") + cls.ff_cct = cls.env.ref("account_ebics.ebics_ff_CCT") + cls.method = cls.env.ref("account.account_payment_method_manual_out") + + def _batch(self, state="sent"): + batch = self.env["account.batch.payment"].create( + { + "journal_id": self.journal.id, + "batch_type": "outbound", + "payment_method_id": self.method.id, + "export_file": base64.b64encode(b"pain.001"), + "export_filename": "batch.xml", + } + ) + # Without payments the batch stays in draft: set the state directly. + batch.state = state + return batch + + def _generating_files(self): + batch_class = type(self.env["account.batch.payment"]) + return patch.object( + batch_class, "_get_methods_generating_files", return_value=["manual"] + ) + + def test_hide_ebics_upload(self): + with self._generating_files(): + self.assertFalse(self._batch().hide_ebics_upload) + self.assertTrue(self._batch(state="draft").hide_ebics_upload) + batch = self._batch() + batch.ebics_file_id = self.env["ebics.file"].create( + {"name": "batch.xml", "date": "2026-10-13", "pain_state": "uploaded"} + ) + self.assertTrue(batch.hide_ebics_upload) + # no file generation for this payment method + self.assertTrue(self._batch().hide_ebics_upload) + + def test_upload_requires_ebics_config(self): + self.ebics_config.journal_ids = False + with self.assertRaises(UserError): + self._batch().ebics_upload() + + def test_upload_format_from_payment_method(self): + self.method.ebics_file_format_id = self.ff_cct + action = self._batch().ebics_upload() + wizard = self.env["ebics.xfer"].browse(action["res_id"]) + self.assertEqual(wizard.format_id, self.ff_cct) + self.assertEqual(wizard.upload_fname, "batch.xml") + + def test_upload(self): + self.method.ebics_file_format_id = self.ff_cct + batch = self._batch() + action = batch.ebics_upload() + wizard = self.env["ebics.xfer"].browse(action["res_id"]) + with self._fake_client(FakeEbicsClient(order_id="N088")) as client: + wizard.with_context(**action["context"]).ebics_upload() + self.assertEqual(client.uploads[0][1], b"pain.001") + self.assertEqual(batch.ebics_order_number, "N088") + self.assertEqual(batch.ebics_pain_state, "uploaded") + self.assertIn(f"Batch Payment: {batch.name}", batch.ebics_file_id.note) + self.assertTrue(any("N088" in msg.body for msg in batch.message_ids))