Skip to content

Commit

Permalink
[MIG] *_import[_online]_adyen: adapt to 16.0
Browse files Browse the repository at this point in the history
  • Loading branch information
NL66278 committed Sep 25, 2023
1 parent 82e5da0 commit 14762b2
Show file tree
Hide file tree
Showing 11 changed files with 57 additions and 91 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ repos:
name: flake8
additional_dependencies: ["flake8-bugbear==21.9.2", "importlib-metadata<5.0.0"]
- repo: https://github.com/OCA/pylint-odoo
rev: 7.0.2
rev: v8.0.9
hooks:
- id: pylint_odoo
name: pylint with optional checks
Expand Down
10 changes: 5 additions & 5 deletions account_statement_import_adyen/__manifest__.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
# Copyright 2017 Opener BV <https://opener.amsterdam>
# Copyright 2020 Vanmoof BV <https://www.vanmoof.com>
# Copyright 2021 Therp BV <https://therp.nl>.
# Copyright 2021-2023 Therp BV <https://therp.nl>.
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
{
"name": "Adyen statement import",
"version": "13.0.1.0.0",
"author": "Opener BV, Vanmoof BV, Odoo Community Association (OCA)",
"version": "16.0.1.0.0",
"author": "Opener BV, Vanmoof BV, Therp BV, Odoo Community Association (OCA)",
"category": "Banking addons",
"website": "https://github.com/OCA/bank-statement-import",
"license": "AGPL-3",
"depends": [
"base_import",
"account_bank_statement_import",
"account_bank_statement_clearing_account",
"account_statement_import_base",
"account_statement_clearing_account",
],
"data": ["views/account_journal.xml"],
"installable": True,
Expand Down
4 changes: 2 additions & 2 deletions account_statement_import_adyen/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from . import account_bank_statement_import
from . import account_bank_statement_import_adyen_parser
from . import account_statement_import
from . import account_statement_import_adyen_parser
from . import account_journal
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Copyright 2017 Opener BV (<https://opener.amsterdam>)
# Copyright 2021-2022 Therp BV <https://therp.nl>.
# Copyright 2021-2023 Therp BV <https://therp.nl>.
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
"""Add import of Adyen statements."""
# pylint: disable=protected-access,no-self-use
Expand All @@ -11,26 +11,26 @@
_logger = logging.getLogger(__name__) # pylint: disable=invalid-name


class AccountBankStatementImport(models.TransientModel):
class AccountStatementImport(models.TransientModel):
"""Add import of Adyen statements."""

_inherit = "account.bank.statement.import"
_inherit = "account.statement.import"

def _parse_file(self, data_file):
"""Parse an Adyen xlsx file and map merchant account strings to journals."""
try:
return self._parse_adyen_file(data_file)
except Exception as exc: # pylint: disable=broad-except
message = _("Statement file was not a Adyen settlement details file.")
if self.env.context.get("account_bank_statement_import_adyen", False):
if self.env.context.get("account_statement_import_adyen", False):
raise UserError(message) from exc
_logger.debug(message, exc_info=True)
return super()._parse_file(data_file)

def _parse_adyen_file(self, data_file):
"""Just parse the adyen file."""
_logger.debug(_("Try parsing as Adyen settlement details."))
parser = self.env["account.bank.statement.import.adyen.parser"]
parser = self.env["account.statement.import.adyen.parser"]
rows = self._get_rows(data_file)
return parser.parse_rows(rows)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@
}


class AccountBankStatementImportAdyenParser(models.TransientModel):
class AccountStatementImportAdyenParser(models.TransientModel):
"""Parse Adyen statement files for bank import."""

_name = "account.bank.statement.import.adyen.parser"
_description = "Account Bank Statement Import Adyen Parser"
_name = "account.statement.import.adyen.parser"
_description = "Account Statement Import Adyen Parser"

def parse_rows(self, rows):
"""Parse rows generated from an Adyen file.
Expand Down Expand Up @@ -82,7 +82,7 @@ def parse_rows(self, rows):
)
self._validate_statement(statement, payout, balance)
_logger.info(
_("Processed %d rows from Adyen statement file with %d transactions"),
"Processed %d rows from Adyen statement file with %d transactions",
num_rows,
len(statement["transactions"]),
)
Expand Down Expand Up @@ -182,8 +182,11 @@ def _validate_statement(self, statement, payout, balance):
_logger.info(_("No payout detected in Adyen statement."))
if self.env.user.company_id.currency_id.compare_amounts(balance, payout) != 0:
raise UserError(
_("Parse error. Balance %s not equal to merchant " "payout %s")
% (balance, payout)
_(
"Parse error."
" Balance %(balance)s not equal to merchant payout %(payout)s"
)
% {"balance": balance, "payout": payout}
)

def _get_value(self, row, column):
Expand Down
10 changes: 4 additions & 6 deletions account_statement_import_adyen/tests/test_import_adyen.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,18 +100,16 @@ def test_05_import_adyen_csv(self):
def _test_statement_import(self, file_name, statement_name):
"""Test correct creation of single statement."""
testfile = get_module_resource(
"account_bank_statement_import_adyen", "test_files", file_name
"account_statement_import_adyen", "test_files", file_name
)
with open(testfile, "rb") as datafile:
data_file = base64.b64encode(datafile.read())
import_wizard = self.env["account.bank.statement.import"].create(
import_wizard = self.env["account.statement.import"].create(
{"attachment_ids": [(0, 0, {"name": file_name, "datas": data_file})]}
)
import_wizard.with_context(
{
"account_bank_statement_import_adyen": True,
"journal_id": self.journal.id,
}
account_bank_statement_import_adyen=True,
journal_id=self.journal.id,
).import_file()
# statement name is account number + '-' + date of last line.
statements = self.env["account.bank.statement"].search(
Expand Down
8 changes: 4 additions & 4 deletions account_statement_import_online_adyen/__manifest__.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
# Copyright 2021 - Therp BV <https://therp.nl>.
# Copyright 2021-2023 - Therp BV <https://therp.nl>.
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
{
"name": "Online Bank Statements: Adyen payment report",
"version": "13.0.1.0.0",
"version": "16.0.1.0.0",
"category": "Account",
"website": "https://github.com/OCA/bank-statement-import",
"author": "Ronald Portier (Therp BV), Odoo Community Association (OCA)",
"license": "AGPL-3",
"installable": True,
"depends": [
"account_bank_statement_import_adyen",
"account_bank_statement_import_online",
"account_statement_import_adyen",
"account_statement_import_online",
],
"data": ["views/online_bank_statement_provider.xml"],
}
1 change: 0 additions & 1 deletion account_statement_import_online_adyen/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from . import account_journal
from . import online_bank_statement_provider
30 changes: 0 additions & 30 deletions account_statement_import_online_adyen/models/account_journal.py

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

from odoo import _, api, fields, models
from odoo.exceptions import UserError
from odoo.modules.module import get_module_resource

_logger = logging.getLogger(__name__)

Expand All @@ -31,12 +32,13 @@ def _get_available_services(self):

def _pull(self, date_since, date_until): # noqa: C901
"""Split between adyen providers and others."""
result = None # Need because of super() call.
adyen_providers = self.filtered(lambda r: r.service in ("adyen", "dummy_adyen"))
other_providers = self.filtered(
lambda r: r.service not in ("adyen", "dummy_adyen")
)
if other_providers:
super(OnlineBankStatementProvider, other_providers)._pull(
result = super(OnlineBankStatementProvider, other_providers)._pull(
date_since, date_until
)
for provider in adyen_providers:
Expand All @@ -63,14 +65,15 @@ def _pull(self, date_since, date_until): # noqa: C901
raise
if is_scheduled:
provider._schedule_next_run()
return result

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})
self.env["account.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)
Expand Down Expand Up @@ -101,24 +104,41 @@ def _adyen_get_settlement_details_file(self):
https://ca-test.adyen.com/reports/download/MerchantAccount/ +
[YourMerchantAccount]/[ReportFileName]"
"""
if self.service == "dummy_adyen":
# Call the dummy method for testing.
return super()._adyen_dummy_get_settlement_details_file()
batch_number = self.next_batch_number
filename = self.download_file_name % batch_number
URL = "/".join(
[self.api_base, self.journal_id.adyen_merchant_account, filename]
)
response = requests.get(URL, auth=(self.username, self.password), timeout=30)
if response.status_code != 200:
raise UserError(_("%s \n\n %s") % (response.status_code, response.text))
_logger.debug(_("Headers returned by Adyen %s"), response.headers)
raise UserError(
_("%(status_code)s \n\n %(text)s")
% {"status_code": response.status_code, "text": response.text}
)
_logger.debug("Headers returned by Adyen %s", response.headers)
byte_count = len(response.content)
_logger.debug(
_("Retrieved %d bytes from Adyen, starting with %s"),
"Retrieved %d bytes from Adyen, starting with %s",
byte_count,
response.content[:64],
)
return response.content, filename

def _adyen_dummy_get_settlement_details_file(self):
"""Get file from disk, instead of from url."""
filename = self.download_file_name
testfile = get_module_resource(
"account_statement_import_adyen", "test_files", filename
)
with open(testfile, "rb") as datafile:
data_file = datafile.read()
return data_file, filename

def _schedule_next_run(self):
"""Set next run date and autoincrement batch number."""
super()._schedule_next_run()
result = super()._schedule_next_run()
self.next_batch_number += 1
return result

This file was deleted.

0 comments on commit 14762b2

Please sign in to comment.