diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index ee4536488a..b911f0891f 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -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 diff --git a/account_statement_clearing_account/tests/test_clearing_account.py b/account_statement_clearing_account/tests/test_clearing_account.py index 2862031442..e6e695dfa5 100644 --- a/account_statement_clearing_account/tests/test_clearing_account.py +++ b/account_statement_clearing_account/tests/test_clearing_account.py @@ -2,40 +2,48 @@ # Copyright 2020 Vanmoof BV # Copyright 2015-2023 Therp BV ) # 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": [ ( @@ -43,9 +51,9 @@ def test_reconcile_unreconcile(self): 0, { "name": "web sale", + "journal_id": self.journal.id, "partner_id": self.partner_customer.id, "amount": 100.00, - "account_id": account.id, }, ), ( @@ -53,9 +61,9 @@ def test_reconcile_unreconcile(self): 0, { "name": "transaction_fees", + "journal_id": self.journal.id, "partner_id": False, "amount": -1.25, - "account_id": account.id, }, ), ( @@ -63,9 +71,9 @@ def test_reconcile_unreconcile(self): 0, { "name": "due_from_provider", + "journal_id": self.journal.id, "partner_id": self.partner_provider.id, "amount": -98.75, - "account_id": account.id, }, ), ], @@ -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 + # ) diff --git a/account_statement_import_adyen/__init__.py b/account_statement_import_adyen/__init__.py index 0650744f6b..237bb9c5b2 100644 --- a/account_statement_import_adyen/__init__.py +++ b/account_statement_import_adyen/__init__.py @@ -1 +1,3 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). from . import models +from . import wizards diff --git a/account_statement_import_adyen/__manifest__.py b/account_statement_import_adyen/__manifest__.py index 9106469468..6a21d2861b 100644 --- a/account_statement_import_adyen/__manifest__.py +++ b/account_statement_import_adyen/__manifest__.py @@ -1,19 +1,22 @@ # Copyright 2017 Opener BV # Copyright 2020 Vanmoof BV -# Copyright 2021 Therp BV . +# Copyright 2021-2023 Therp BV . # 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, } diff --git a/account_statement_import_adyen/models/__init__.py b/account_statement_import_adyen/models/__init__.py index 7ce2f087dc..d12eea5ecd 100644 --- a/account_statement_import_adyen/models/__init__.py +++ b/account_statement_import_adyen/models/__init__.py @@ -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 diff --git a/account_statement_import_adyen/security/ir.model.access.csv b/account_statement_import_adyen/security/ir.model.access.csv new file mode 100644 index 0000000000..d23ca9afd9 --- /dev/null +++ b/account_statement_import_adyen/security/ir.model.access.csv @@ -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 diff --git a/account_statement_import_adyen/tests/test_import_adyen.py b/account_statement_import_adyen/tests/test_import_adyen.py index 032374b04d..4918ad18e2 100644 --- a/account_statement_import_adyen/tests/test_import_adyen.py +++ b/account_statement_import_adyen/tests/test_import_adyen.py @@ -1,16 +1,15 @@ # Copyright 2017 Opener BV # Copyright 2020 Vanmoof BV -# Copyright 2015-2022 Therp BV ) +# Copyright 2015-2023 Therp BV ) # 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 @@ -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, } @@ -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", @@ -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)] diff --git a/account_statement_import_adyen/wizards/__init__.py b/account_statement_import_adyen/wizards/__init__.py new file mode 100644 index 0000000000..13153b3ec9 --- /dev/null +++ b/account_statement_import_adyen/wizards/__init__.py @@ -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 diff --git a/account_statement_import_adyen/models/account_bank_statement_import.py b/account_statement_import_adyen/wizards/account_statement_import.py similarity index 58% rename from account_statement_import_adyen/models/account_bank_statement_import.py rename to account_statement_import_adyen/wizards/account_statement_import.py index 0e232a3379..a61b03b6a6 100644 --- a/account_statement_import_adyen/models/account_bank_statement_import.py +++ b/account_statement_import_adyen/wizards/account_statement_import.py @@ -1,36 +1,39 @@ # Copyright 2017 Opener BV () -# Copyright 2021-2022 Therp BV . +# Copyright 2021-2023 Therp BV . # 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) 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) @@ -38,10 +41,16 @@ 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 diff --git a/account_statement_import_adyen/models/account_bank_statement_import_adyen_parser.py b/account_statement_import_adyen/wizards/account_statement_import_adyen_parser.py similarity index 90% rename from account_statement_import_adyen/models/account_bank_statement_import_adyen_parser.py rename to account_statement_import_adyen/wizards/account_statement_import_adyen_parser.py index a71900a2ab..7810d7cb54 100644 --- a/account_statement_import_adyen/models/account_bank_statement_import_adyen_parser.py +++ b/account_statement_import_adyen/wizards/account_statement_import_adyen_parser.py @@ -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. @@ -60,7 +60,7 @@ def parse_rows(self, rows): balance = 0.0 payout = 0.0 num_rows = self._process_headers(rows) - for row in rows: + for row in rows[num_rows:]: num_rows += 1 if not self._is_transaction_row(row): continue @@ -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"]), ) @@ -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): @@ -238,33 +241,22 @@ def _get_transaction(self, row): This can easily be overwritten in custom modules to add extra information. """ - merchant_account = self._get_value(row, "Merchant Account") + self._get_value(row, "Merchant Account") psp_reference = self._get_value(row, "Psp Reference") merchant_reference = self._get_value(row, "Merchant Reference") - payment_method = self._get_value(row, "Payment Method Variant") + self._get_value(row, "Payment Method Variant") modification_reference = self._get_value(row, "Modification Reference") transaction = { "date": self._get_transaction_date(row), "amount": self._balance(row), + "raw_data": str(row), } - transaction["note"] = " ".join( - [ - part - for part in [ - merchant_account, - psp_reference, - merchant_reference, - payment_method, - ] - if part - ] - ) - transaction["name"] = ( - merchant_reference or psp_reference or modification_reference - ) transaction["ref"] = ( psp_reference or modification_reference or merchant_reference ) + transaction["payment_ref"] = ( + merchant_reference or modification_reference or psp_reference or "unknown" + ) transaction["transaction_type"] = self._get_value(row, "Type") return transaction @@ -274,7 +266,7 @@ def _append_fees_transaction(self, statement, fees, batch_number): transaction = { "date": max_date, "amount": -fees, - "name": "Commission, markup etc. batch %s" % batch_number, + "payment_ref": "Commission, markup etc. batch %s" % batch_number, } self._append_transaction(statement, transaction) diff --git a/account_statement_import_camt/models/account_statement_import.py b/account_statement_import_camt/models/account_statement_import.py index bbb40208c2..712687b378 100644 --- a/account_statement_import_camt/models/account_statement_import.py +++ b/account_statement_import_camt/models/account_statement_import.py @@ -25,7 +25,7 @@ def _parse_file(self, data_file): account_number = None transactions = [] for member in data.namelist(): - currency, account_number, new = self._parse_file( + currency, account_number, new = parser.parse( data.open(member).read() ) transactions.extend(new) diff --git a/account_statement_import_online/models/account_journal.py b/account_statement_import_online/models/account_journal.py index 472c72a388..d8dc248160 100644 --- a/account_statement_import_online/models/account_journal.py +++ b/account_statement_import_online/models/account_journal.py @@ -15,9 +15,7 @@ class AccountJournal(models.Model): @api.model def _selection_service(self): OnlineBankStatementProvider = self.env["online.bank.statement.provider"] - return OnlineBankStatementProvider._get_available_services() + [ - ("dummy", "Dummy") - ] + return OnlineBankStatementProvider._selection_service() # Keep provider fields for compatibility with other modules. online_bank_statement_provider = fields.Selection( diff --git a/account_statement_import_online_adyen/__manifest__.py b/account_statement_import_online_adyen/__manifest__.py index 52ae345b64..4408874ff6 100644 --- a/account_statement_import_online_adyen/__manifest__.py +++ b/account_statement_import_online_adyen/__manifest__.py @@ -1,16 +1,16 @@ -# Copyright 2021 - Therp BV . +# Copyright 2021-2023 - Therp BV . # 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"], } diff --git a/account_statement_import_online_adyen/models/__init__.py b/account_statement_import_online_adyen/models/__init__.py index 56bd827cc6..03e38c9993 100644 --- a/account_statement_import_online_adyen/models/__init__.py +++ b/account_statement_import_online_adyen/models/__init__.py @@ -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 diff --git a/account_statement_import_online_adyen/models/account_journal.py b/account_statement_import_online_adyen/models/account_journal.py deleted file mode 100644 index fb7572a39f..0000000000 --- a/account_statement_import_online_adyen/models/account_journal.py +++ /dev/null @@ -1,30 +0,0 @@ -# Copyright 2021 Therp BV . -# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). -from odoo import api, models - - -class AccountJournal(models.Model): - _inherit = "account.journal" - - def write(self, vals): - """Do not reset a provider to file_import, if that will delete provider.""" - # TODO: In the future place this in super account_bank_statement_import_online. - for this in self: - is_online = this.bank_statements_source == "online" - if is_online and vals.get("bank_statements_source", "online") != "online": - vals.pop("bank_statements_source") - super(AccountJournal, this).write(vals) - return True - - @api.model - def _selection_online_bank_statement_provider(self): - res = super()._selection_online_bank_statement_provider() - res.append(("dummy_adyen", "Dummy Adyen")) - return res - - @api.model - def values_online_bank_statement_provider(self): - res = super().values_online_bank_statement_provider() - if self.user_has_groups("base.group_no_one"): - res += [("dummy_adyen", "Dummy Adyen")] - return res diff --git a/account_statement_import_online_adyen/models/online_bank_statement_provider.py b/account_statement_import_online_adyen/models/online_bank_statement_provider.py index 0ae58f9281..15ba2189e5 100644 --- a/account_statement_import_online_adyen/models/online_bank_statement_provider.py +++ b/account_statement_import_online_adyen/models/online_bank_statement_provider.py @@ -1,7 +1,6 @@ # Copyright 2021 Therp BV . # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). # pylint: disable=missing-docstring,invalid-name,protected-access -import base64 import logging from html import escape @@ -9,6 +8,7 @@ from odoo import _, api, fields, models from odoo.exceptions import UserError +from odoo.modules.module import get_module_resource _logger = logging.getLogger(__name__) @@ -31,12 +31,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: @@ -63,32 +64,35 @@ 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}) - .create({"attachment_ids": [(0, 0, attachment_vals)]}) + if self.service == "dummy_adyen": + data_file, file_name = self._adyen_dummy_get_settlement_details_file() + else: + data_file, file_name = self._adyen_get_settlement_details_file() + wizard_model = self.env["account.statement.import"] + wizard = wizard_model.create( + { + "statement_filename": file_name, # Only need the name in the wizard + } ) - 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() - encoded_content = base64.encodebytes(content) - # Make sure base64 encoded content contains multiple of 4 bytes. - byte_count = len(encoded_content) - byte_padding = b"=" * (byte_count % 4) - data_file = encoded_content + byte_padding - attachment_vals = {"name": filename, "datas": data_file} - return content, attachment_vals + currency_code, account_number, stmts_vals = wizard._parse_adyen_file(data_file) + success = wizard._check_parsed_data(stmts_vals) + if not success: + _logger.debug("Parser did not return valid statement data", stmts_vals) + else: + # Result is used in file import to collect result of several statements. + result = { + "statement_ids": [], + "notifications": [], # list of text messages + } + stmts_vals = wizard._complete_stmts_vals( + stmts_vals, self.journal_id, account_number + ) + wizard._create_bank_statements(stmts_vals, result) def _adyen_get_settlement_details_file(self): """Retrieve daily generated settlement details file. @@ -108,17 +112,31 @@ def _adyen_get_settlement_details_file(self): ) 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 diff --git a/account_statement_import_online_adyen/tests/online_bank_statement_provider_dummy.py b/account_statement_import_online_adyen/tests/online_bank_statement_provider_dummy.py deleted file mode 100644 index 9b028cb4d6..0000000000 --- a/account_statement_import_online_adyen/tests/online_bank_statement_provider_dummy.py +++ /dev/null @@ -1,24 +0,0 @@ -# Copyright 2021-2022 Therp BV . -# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). -"""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): - """Get file from disk, instead of from url.""" - if self.service != "dummy_adyen": - # Not a dummy, get the regular adyen method. - return super()._adyen_get_settlement_details_file() - 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 diff --git a/account_statement_import_online_adyen/tests/test_import_online.py b/account_statement_import_online_adyen/tests/test_import_online.py index 1579af18e1..b476a52e0a 100644 --- a/account_statement_import_online_adyen/tests/test_import_online.py +++ b/account_statement_import_online_adyen/tests/test_import_online.py @@ -6,7 +6,7 @@ from odoo import fields # pylint: disable=import-error -from odoo.addons.account_bank_statement_import_adyen.tests.test_import_adyen import ( +from odoo.addons.account_statement_import_adyen.tests.test_import_adyen import ( TestImportAdyen, ) @@ -60,7 +60,6 @@ def _test_statement_import(self, file_name, statement_name): 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( [("name", "=", statement_name)] ) diff --git a/account_statement_import_online_adyen/views/online_bank_statement_provider.xml b/account_statement_import_online_adyen/views/online_bank_statement_provider.xml index 294c776904..3c3bca2eb6 100644 --- a/account_statement_import_online_adyen/views/online_bank_statement_provider.xml +++ b/account_statement_import_online_adyen/views/online_bank_statement_provider.xml @@ -5,10 +5,10 @@ online.bank.statement.provider - +