diff --git a/account_bank_statement_import_online_adyen/models/online_bank_statement_provider.py b/account_bank_statement_import_online_adyen/models/online_bank_statement_provider.py index 4e6ef44d..97d3467d 100644 --- a/account_bank_statement_import_online_adyen/models/online_bank_statement_provider.py +++ b/account_bank_statement_import_online_adyen/models/online_bank_statement_provider.py @@ -42,13 +42,7 @@ class OnlineBankStatementProvider(models.Model): for provider in adyen_providers: is_scheduled = self.env.context.get("scheduled") try: - attachment_vals = self._get_attachment_vals() - import_wizard = self.env["account.bank.statement.import"].create( - {"attachment_ids": [(0, 0, attachment_vals)]} - ) - import_wizard.with_context( - {"account_bank_statement_import_adyen": True} - ).import_file() + self._import_adyen_file() except BaseException as e: if is_scheduled: _logger.warning( @@ -70,6 +64,21 @@ class OnlineBankStatementProvider(models.Model): if is_scheduled: provider._schedule_next_run() + def _import_adyen_file(self): + """Import Adyen file using functionality from manual Adyen import module.""" + self.ensure_one() + content, attachment_vals = self._get_attachment_vals() + wizard = ( + self.env["account.bank.statement.import"] + .with_context({"journal_id": self.journal_id.id}) + .create({"attachment_ids": [(0, 0, attachment_vals)]}) + ) + currency_code, account_number, stmts_vals = wizard._parse_adyen_file(content) + wizard._check_parsed_data(stmts_vals, account_number) + _currency, journal = wizard._find_additional_data(currency_code, account_number) + stmts_vals = wizard._complete_stmts_vals(stmts_vals, journal, account_number) + wizard._create_bank_statements(stmts_vals) + def _get_attachment_vals(self): """Retrieve settlement details and convert to attachment vals.""" content, filename = self._adyen_get_settlement_details_file() @@ -79,7 +88,7 @@ class OnlineBankStatementProvider(models.Model): byte_padding = b"=" * (byte_count % 4) data_file = encoded_content + byte_padding attachment_vals = {"name": filename, "datas": data_file} - return attachment_vals + return content, attachment_vals def _adyen_get_settlement_details_file(self): """Retrieve daily generated settlement details file. diff --git a/account_bank_statement_import_online_adyen/tests/online_bank_statement_provider_dummy.py b/account_bank_statement_import_online_adyen/tests/online_bank_statement_provider_dummy.py index 39adbe37..9b028cb4 100644 --- a/account_bank_statement_import_online_adyen/tests/online_bank_statement_provider_dummy.py +++ b/account_bank_statement_import_online_adyen/tests/online_bank_statement_provider_dummy.py @@ -1,12 +1,13 @@ -# Copyright 2021 Therp BV . +# Copyright 2021-2022 Therp BV . # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). -import base64 - +"""Dummy provider gets files from file-system, instead of from api.""" from odoo import models from odoo.modules.module import get_module_resource class OnlineBankStatementProviderDummy(models.Model): + """Dummy provider gets files from file-system, instead of from api.""" + _inherit = "online.bank.statement.provider" def _adyen_get_settlement_details_file(self): @@ -20,5 +21,4 @@ class OnlineBankStatementProviderDummy(models.Model): ) with open(testfile, "rb") as datafile: data_file = datafile.read() - data_file = base64.b64encode(data_file) return data_file, filename diff --git a/account_bank_statement_import_online_adyen/tests/test_import_online.py b/account_bank_statement_import_online_adyen/tests/test_import_online.py index 9921e51f..64d42de4 100644 --- a/account_bank_statement_import_online_adyen/tests/test_import_online.py +++ b/account_bank_statement_import_online_adyen/tests/test_import_online.py @@ -1,9 +1,11 @@ -# Copyright 2021 Therp BV . +# Copyright 2021-2022 Therp BV . # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +"""Test online Adyen reusing tests for manual import.""" from dateutil.relativedelta import relativedelta from odoo import fields +# pylint: disable=import-error from odoo.addons.account_bank_statement_import_adyen.tests.test_import_adyen import ( TestImportAdyen, ) @@ -14,6 +16,8 @@ class TestImportOnline(TestImportAdyen): @classmethod def setUpClass(cls): + """Setup online journal.""" + # pylint: disable=invalid-name super().setUpClass() cls.now = fields.Datetime.now() cls.journal.write( @@ -53,6 +57,7 @@ class TestImportOnline(TestImportAdyen): ) # Pull from yesterday, until today yesterday = self.now - relativedelta(days=1) + # pylint: disable=protected-access provider.with_context(scheduled=True)._pull(yesterday, self.now) # statement name is account number + '-' + date of last line. statements = self.env["account.bank.statement"].search(