mirror of
https://github.com/OCA/bank-statement-import.git
synced 2025-01-20 12:37:43 +02:00
@@ -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
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
@@ -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&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>
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
@@ -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>
|
||||
@@ -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
|
||||
|
||||
@@ -17,11 +17,18 @@
|
||||
<footer>
|
||||
<button
|
||||
name="action_pull"
|
||||
string="Pull"
|
||||
string="Import Transactions"
|
||||
type="object"
|
||||
default_focus="1"
|
||||
class="btn-primary"
|
||||
/>
|
||||
<button
|
||||
name="action_debug"
|
||||
string="Show Transaction Data"
|
||||
help="Fetch and display transaction data (for debug purposes)"
|
||||
type="object"
|
||||
groups="base.group_no_one"
|
||||
/>
|
||||
<button string="Cancel" special="cancel" />
|
||||
</footer>
|
||||
</form>
|
||||
|
||||
@@ -49,11 +49,18 @@ class OnlineBankStatementProvider(models.Model):
|
||||
"""
|
||||
# pylint: disable=missing-return
|
||||
ponto_providers = self.filtered(lambda provider: provider.service == "ponto")
|
||||
super(OnlineBankStatementProvider, self - ponto_providers)._pull(
|
||||
debug = self.env.context.get("account_statement_online_import_debug")
|
||||
debug_data = []
|
||||
data = super(OnlineBankStatementProvider, self - ponto_providers)._pull(
|
||||
date_since, date_until
|
||||
)
|
||||
if debug:
|
||||
debug_data += data
|
||||
for provider in ponto_providers:
|
||||
provider._ponto_pull(date_since, date_until)
|
||||
data = provider._ponto_pull(date_since, date_until)
|
||||
if debug:
|
||||
debug_data += data
|
||||
return debug_data
|
||||
|
||||
def _ponto_pull(self, date_since, date_until):
|
||||
"""Translate information from Ponto to Odoo bank statement lines."""
|
||||
@@ -84,6 +91,7 @@ class OnlineBankStatementProvider(models.Model):
|
||||
if is_scheduled:
|
||||
self.ponto_last_identifier = lines[0].get("id")
|
||||
self._ponto_store_lines(lines)
|
||||
return lines
|
||||
|
||||
def _ponto_retrieve_data(self, date_since, date_until):
|
||||
"""Fill buffer with data from Ponto.
|
||||
|
||||
@@ -407,3 +407,24 @@ class TestAccountStatementImportOnlinePonto(common.TransactionCase):
|
||||
"account_number": "XX00 0000 0000 0000",
|
||||
}
|
||||
], {}
|
||||
|
||||
def test_wizard_action_debug(self):
|
||||
"""Debug data is returned properly."""
|
||||
statement_date = datetime(2019, 11, 1)
|
||||
data = self._get_statement_line_data(statement_date)
|
||||
self.provider.statement_creation_mode = "daily"
|
||||
self.provider._create_or_update_statement(
|
||||
data, statement_date, datetime(2019, 11, 2)
|
||||
)
|
||||
with self.mock_login(), self.mock_set_access_account(), self.mock_get_transactions(): # noqa: B950
|
||||
vals = {
|
||||
"date_since": datetime(2019, 11, 4),
|
||||
"date_until": datetime(2019, 11, 5),
|
||||
}
|
||||
wizard = self.AccountStatementPull.with_context(
|
||||
active_model=self.provider._name,
|
||||
active_id=self.provider.id,
|
||||
).create(vals)
|
||||
action = wizard.action_debug()
|
||||
debug_wizard = self.env[action["res_model"]].browse(action["res_id"])
|
||||
self.assertIn("Laboriosam repelo", debug_wizard.data)
|
||||
|
||||
Reference in New Issue
Block a user