Skip to content

Commit

Permalink
[FIX] *_import[_online]_adyen: solve pre-commit errors
Browse files Browse the repository at this point in the history
  • Loading branch information
NL66278 committed Sep 25, 2023
1 parent 5bd5b7a commit 5eecd30
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 38 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
Original file line number Diff line number Diff line change
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
6 changes: 2 additions & 4 deletions account_statement_import_adyen/tests/test_import_adyen.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,8 @@ def _test_statement_import(self, file_name, statement_name):
{"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
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})
.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_bank_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 5eecd30

Please sign in to comment.