From 4e8ed7959960e39a1ed3d5850a6ae810062456e2 Mon Sep 17 00:00:00 2001 From: "Pedro M. Baeza" Date: Wed, 17 Jan 2024 20:28:15 +0100 Subject: [PATCH 1/2] [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 | 17 +++++++++++++ .../online_bank_statement_pull_wizard.xml | 6 +++++ 10 files changed, 73 insertions(+), 5 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 087016c9..f2ddc4ac 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:2b6c268fc49f5581274d78a7e7c753ac5ef98d158df29ea26bef98867d266dff + !! source digest: sha256:f9d33e5edb980fbe8f48c2777b4d360b8688dc93160aacd970d55d604d269ded !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! .. |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 fdfde43d..c259e8db 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 64af9344..f7ef0a6b 100644 --- a/account_statement_import_online/models/online_bank_statement_provider.py +++ b/account_statement_import_online/models/online_bank_statement_provider.py @@ -1,5 +1,6 @@ # Copyright 2019-2020 Brainbean Apps (https://brainbeanapps.com) # Copyright 2019-2020 Dataplug (https://dataplug.io) +# Copyright 2014 Tecnativa - Pedro M. Baeza # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). import logging @@ -146,6 +147,8 @@ class OnlineBankStatementProvider(models.Model): def _pull(self, date_since, date_until): 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: @@ -182,12 +185,16 @@ class OnlineBankStatementProvider(models.Model): ) break raise - 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 _create_or_update_statement( self, data, 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 d0856372..22a9f544 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 e2379303..af30a495 100644 --- a/account_statement_import_online/static/description/index.html +++ b/account_statement_import_online/static/description/index.html @@ -367,7 +367,7 @@ ul.auto-toc { !! This file is generated by oca-gen-addon-readme !! !! changes will be overwritten. !! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -!! source digest: sha256:2b6c268fc49f5581274d78a7e7c753ac5ef98d158df29ea26bef98867d266dff +!! source digest: sha256:f9d33e5edb980fbe8f48c2777b4d360b8688dc93160aacd970d55d604d269ded !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->

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 a8ac6626..f7fd2d8d 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 00000000..90d834a4 --- /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 00000000..29fc0468 --- /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 5c390550..9761ee30 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 @@ -2,6 +2,8 @@ # Copyright 2019-2020 Dataplug (https://dataplug.io) # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +import pprint + from odoo import api, fields, models @@ -60,3 +62,18 @@ class OnlineBankStatementPullWizard(models.TransientModel): ("journal_id", "in", [o.journal_id.id for o in self.provider_ids]) ] return action + + def action_debug(self): + """Pull statements in debug and show result.""" + self.ensure_one() + data = self.with_context( + active_test=False, account_statement_online_import_debug=True + ).provider_ids._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 52209cb9..27cc6609 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 @@ -28,6 +28,12 @@ default_focus="1" class="btn-primary" /> +