[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
This commit is contained in:
Pedro M. Baeza
2024-01-30 11:33:00 +01:00
committed by Carolina Fernandez
parent afb6ef7926
commit e793b51c4b
10 changed files with 81 additions and 7 deletions

View File

@@ -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

View File

@@ -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",

View File

@@ -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 @@ class OnlineBankStatementProvider(models.Model):
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 @@ class OnlineBankStatementProvider(models.Model):
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

View File

@@ -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
1 id name model_id:id group_id:id perm_read perm_write perm_create perm_unlink
2 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
3 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
4 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
5 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

View File

@@ -367,7 +367,7 @@ ul.auto-toc {
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:5f8fb744f2638751d3401c3c729502aa387c024bbf66769c89302067a5c7bf28
!! source digest: sha256:8fcd953e1f7dbcc59cc99c790825bef09e423b32ca67b7ac5714e12b1ced7b5c
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/bank-statement-import/tree/16.0/account_statement_import_online"><img alt="OCA/bank-statement-import" src="https://img.shields.io/badge/github-OCA%2Fbank--statement--import-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/bank-statement-import-16-0/bank-statement-import-16-0-account_statement_import_online"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/bank-statement-import&amp;target_branch=16.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>This module provides base for building online bank statements providers.</p>

View File

@@ -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

View File

@@ -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)

View File

@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!--
Copyright 2024 Tecnativa - Pedro M. Baeza
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
-->
<odoo>
<record id="online_bank_statement_pull_debug_form" model="ir.ui.view">
<field name="model">online.bank.statement.pull.debug</field>
<field name="arch" type="xml">
<form>
<field name="data" />
<footer>
<button string="Close" special="cancel" />
</footer>
</form>
</field>
</record>
<record id="online_bank_statement_pull_debug_action" model="ir.actions.act_window">
<field name="name">Online bank statements - Debug</field>
<field name="res_model">online.bank.statement.pull.debug</field>
<field name="view_mode">form</field>
<field name="target">new</field>
</record>
</odoo>

View File

@@ -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 @@ class OnlineBankStatementPullWizard(models.TransientModel):
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

View File

@@ -22,6 +22,12 @@
default_focus="1"
class="btn-primary"
/>
<button
name="action_debug"
string="Debug"
type="object"
groups="base.group_no_one"
/>
<button string="Cancel" special="cancel" />
</footer>
</form>