From 302e0d895545561f697b3f75a4475e532ecb2620 Mon Sep 17 00:00:00 2001 From: Ronald Portier Date: Wed, 17 Feb 2021 16:55:26 +0100 Subject: [PATCH] [MIG] account_bank_statement_import_adyen Migrate to 13.0 --- .../readme/CREDITS.rst | 0 .../readme/HISTORY.rst | 0 .../readme/INSTALL.rst | 0 .../readme/ROADMAP.rst | 0 .../tests/__init__.py | 1 + .../tests/test_clearing_account.py | 120 +++++ .../README.rst | 110 ++++- .../__manifest__.py | 13 +- .../models/account_bank_statement_import.py | 119 +++-- .../models/account_journal.py | 10 +- .../readme/CONFIGURE.rst | 6 +- .../readme/CONTRIBUTORS.rst | 1 + .../readme/CREDITS.rst | 0 .../readme/DESCRIPTION.rst | 8 +- .../readme/HISTORY.rst | 0 .../readme/INSTALL.rst | 0 .../readme/ROADMAP.rst | 0 .../static/description/index.html | 442 ++++++++++++++++++ .../tests/test_import_adyen.py | 92 +--- 19 files changed, 747 insertions(+), 175 deletions(-) delete mode 100644 account_bank_statement_clearing_account/readme/CREDITS.rst delete mode 100644 account_bank_statement_clearing_account/readme/HISTORY.rst delete mode 100644 account_bank_statement_clearing_account/readme/INSTALL.rst delete mode 100644 account_bank_statement_clearing_account/readme/ROADMAP.rst create mode 100644 account_bank_statement_clearing_account/tests/__init__.py create mode 100644 account_bank_statement_clearing_account/tests/test_clearing_account.py delete mode 100644 account_bank_statement_import_adyen/readme/CREDITS.rst delete mode 100644 account_bank_statement_import_adyen/readme/HISTORY.rst delete mode 100644 account_bank_statement_import_adyen/readme/INSTALL.rst delete mode 100644 account_bank_statement_import_adyen/readme/ROADMAP.rst create mode 100644 account_bank_statement_import_adyen/static/description/index.html diff --git a/account_bank_statement_clearing_account/readme/CREDITS.rst b/account_bank_statement_clearing_account/readme/CREDITS.rst deleted file mode 100644 index e69de29b..00000000 diff --git a/account_bank_statement_clearing_account/readme/HISTORY.rst b/account_bank_statement_clearing_account/readme/HISTORY.rst deleted file mode 100644 index e69de29b..00000000 diff --git a/account_bank_statement_clearing_account/readme/INSTALL.rst b/account_bank_statement_clearing_account/readme/INSTALL.rst deleted file mode 100644 index e69de29b..00000000 diff --git a/account_bank_statement_clearing_account/readme/ROADMAP.rst b/account_bank_statement_clearing_account/readme/ROADMAP.rst deleted file mode 100644 index e69de29b..00000000 diff --git a/account_bank_statement_clearing_account/tests/__init__.py b/account_bank_statement_clearing_account/tests/__init__.py new file mode 100644 index 00000000..3e17ae02 --- /dev/null +++ b/account_bank_statement_clearing_account/tests/__init__.py @@ -0,0 +1 @@ +from . import test_clearing_account diff --git a/account_bank_statement_clearing_account/tests/test_clearing_account.py b/account_bank_statement_clearing_account/tests/test_clearing_account.py new file mode 100644 index 00000000..e698da0a --- /dev/null +++ b/account_bank_statement_clearing_account/tests/test_clearing_account.py @@ -0,0 +1,120 @@ +# Copyright 2017 Opener BV +# Copyright 2020 Vanmoof BV +# Copyright 2015-2021 Therp BV ) +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). +from odoo.tests.common import SavepointCase + + +class TestClearingAccount(SavepointCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.journal = cls.env["account.journal"].create( + { + "company_id": cls.env.user.company_id.id, + "name": "Clearing account test", + "code": "CAT", + "type": "bank", + "currency_id": cls.env.ref("base.USD").id, + } + ) + cls.partner_customer = cls.env["res.partner"].create({"name": "cutomer"}) + 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. + """ + account = self.journal.default_debit_account_id + 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", + "partner_id": self.partner_customer.id, + "amount": 100.00, + "account_id": account.id, + }, + ), + ( + 0, + 0, + { + "name": "transaction_fees", + "partner_id": False, + "amount": -1.25, + "account_id": account.id, + }, + ), + ( + 0, + 0, + { + "name": "due_from_provider", + "partner_id": self.partner_provider.id, + "amount": -98.75, + "account_id": account.id, + }, + ), + ], + } + ) + self.assertEqual(statement.journal_id, self.journal) + self.assertEqual(len(statement.line_ids), 3) + self.assertTrue( + self.env.user.company_id.currency_id.is_zero( + 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")) diff --git a/account_bank_statement_import_adyen/README.rst b/account_bank_statement_import_adyen/README.rst index 38929e87..5a8d54c1 100644 --- a/account_bank_statement_import_adyen/README.rst +++ b/account_bank_statement_import_adyen/README.rst @@ -1,35 +1,97 @@ -**This file is going to be generated by oca-gen-addon-readme.** +====================== +Adyen statement import +====================== -*Manual changes will be overwritten.* +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -Please provide content in the ``readme`` directory: +.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png + :target: https://odoo-community.org/page/development-status + :alt: Beta +.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fbank--statement--import-lightgray.png?logo=github + :target: https://github.com/OCA/bank-statement-import/tree/13.0/account_bank_statement_import_adyen + :alt: OCA/bank-statement-import +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/bank-statement-import-13-0/bank-statement-import-13-0-account_bank_statement_import_adyen + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png + :target: https://runbot.odoo-community.org/runbot/174/13.0 + :alt: Try me on Runbot -* **DESCRIPTION.rst** (required) -* INSTALL.rst (optional) -* CONFIGURE.rst (optional) -* **USAGE.rst** (optional, highly recommended) -* DEVELOP.rst (optional) -* ROADMAP.rst (optional) -* HISTORY.rst (optional, recommended) -* **CONTRIBUTORS.rst** (optional, highly recommended) -* CREDITS.rst (optional) +|badge1| |badge2| |badge3| |badge4| |badge5| -Content of this README will also be drawn from the addon manifest, -from keys such as name, authors, maintainers, development_status, -and license. +This module processes Adyen transaction statements, the settlement details report, +in excel or csv format. -A good, one sentence summary in the manifest is also highly recommended. +You can import the statements in a dedicated journal. Reconcile your sale invoices +with the credit transations. Reconcile the aggregated counterpart +transaction with the transaction in your real bank journal and register the +aggregated fee line containing commision and markup on the applicable +cost account. +**Table of contents** -Automatic changelog generation -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +.. contents:: + :local: -`HISTORY.rst` can be auto generated using `towncrier `_. +Configuration +============= -Just put towncrier compatible changelog fragments into `readme/newsfragments` -and the changelog file will be automatically generated and updated when a new fragment is added. +Configure a pseudo bank journal by creating a new journal linked to your Adyen +merchant account. Set your merchant account string in the Advanced settings +on the journal form. -Please refer to `towncrier` documentation to know more. +Usage +===== -NOTE: the changelog will be automatically generated when using `/ocabot merge $option`. -If you need to run it manually, refer to `OCA/maintainer-tools README `_. +After installing this module, you can import your Adyen transaction statements +through Menu Finance -> Bank -> Import. Don't enter a journal in the import +wizard. + +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues `_. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us smashing it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +~~~~~~~ + +* Opener BV +* Vanmoof BV + +Contributors +~~~~~~~~~~~~ + +* Stefan Rijnhart (https://opener.amsterdam) +* Martin Pishpecki (https://www.vanmoof.com) +* Ronald Portier (https://therp.nl) + +Maintainers +~~~~~~~~~~~ + +This module is maintained by the OCA. + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use. + +This module is part of the `OCA/bank-statement-import `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/account_bank_statement_import_adyen/__manifest__.py b/account_bank_statement_import_adyen/__manifest__.py index de271032..bc24a336 100644 --- a/account_bank_statement_import_adyen/__manifest__.py +++ b/account_bank_statement_import_adyen/__manifest__.py @@ -1,18 +1,19 @@ -# © 2017 Opener BV () -# © 2020 Vanmoof BV () -# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +# Copyright 2017 Opener BV +# Copyright 2020 Vanmoof BV +# Copyright 2021 Therp BV . +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). { "name": "Adyen statement import", - "version": "12.0.1.0.0", + "version": "13.0.1.0.0", "author": "Opener BV, Vanmoof 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", ], - "external_dependencies": {"python": ["openpyxl",],}, - "data": ["views/account_journal.xml",], + "data": ["views/account_journal.xml"], "installable": True, } diff --git a/account_bank_statement_import_adyen/models/account_bank_statement_import.py b/account_bank_statement_import_adyen/models/account_bank_statement_import.py index 45e062de..0ba9b7ba 100644 --- a/account_bank_statement_import_adyen/models/account_bank_statement_import.py +++ b/account_bank_statement_import_adyen/models/account_bank_statement_import.py @@ -1,13 +1,12 @@ -# © 2017 Opener BV () -# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -from io import BytesIO -from zipfile import BadZipfile +# Copyright 2017 Opener BV () +# Copyright 2021 Therp BV . +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). +import logging -from openpyxl import load_workbook - -from odoo import api, fields, models +from odoo import _, api, fields, models from odoo.exceptions import UserError -from odoo.tools.translate import _ + +_logger = logging.getLogger(__name__) class AccountBankStatementImport(models.TransientModel): @@ -15,15 +14,14 @@ class AccountBankStatementImport(models.TransientModel): @api.model def _parse_file(self, data_file): - """Parse an Adyen xlsx file and map merchant account strings - to journals. """ + """Parse an Adyen xlsx file and map merchant account strings to journals.""" try: return self.import_adyen_xlsx(data_file) except ValueError: - return super(AccountBankStatementImport, self)._parse_file(data_file) + return super()._parse_file(data_file) def _find_additional_data(self, currency_code, account_number): - """ Try to find journal by Adyen merchant account """ + """Try to find journal by Adyen merchant account.""" if account_number: journal = self.env["account.journal"].search( [("adyen_merchant_account", "=", account_number)], limit=1 @@ -39,14 +37,12 @@ class AccountBankStatementImport(models.TransientModel): % account_number ) self = self.with_context(journal_id=journal.id) - return super(AccountBankStatementImport, self)._find_additional_data( - currency_code, account_number - ) + return super()._find_additional_data(currency_code, account_number) @api.model def balance(self, row): - return -(row[15] or 0) + sum( - row[i] if row[i] else 0.0 for i in (16, 17, 18, 19, 20) + return -(float(row[15]) if row[15] else 0.0) + sum( + float(row[i]) if row[i] else 0.0 for i in (16, 17, 18, 19, 20) ) @api.model @@ -62,7 +58,7 @@ class AccountBankStatementImport(models.TransientModel): statement["transactions"].append(transaction) @api.model - def import_adyen_xlsx(self, data_file): + def parse_adyen_file(self, data_file): statements = [] statement = None headers = False @@ -71,52 +67,49 @@ class AccountBankStatementImport(models.TransientModel): payout = 0.0 statement_id = None - with BytesIO() as buf: - buf.write(data_file) - try: - sheet = load_workbook(buf)._sheets[0] - except BadZipfile as e: - raise ValueError(e) - for row in sheet.rows: - row = [cell.value for cell in row] - if len(row) != 31: - raise ValueError( - "Not an Adyen statement. Unexpected row length %s " - "instead of 31" % len(row) - ) - if not row[1]: - continue - if not headers: - if row[1] != "Company Account": - raise ValueError( - 'Not an Adyen statement. Unexpected header "%s" ' - 'instead of "Company Account"', - row[1], - ) - headers = True - continue - if not statement: - statement = {"transactions": []} - statements.append(statement) - statement_id = "{} {}/{}".format( - row[2], - row[6].strftime("%Y"), - int(row[23]), - ) - currency_code = row[14] - merchant_id = row[2] - statement["name"] = "{} {}/{}".format(row[2], row[6].year, row[23]) - date = fields.Date.from_string(row[6]) - if not statement.get("date") or statement.get("date") > date: - statement["date"] = date + import_model = self.env["base_import.import"] + importer = import_model.create( + {"file": data_file, "file_name": "Ayden settlemnt details"} + ) + rows = importer._read_file({}) - row[8] = row[8].strip() - if row[8] == "MerchantPayout": - payout -= self.balance(row) - else: - balance += self.balance(row) - self.import_adyen_transaction(statement, statement_id, row) - fees += sum(row[i] if row[i] else 0.0 for i in (17, 18, 19, 20)) + for row in rows: + if len(row) != 31: + raise ValueError( + "Not an Adyen statement. Unexpected row length %s " + "instead of 31" % len(row) + ) + if not row[1]: + continue + if not headers: + if row[1] != "Company Account": + raise ValueError( + 'Not an Adyen statement. Unexpected header "%s" ' + 'instead of "Company Account"', + row[1], + ) + headers = True + continue + if not statement: + statement = {"transactions": []} + statements.append(statement) + statement_id = "{merchant} {year}/{batch}".format( + merchant=row[2], year=row[6][:4], batch=row[23], + ) + currency_code = row[14] + merchant_id = row[2] + statement["name"] = statement_id + date = fields.Date.from_string(row[6]) + if not statement.get("date") or statement.get("date") > date: + statement["date"] = date + + row[8] = row[8].strip() + if row[8] == "MerchantPayout": + payout -= self.balance(row) + else: + balance += self.balance(row) + self.import_adyen_transaction(statement, statement_id, row) + fees += sum(float(row[i]) if row[i] else 0.0 for i in (17, 18, 19, 20)) if not headers: raise ValueError("Not an Adyen statement. Did not encounter header row.") diff --git a/account_bank_statement_import_adyen/models/account_journal.py b/account_bank_statement_import_adyen/models/account_journal.py index 32c213dd..605fc528 100644 --- a/account_bank_statement_import_adyen/models/account_journal.py +++ b/account_bank_statement_import_adyen/models/account_journal.py @@ -1,10 +1,10 @@ -# © 2017 Opener BV () -# © 2020 Vanmoof BV () -# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +# Copyright 2017 Opener BV () +# Copyright 2020 Vanmoof BV () +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). from odoo import fields, models -class Journal(models.Model): +class AccountJournal(models.Model): _inherit = "account.journal" adyen_merchant_account = fields.Char( @@ -15,6 +15,6 @@ class Journal(models.Model): ) def _get_bank_statements_available_import_formats(self): - res = super(Journal, self)._get_bank_statements_available_import_formats() + res = super()._get_bank_statements_available_import_formats() res.append("adyen") return res diff --git a/account_bank_statement_import_adyen/readme/CONFIGURE.rst b/account_bank_statement_import_adyen/readme/CONFIGURE.rst index 7df8a95e..0f7870bd 100644 --- a/account_bank_statement_import_adyen/readme/CONFIGURE.rst +++ b/account_bank_statement_import_adyen/readme/CONFIGURE.rst @@ -1,3 +1,3 @@ -Configure a pseudo bank journal by creating a new journal with a dedicated -Adyen clearing account as the default ledger account. Set your merchant -account string in the Advanced settings on the journal form. +Configure a pseudo bank journal by creating a new journal linked to your Adyen +merchant account. Set your merchant account string in the Advanced settings +on the journal form. diff --git a/account_bank_statement_import_adyen/readme/CONTRIBUTORS.rst b/account_bank_statement_import_adyen/readme/CONTRIBUTORS.rst index 58e9f494..f00439e5 100644 --- a/account_bank_statement_import_adyen/readme/CONTRIBUTORS.rst +++ b/account_bank_statement_import_adyen/readme/CONTRIBUTORS.rst @@ -1,2 +1,3 @@ * Stefan Rijnhart (https://opener.amsterdam) * Martin Pishpecki (https://www.vanmoof.com) +* Ronald Portier (https://therp.nl) diff --git a/account_bank_statement_import_adyen/readme/CREDITS.rst b/account_bank_statement_import_adyen/readme/CREDITS.rst deleted file mode 100644 index e69de29b..00000000 diff --git a/account_bank_statement_import_adyen/readme/DESCRIPTION.rst b/account_bank_statement_import_adyen/readme/DESCRIPTION.rst index c0832e16..c07218ef 100644 --- a/account_bank_statement_import_adyen/readme/DESCRIPTION.rst +++ b/account_bank_statement_import_adyen/readme/DESCRIPTION.rst @@ -1,9 +1,7 @@ -====================== -Adyen statement import -====================== +This module processes Adyen transaction statements, the settlement details report, +in excel or csv format. -This module processes Adyen transaction statements in xlsx format. You can -import the statements in a dedicated journal. Reconcile your sale invoices +You can import the statements in a dedicated journal. Reconcile your sale invoices with the credit transations. Reconcile the aggregated counterpart transaction with the transaction in your real bank journal and register the aggregated fee line containing commision and markup on the applicable diff --git a/account_bank_statement_import_adyen/readme/HISTORY.rst b/account_bank_statement_import_adyen/readme/HISTORY.rst deleted file mode 100644 index e69de29b..00000000 diff --git a/account_bank_statement_import_adyen/readme/INSTALL.rst b/account_bank_statement_import_adyen/readme/INSTALL.rst deleted file mode 100644 index e69de29b..00000000 diff --git a/account_bank_statement_import_adyen/readme/ROADMAP.rst b/account_bank_statement_import_adyen/readme/ROADMAP.rst deleted file mode 100644 index e69de29b..00000000 diff --git a/account_bank_statement_import_adyen/static/description/index.html b/account_bank_statement_import_adyen/static/description/index.html new file mode 100644 index 00000000..7d826df9 --- /dev/null +++ b/account_bank_statement_import_adyen/static/description/index.html @@ -0,0 +1,442 @@ + + + + + + +Adyen statement import + + + +
+

