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 Oct 18, 2023
1 parent 0f3b1ef commit 514284f
Show file tree
Hide file tree
Showing 19 changed files with 150 additions and 206 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
78 changes: 25 additions & 53 deletions account_statement_clearing_account/tests/test_clearing_account.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,70 +2,78 @@
# Copyright 2020 Vanmoof BV <https://www.vanmoof.com>
# Copyright 2015-2023 Therp BV <https://therp.nl>)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from odoo.tests.common import SavepointCase
from odoo.tests.common import TransactionCase


class TestClearingAccount(SavepointCase):
class TestClearingAccount(TransactionCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.suspense_account = cls.env["account.account"].create(
{
"company_id": cls.env.user.company_id.id,
"name": "TEST Bank Suspense Account",
"code": "TESTSPS",
"account_type": "asset_current",
"reconcile": True,
"currency_id": cls.env.ref("base.USD").id,
}
)
cls.journal = cls.env["account.journal"].create(
{
"company_id": cls.env.user.company_id.id,
"name": "Clearing account test",
"code": "CAT",
"type": "bank",
"bank_acc_number": "NL02ABNA0123456789",
"currency_id": cls.env.ref("base.USD").id,
"suspense_account_id": cls.suspense_account.id,
}
)
cls.partner_customer = cls.env["res.partner"].create({"name": "customer"})
cls.partner_provider = cls.env["res.partner"].create({"name": "provider"})
# Enable reconcilation on the default journal account to trigger
# the functionality from account_bank_statement_clearing_account
cls.journal.default_debit_account_id.reconcile = True

def test_reconcile_unreconcile(self):
"""Test that a bank statement that satiesfies the conditions, cab be
automatically reconciled and unreconciled on confirmation or reset of the
statement.
"""Test that a bank statement that satisfies the conditions, can be
automatically reconciled.
"""
account = self.journal.default_debit_account_id
# TODO bank statement no longer has a state, nor a confirm button.
# So the previuously existing checks might need to be done in another way.
statement = self.env["account.bank.statement"].create(
{
"name": "Test autoreconcile 2021-03-08",
"reference": "AUTO-2021-08-03",
"date": "2021-03-08",
"state": "open",
"journal_id": self.journal.id,
"line_ids": [
(
0,
0,
{
"name": "web sale",
"journal_id": self.journal.id,
"partner_id": self.partner_customer.id,
"amount": 100.00,
"account_id": account.id,
},
),
(
0,
0,
{
"name": "transaction_fees",
"journal_id": self.journal.id,
"partner_id": False,
"amount": -1.25,
"account_id": account.id,
},
),
(
0,
0,
{
"name": "due_from_provider",
"journal_id": self.journal.id,
"partner_id": self.partner_provider.id,
"amount": -98.75,
"account_id": account.id,
},
),
],
Expand All @@ -78,43 +86,7 @@ def test_reconcile_unreconcile(self):
sum(line.amount for line in statement.line_ids)
)
)
account = self.env["account.account"].search(
[("internal_type", "=", "receivable")], limit=1
)
for line in statement.line_ids:
line.process_reconciliation(
new_aml_dicts=[
{
"debit": -line.amount if line.amount < 0 else 0,
"credit": line.amount if line.amount > 0 else 0,
"account_id": account.id,
}
]
)
statement.button_confirm_bank()
self.assertEqual(statement.state, "confirm")
lines = self.env["account.move.line"].search(
[
("account_id", "=", self.journal.default_debit_account_id.id),
("statement_id", "=", statement.id),
]
)
reconcile = lines.mapped("full_reconcile_id")
self.assertEqual(len(reconcile), 1)
self.assertEqual(lines, reconcile.reconciled_line_ids)

# Reset the bank statement to see the counterpart lines being
# unreconciled
statement.button_reopen()
self.assertEqual(statement.state, "open")
self.assertFalse(lines.mapped("matched_debit_ids"))
self.assertFalse(lines.mapped("matched_credit_ids"))
self.assertFalse(lines.mapped("full_reconcile_id"))

# Confirm the statement without the correct clearing account settings
self.journal.default_debit_account_id.reconcile = False
statement.button_confirm_bank()
self.assertEqual(statement.state, "confirm")
self.assertFalse(lines.mapped("matched_debit_ids"))
self.assertFalse(lines.mapped("matched_credit_ids"))
self.assertFalse(lines.mapped("full_reconcile_id"))
# TODO: Test working of suspend account
# account = self.env["account.account"].search(
# [("account_type", "=", "asset_receivable")], limit=1
# )
2 changes: 2 additions & 0 deletions account_statement_import_adyen/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from . import models
from . import wizards
15 changes: 9 additions & 6 deletions account_statement_import_adyen/__manifest__.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
# 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_file",
"account_statement_clearing_account",
],
"data": [
"security/ir.model.access.csv",
"views/account_journal.xml",
],
"data": ["views/account_journal.xml"],
"installable": True,
}
3 changes: 1 addition & 2 deletions account_statement_import_adyen/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
from . import account_bank_statement_import
from . import account_bank_statement_import_adyen_parser
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from . import account_journal
2 changes: 2 additions & 0 deletions account_statement_import_adyen/security/ir.model.access.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
access_account_statement_import_adyen_parser,access_account_statement_import_adyen_parser,model_account_statement_import_adyen_parser,base.group_user,1,0,0,0
28 changes: 15 additions & 13 deletions account_statement_import_adyen/tests/test_import_adyen.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
# Copyright 2017 Opener BV <https://opener.amsterdam>
# Copyright 2020 Vanmoof BV <https://www.vanmoof.com>
# Copyright 2015-2022 Therp BV <https://therp.nl>)
# Copyright 2015-2023 Therp BV <https://therp.nl>)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
"""Run test imports of Adyen files."""
import base64

from odoo.exceptions import UserError
from odoo.modules.module import get_module_resource
from odoo.tests.common import SavepointCase
from odoo.tests.common import TransactionCase


class TestImportAdyen(SavepointCase):
class TestImportAdyen(TransactionCase):
"""Run test imports of Adyen files."""

@classmethod
Expand All @@ -22,6 +21,7 @@ def setUpClass(cls):
"name": "Adyen test",
"code": "ADY",
"type": "bank",
"bank_acc_number": "YOURCOMPANY_ACCOUNT",
"adyen_merchant_account": "YOURCOMPANY_ACCOUNT",
"currency_id": cls.env.ref("base.USD").id,
}
Expand Down Expand Up @@ -55,7 +55,7 @@ def test_02_import_adyen_credit_fees(self):

def test_03_import_adyen_invalid(self):
"""Trying to hit that coverall target"""
with self.assertRaisesRegex(UserError, "not a Adyen settlement details file"):
with self.assertRaisesRegex(ValueError, "not a Adyen settlement details file"):
self._test_statement_import(
"adyen_test_invalid.xls",
"invalid",
Expand Down Expand Up @@ -99,20 +99,22 @@ def test_05_import_adyen_csv(self):

def _test_statement_import(self, file_name, statement_name):
"""Test correct creation of single statement."""
wizard_model = self.env["account.statement.import"]
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(
{"attachment_ids": [(0, 0, {"name": file_name, "datas": data_file})]}
)
import_wizard.with_context(
import_wizard = wizard_model.create(
{
"account_bank_statement_import_adyen": True,
"journal_id": self.journal.id,
"statement_file": data_file,
"statement_filename": file_name,
}
).import_file()
)
import_wizard.with_context(
account_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(
[("name", "=", statement_name)]
Expand Down
3 changes: 3 additions & 0 deletions account_statement_import_adyen/wizards/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from . import account_statement_import
from . import account_statement_import_adyen_parser
Original file line number Diff line number Diff line change
@@ -1,47 +1,56 @@
# 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
import logging

from odoo import _, models
from odoo.exceptions import UserError

_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):
raise UserError(message) from exc
message = (
_("Statement file %s was not a Adyen settlement details file.")
% self.statement_filename
or "* no filename *"
)
if self.env.context.get("account_statement_import_adyen", False):
raise ValueError(message) from exc
_logger.debug(message, exc_info=True)
return super()._parse_file(data_file)

Check warning on line 31 in account_statement_import_adyen/wizards/account_statement_import.py

View check run for this annotation

Codecov / codecov/patch

account_statement_import_adyen/wizards/account_statement_import.py#L30-L31

Added lines #L30 - L31 were not covered by tests

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)

def _get_rows(self, data_file):
"""Get rows from data_file."""
# Try to use original import file name.
filename = (
self.attachment_ids[0].name
if len(self.attachment_ids) == 1
self.statement_filename
if self.statement_filename
else "Ayden settlement details"
)
import_model = self.env["base_import.import"]
importer = import_model.create({"file": data_file, "file_name": filename})
return importer._read_file({"quoting": '"', "separator": ","})
importer = import_model.create(
{
"file": data_file,
"file_name": filename,
}
)
_num_rows, rows = importer._read_file({"quoting": '"', "separator": ","})
return rows
Loading

0 comments on commit 514284f

Please sign in to comment.