From b635b3be65f6b8ff2eefe7e0ae20d9d33bc589fd Mon Sep 17 00:00:00 2001 From: "Pedro M. Baeza" Date: Tue, 30 Jan 2024 11:33:00 +0100 Subject: [PATCH 1/7] [IMP] account_statement_import_online: Add debug wizard It's useful to debug RAW data received from your online sources. With this improvement, you can do it easily from the manual pull wizard. It's only available for users in debug mode (or with technical features). TT47238 --- account_statement_import_online/README.rst | 2 +- .../__manifest__.py | 1 + .../models/online_bank_statement_provider.py | 13 ++++++--- .../security/ir.model.access.csv | 1 + .../static/description/index.html | 2 +- .../wizards/__init__.py | 1 + .../online_bank_statement_pull_debug.py | 11 ++++++++ .../online_bank_statement_pull_debug.xml | 24 +++++++++++++++++ .../online_bank_statement_pull_wizard.py | 27 +++++++++++++++++-- .../online_bank_statement_pull_wizard.xml | 6 +++++ 10 files changed, 81 insertions(+), 7 deletions(-) create mode 100644 account_statement_import_online/wizards/online_bank_statement_pull_debug.py create mode 100644 account_statement_import_online/wizards/online_bank_statement_pull_debug.xml diff --git a/account_statement_import_online/README.rst b/account_statement_import_online/README.rst index aa2b19ac5..9788e9c6e 100644 --- a/account_statement_import_online/README.rst +++ b/account_statement_import_online/README.rst @@ -7,7 +7,7 @@ Online Bank Statements !! This file is generated by oca-gen-addon-readme !! !! changes will be overwritten. !! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - !! source digest: sha256:5f8fb744f2638751d3401c3c729502aa387c024bbf66769c89302067a5c7bf28 + !! source digest: sha256:8fcd953e1f7dbcc59cc99c790825bef09e423b32ca67b7ac5714e12b1ced7b5c !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! .. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png diff --git a/account_statement_import_online/__manifest__.py b/account_statement_import_online/__manifest__.py index 4f2c612c1..a982f8c82 100644 --- a/account_statement_import_online/__manifest__.py +++ b/account_statement_import_online/__manifest__.py @@ -19,6 +19,7 @@ "data/account_statement_import_online.xml", "security/ir.model.access.csv", "security/online_bank_statement_provider.xml", + "wizards/online_bank_statement_pull_debug.xml", "wizards/online_bank_statement_pull_wizard.xml", "views/actions.xml", "views/account_journal.xml", diff --git a/account_statement_import_online/models/online_bank_statement_provider.py b/account_statement_import_online/models/online_bank_statement_provider.py index a6e83d3cb..cb9081a3b 100644 --- a/account_statement_import_online/models/online_bank_statement_provider.py +++ b/account_statement_import_online/models/online_bank_statement_provider.py @@ -1,6 +1,7 @@ # Copyright 2019-2020 Brainbean Apps (https://brainbeanapps.com) # Copyright 2019-2020 Dataplug (https://dataplug.io) # Copyright 2022-2023 Therp BV (https://therp.nl) +# Copyright 2014 Tecnativa - Pedro M. Baeza # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). import logging @@ -185,6 +186,8 @@ def _compute_update_schedule(self): def _pull(self, date_since, date_until): """Pull data for all providers within requested period.""" is_scheduled = self.env.context.get("scheduled") + debug = self.env.context.get("account_statement_online_import_debug") + debug_data = [] for provider in self: statement_date_since = provider._get_statement_date_since(date_since) while statement_date_since < date_until: @@ -205,12 +208,16 @@ def _pull(self, date_since, date_until): exception, statement_date_since, statement_date_until ) break # Continue with next provider. - provider._create_or_update_statement( - data, statement_date_since, statement_date_until - ) + if debug: + debug_data += data + else: + provider._create_or_update_statement( + data, statement_date_since, statement_date_until + ) statement_date_since = statement_date_until if is_scheduled: provider._schedule_next_run() + return debug_data def _log_provider_exception( self, exception, statement_date_since, statement_date_until diff --git a/account_statement_import_online/security/ir.model.access.csv b/account_statement_import_online/security/ir.model.access.csv index d0856372e..22a9f544f 100644 --- a/account_statement_import_online/security/ir.model.access.csv +++ b/account_statement_import_online/security/ir.model.access.csv @@ -1,4 +1,5 @@ id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink access_online_bank_statement_provider_admin,online.bank.statement.provider:base.group_system,model_online_bank_statement_provider,base.group_system,1,1,1,1 access_online_bank_statement_provider_user,online.bank.statement.provider:account.group_account_user,model_online_bank_statement_provider,account.group_account_user,1,1,1,1 +access_online_bank_statement_pull_debug_user,online.bank.statement.pull.debug:account.group_account_user,model_online_bank_statement_pull_debug,account.group_account_user,1,1,1,1 access_online_bank_statement_pull_wizard_user,online.bank.statement.pull.wizard:account.group_account_user,model_online_bank_statement_pull_wizard,account.group_account_user,1,1,1,1 diff --git a/account_statement_import_online/static/description/index.html b/account_statement_import_online/static/description/index.html index 7f0fc6678..a390ff5ec 100644 --- a/account_statement_import_online/static/description/index.html +++ b/account_statement_import_online/static/description/index.html @@ -367,7 +367,7 @@