Adyen statement import

+ + +

Beta License: AGPL-3 OCA/bank-statement-import Translate me on Weblate Try me on Runbot

+

This module processes Adyen transaction statements, the settlement details report, +in excel or csv format.

+

You can import the statements in a dedicated journal. Reconcile your sale invoices +with the credit transations. Reconcile the aggregated counterpart +transaction with the transaction in your real bank journal and register the +aggregated fee line containing commision and markup on the applicable +cost account.

+

Table of contents

+ +
+

Configuration

+

Configure a pseudo bank journal by creating a new journal linked to your Adyen +merchant account. Set your merchant account string in the Advanced settings +on the journal form.

+
+
+

Usage

+

After installing this module, you can import your Adyen transaction statements +through Menu Finance -> Bank -> Import. Don’t enter a journal in the import +wizard.

+
+
+

Bug Tracker

+

Bugs are tracked on GitHub Issues. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us smashing it by providing a detailed and welcomed +feedback.

+

Do not contact contributors directly about support or help with technical issues.

+
+
+

Credits

+
+

Authors

+
    +
  • Opener BV
  • +
  • Vanmoof BV
  • +
+
+ +
+

Maintainers

+

This module is maintained by the OCA.

+Odoo Community Association +

OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use.

+

This module is part of the OCA/bank-statement-import project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+ + diff --git a/account_bank_statement_import_adyen/tests/test_import_adyen.py b/account_bank_statement_import_adyen/tests/test_import_adyen.py index 10e61e92..1fc5418f 100644 --- a/account_bank_statement_import_adyen/tests/test_import_adyen.py +++ b/account_bank_statement_import_adyen/tests/test_import_adyen.py @@ -1,7 +1,7 @@ -# © 2017 Opener BV () -# © 2020 Vanmoof BV () -# © 2015 Therp BV () -# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +# Copyright 2017 Opener BV +# Copyright 2020 Vanmoof BV +# Copyright 2015-2021 Therp BV ) +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). import base64 from odoo.exceptions import UserError @@ -12,7 +12,7 @@ from odoo.tests.common import SavepointCase class TestImportAdyen(SavepointCase): @classmethod def setUpClass(cls): - super(TestImportAdyen, cls).setUpClass() + super().setUpClass() cls.journal = cls.env["account.journal"].create( { "company_id": cls.env.user.company_id.id, @@ -20,7 +20,6 @@ class TestImportAdyen(SavepointCase): "code": "ADY", "type": "bank", "adyen_merchant_account": "YOURCOMPANY_ACCOUNT", - "update_posted": True, "currency_id": cls.env.ref("base.USD").id, } ) @@ -33,9 +32,7 @@ class TestImportAdyen(SavepointCase): lines on the default journal (clearing) account are fully reconciled with each other """ self._test_statement_import( - "account_bank_statement_import_adyen", - "adyen_test.xlsx", - "YOURCOMPANY_ACCOUNT 2016/48", + "adyen_test.xlsx", "YOURCOMPANY_ACCOUNT 2016/48", ) statement = self.env["account.bank.statement"].search( [], order="create_date desc", limit=1 @@ -48,76 +45,33 @@ class TestImportAdyen(SavepointCase): ) ) - 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_draft() - 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")) - def test_02_import_adyen_credit_fees(self): """ Import an Adyen statement with credit fees """ self._test_statement_import( - "account_bank_statement_import_adyen", - "adyen_test_credit_fees.xlsx", - "YOURCOMPANY_ACCOUNT 2016/8", + "adyen_test_credit_fees.xlsx", "YOURCOMPANY_ACCOUNT 2016/8", ) def test_03_import_adyen_invalid(self): """ Trying to hit that coverall target """ with self.assertRaisesRegex(UserError, "Could not make sense"): self._test_statement_import( - "account_bank_statement_import_adyen", - "adyen_test_invalid.xls", - "invalid", + "adyen_test_invalid.xls", "invalid", ) - def _test_statement_import(self, module_name, file_name, statement_name): + def _test_statement_import(self, file_name, statement_name): """Test correct creation of single statement.""" - statement_path = get_module_resource(module_name, "test_files", file_name) - statement_file = open(statement_path, "rb").read() - import_wizard = self.env["account.bank.statement.import"].create( - {"data_file": base64.b64encode(statement_file), "filename": file_name} + testfile = get_module_resource( + "account_bank_statement_import_adyen", "test_files", file_name ) - import_wizard.import_file() - # statement name is account number + '-' + date of last line: - statements = self.env["account.bank.statement"].search( - [("name", "=", statement_name)] - ) - self.assertTrue(statements) - return statements + 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": "test file", "datas": data_file})]} + ) + import_wizard.import_file() + # statement name is account number + '-' + date of last line: + statements = self.env["account.bank.statement"].search( + [("name", "=", statement_name)] + ) + self.assertTrue(statements) + return statements