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_import_adyen/__manifest__.py b/account_statement_import_adyen/__manifest__.py index 9106469468..3ab94e4862 100644 --- a/account_statement_import_adyen/__manifest__.py +++ b/account_statement_import_adyen/__manifest__.py @@ -1,18 +1,18 @@ # 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": ["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..1004bfabea 100644 --- a/account_statement_import_adyen/models/__init__.py +++ b/account_statement_import_adyen/models/__init__.py @@ -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 diff --git a/account_statement_import_adyen/models/account_bank_statement_import.py b/account_statement_import_adyen/models/account_statement_import.py similarity index 83% rename from account_statement_import_adyen/models/account_bank_statement_import.py rename to account_statement_import_adyen/models/account_statement_import.py index 0e232a3379..9505cb9a1c 100644 --- a/account_statement_import_adyen/models/account_bank_statement_import.py +++ b/account_statement_import_adyen/models/account_statement_import.py @@ -1,5 +1,5 @@ # 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 @@ -11,10 +11,10 @@ _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.""" @@ -22,7 +22,7 @@ def _parse_file(self, data_file): 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) @@ -30,7 +30,7 @@ def _parse_file(self, 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) diff --git a/account_statement_import_adyen/models/account_bank_statement_import_adyen_parser.py b/account_statement_import_adyen/models/account_statement_import_adyen_parser.py similarity index 95% rename from account_statement_import_adyen/models/account_bank_statement_import_adyen_parser.py rename to account_statement_import_adyen/models/account_statement_import_adyen_parser.py index a71900a2ab..da8159423f 100644 --- a/account_statement_import_adyen/models/account_bank_statement_import_adyen_parser.py +++ b/account_statement_import_adyen/models/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. @@ -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): diff --git a/account_statement_import_adyen/tests/test_import_adyen.py b/account_statement_import_adyen/tests/test_import_adyen.py index 032374b04d..f65b8e3752 100644 --- a/account_statement_import_adyen/tests/test_import_adyen.py +++ b/account_statement_import_adyen/tests/test_import_adyen.py @@ -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( 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..ddce09b8e0 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 @@ -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__) @@ -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: @@ -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) @@ -101,6 +104,9 @@ 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( @@ -108,17 +114,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