Online Bank Statements

!! This file is generated by oca-gen-addon-readme !! !! changes will be overwritten. !! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -!! source digest: sha256:5f8fb744f2638751d3401c3c729502aa387c024bbf66769c89302067a5c7bf28 +!! source digest: sha256:8fcd953e1f7dbcc59cc99c790825bef09e423b32ca67b7ac5714e12b1ced7b5c !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->

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

This module provides base for building online bank statements providers.

diff --git a/account_statement_import_online/wizards/__init__.py b/account_statement_import_online/wizards/__init__.py index a8ac66266..f7fd2d8df 100644 --- a/account_statement_import_online/wizards/__init__.py +++ b/account_statement_import_online/wizards/__init__.py @@ -1,3 +1,4 @@ # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +from . import online_bank_statement_pull_debug from . import online_bank_statement_pull_wizard diff --git a/account_statement_import_online/wizards/online_bank_statement_pull_debug.py b/account_statement_import_online/wizards/online_bank_statement_pull_debug.py new file mode 100644 index 000000000..90d834a42 --- /dev/null +++ b/account_statement_import_online/wizards/online_bank_statement_pull_debug.py @@ -0,0 +1,11 @@ +# Copyright 2024 Tecnativa - Pedro M. Baeza +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import fields, models + + +class OnlineBankStatementPullWizard(models.TransientModel): + _name = "online.bank.statement.pull.debug" + _description = "Online Bank Statement Pull Debug Wizard" + + data = fields.Text(string="RAW data", required=True, readonly=True) diff --git a/account_statement_import_online/wizards/online_bank_statement_pull_debug.xml b/account_statement_import_online/wizards/online_bank_statement_pull_debug.xml new file mode 100644 index 000000000..29fc0468e --- /dev/null +++ b/account_statement_import_online/wizards/online_bank_statement_pull_debug.xml @@ -0,0 +1,24 @@ + + + + + online.bank.statement.pull.debug + +
+ +
+
+ +
+
+ + Online bank statements - Debug + online.bank.statement.pull.debug + form + new + +
diff --git a/account_statement_import_online/wizards/online_bank_statement_pull_wizard.py b/account_statement_import_online/wizards/online_bank_statement_pull_wizard.py index 2d0741dd9..49cc3f0a1 100644 --- a/account_statement_import_online/wizards/online_bank_statement_pull_wizard.py +++ b/account_statement_import_online/wizards/online_bank_statement_pull_wizard.py @@ -3,6 +3,8 @@ # Copyright 2023 Therp BV (https://therp.nl) # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +import pprint + from odoo import fields, models @@ -21,8 +23,8 @@ class OnlineBankStatementPullWizard(models.TransientModel): default=fields.Datetime.now, ) - def action_pull(self): - """Pull statements from provider and then show list of statements.""" + def _get_provider(self): + """Get the provider browse record from the data in the context.""" self.ensure_one() active_model = self.env.context.get("active_model") active_id = self.env.context.get("active_id") @@ -31,7 +33,28 @@ def action_pull(self): provider = active_record.online_bank_statement_provider_id else: provider = active_record + return provider + + def action_pull(self): + """Pull statements from provider and then show list of statements.""" + provider = self._get_provider() provider._pull(self.date_since, self.date_until) action = self.env.ref("account.action_bank_statement_tree").sudo().read([])[0] action["domain"] = [("journal_id", "=", provider.journal_id.id)] return action + + def action_debug(self): + """Pull statements in debug and show result.""" + provider = self._get_provider().with_context( + active_test=False, + account_statement_online_import_debug=True, + ) + data = provider._pull(self.date_since, self.date_until) + wizard = self.env["online.bank.statement.pull.debug"].create( + {"data": pprint.pformat(data)} + ) + action = self.env["ir.actions.act_window"]._for_xml_id( + "account_statement_import_online.online_bank_statement_pull_debug_action" + ) + action["res_id"] = wizard.id + return action diff --git a/account_statement_import_online/wizards/online_bank_statement_pull_wizard.xml b/account_statement_import_online/wizards/online_bank_statement_pull_wizard.xml index c35ba5a58..ac997de56 100644 --- a/account_statement_import_online/wizards/online_bank_statement_pull_wizard.xml +++ b/account_statement_import_online/wizards/online_bank_statement_pull_wizard.xml @@ -22,6 +22,12 @@ default_focus="1" class="btn-primary" /> +