[IMP] *_online_adyen: Directly parse retrieved adyen file

Prevent other statement import modules from processing the file. Without this for instance the
Enterprise account_bank_statement_import_csv module will process a retrieved cv file. In addition this
is more efficient as it saves a decoding step.
This commit is contained in:
Ronald Portier
2022-03-17 15:58:25 +01:00
committed by Ronald Portier (Therp BV)
parent 0f54cfbbe9
commit 88b8b572a8
3 changed files with 27 additions and 13 deletions

View File

@@ -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.

View File

@@ -1,12 +1,13 @@
# Copyright 2021 Therp BV <https://therp.nl>.
# Copyright 2021-2022 Therp BV <https://therp.nl>.
# 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

View File

@@ -1,9 +1,11 @@
# Copyright 2021 Therp BV <https://therp.nl>.
# Copyright 2021-2022 Therp BV <https://therp.nl>.
# 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(