mirror of
https://github.com/OCA/bank-statement-import.git
synced 2025-01-20 12:37:43 +02:00
[FIX] account_statement_import_online: further improvements.
This commit is contained in:
@@ -21,6 +21,7 @@
|
||||
"security/ir.model.access.csv",
|
||||
"security/online_bank_statement_provider.xml",
|
||||
"wizards/online_bank_statement_pull_wizard.xml",
|
||||
"views/actions.xml",
|
||||
"views/account_journal.xml",
|
||||
"views/online_bank_statement_provider.xml",
|
||||
],
|
||||
|
||||
@@ -16,12 +16,16 @@ class AccountJournal(models.Model):
|
||||
selection=lambda self: self.env[
|
||||
"account.journal"
|
||||
]._selection_online_bank_statement_provider(),
|
||||
help="Select the type of service provider (a model)",
|
||||
)
|
||||
online_bank_statement_provider_id = fields.Many2one(
|
||||
string="Statement Provider",
|
||||
comodel_name="online.bank.statement.provider",
|
||||
ondelete="restrict",
|
||||
copy=False,
|
||||
help="Select the actual instance of a configured provider (a record).\n"
|
||||
"Selecting a type of provider will automatically create a provider"
|
||||
" record linked to this journal.",
|
||||
)
|
||||
|
||||
def __get_bank_statements_available_sources(self):
|
||||
@@ -37,12 +41,14 @@ class AccountJournal(models.Model):
|
||||
|
||||
@api.model
|
||||
def values_online_bank_statement_provider(self):
|
||||
"""Return values for provider type selection in the form view."""
|
||||
res = self.env["online.bank.statement.provider"]._get_available_services()
|
||||
if self.user_has_groups("base.group_no_one"):
|
||||
res += [("dummy", "Dummy")]
|
||||
return res
|
||||
|
||||
def _update_online_bank_statement_provider_id(self):
|
||||
"""Keep provider synchronized with journal."""
|
||||
OnlineBankStatementProvider = self.env["online.bank.statement.provider"]
|
||||
for journal in self.filtered("id"):
|
||||
provider_id = journal.online_bank_statement_provider_id
|
||||
|
||||
@@ -24,7 +24,7 @@ class OnlineBankStatementProvider(models.Model):
|
||||
_description = "Online Bank Statement Provider"
|
||||
|
||||
company_id = fields.Many2one(related="journal_id.company_id", store=True)
|
||||
active = fields.Boolean()
|
||||
active = fields.Boolean(default=True)
|
||||
name = fields.Char(string="Name", compute="_compute_name", store=True)
|
||||
journal_id = fields.Many2one(
|
||||
comodel_name="account.journal",
|
||||
@@ -122,12 +122,11 @@ class OnlineBankStatementProvider(models.Model):
|
||||
def values_service(self):
|
||||
return self._get_available_services()
|
||||
|
||||
@api.depends("service")
|
||||
@api.depends("service", "journal_id.name")
|
||||
def _compute_name(self):
|
||||
"""We can have multiple providers/journals for the same service."""
|
||||
for provider in self:
|
||||
provider.name = list(
|
||||
filter(lambda x: x[0] == provider.service, self._selection_service())
|
||||
)[0][1]
|
||||
provider.name = " ".join([provider.journal_id.name, provider.service])
|
||||
|
||||
@api.depends("active", "interval_type", "interval_number")
|
||||
def _compute_update_schedule(self):
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
|
||||
|
||||
from . import test_account_bank_statement_import_online
|
||||
from . import test_account_journal
|
||||
|
||||
@@ -48,8 +48,15 @@ class TestAccountBankAccountStatementImportOnline(common.TransactionCase):
|
||||
journal_form.save()
|
||||
|
||||
self.assertTrue(journal.online_bank_statement_provider_id)
|
||||
save_provider_id = journal.online_bank_statement_provider_id.id
|
||||
journal.unlink()
|
||||
self.assertFalse(self.OnlineBankStatementProvider.search([]))
|
||||
self.assertFalse(
|
||||
self.OnlineBankStatementProvider.search(
|
||||
[
|
||||
("id", "=", save_provider_id),
|
||||
]
|
||||
)
|
||||
)
|
||||
|
||||
def test_source_change_cleanup(self):
|
||||
journal = self.AccountJournal.create(
|
||||
@@ -61,13 +68,25 @@ class TestAccountBankAccountStatementImportOnline(common.TransactionCase):
|
||||
journal_form.save()
|
||||
|
||||
self.assertTrue(journal.online_bank_statement_provider_id)
|
||||
save_provider_id = journal.online_bank_statement_provider_id.id
|
||||
|
||||
# Stuff should not change when doing unrelated write.
|
||||
journal.write({"code": "BIGBANK"})
|
||||
self.assertTrue(journal.online_bank_statement_provider_id)
|
||||
self.assertEqual(journal.online_bank_statement_provider_id.id, save_provider_id)
|
||||
|
||||
with common.Form(journal) as journal_form:
|
||||
journal_form.bank_statements_source = "undefined"
|
||||
journal_form.save()
|
||||
|
||||
self.assertFalse(journal.online_bank_statement_provider_id)
|
||||
self.assertFalse(self.OnlineBankStatementProvider.search([]))
|
||||
self.assertFalse(
|
||||
self.OnlineBankStatementProvider.search(
|
||||
[
|
||||
("id", "=", save_provider_id),
|
||||
]
|
||||
)
|
||||
)
|
||||
|
||||
def test_pull_mode_daily(self):
|
||||
journal = self.AccountJournal.create(
|
||||
@@ -396,13 +415,13 @@ class TestAccountBankAccountStatementImportOnline(common.TransactionCase):
|
||||
"online_bank_statement_provider": "dummy",
|
||||
}
|
||||
)
|
||||
wizard = self.OnlineBankStatementPullWizard.with_context(
|
||||
vals = self.OnlineBankStatementPullWizard.with_context(
|
||||
active_model="account.journal", active_id=journal.id
|
||||
).create(
|
||||
{"date_since": self.now - relativedelta(hours=1), "date_until": self.now}
|
||||
)
|
||||
).default_get(fields_list=["provider_ids"])
|
||||
vals["date_since"] = self.now - relativedelta(hours=1)
|
||||
vals["date_until"] = self.now
|
||||
wizard = self.OnlineBankStatementPullWizard.create(vals)
|
||||
self.assertTrue(wizard.provider_ids)
|
||||
|
||||
wizard.action_pull()
|
||||
self.assertTrue(
|
||||
self.AccountBankStatement.search([("journal_id", "=", journal.id)])
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
# Copyright 2021 Therp BV (https://therp.nl).
|
||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
|
||||
from mock import patch
|
||||
|
||||
from odoo.tests import common
|
||||
|
||||
|
||||
class TestAccountJournal(common.TransactionCase):
|
||||
"""Test some functions adde d to account.journal model."""
|
||||
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
self.AccountJournal = self.env["account.journal"]
|
||||
|
||||
def test_values_online_bank_statement_provider(self):
|
||||
"""Check method to retrieve provider types."""
|
||||
# Make sure the users seems to have the group_no_one.
|
||||
with patch.object(
|
||||
self.AccountJournal.__class__, "user_has_groups", return_value=True
|
||||
):
|
||||
values = self.AccountJournal.values_online_bank_statement_provider()
|
||||
self.assertIn("dummy", [entry[0] for entry in values])
|
||||
@@ -2,6 +2,7 @@
|
||||
<!--
|
||||
Copyright 2019-2020 Brainbean Apps (https://brainbeanapps.com)
|
||||
Copyright 2019-2020 Dataplug (https://dataplug.io)
|
||||
Copyright 2021 Therp BV (https://therp.nl).
|
||||
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
|
||||
-->
|
||||
<odoo>
|
||||
@@ -51,24 +52,12 @@
|
||||
<header>
|
||||
<button
|
||||
type="action"
|
||||
name="%(online_bank_statement_pull_wizard_action)d"
|
||||
attrs="{'invisible': ['|', ('bank_statements_source', '!=', 'online'), ('online_bank_statement_provider', '=', False)]}"
|
||||
name="%(action_online_bank_statements_pull_wizard)d"
|
||||
attrs="{'invisible': [('online_bank_statement_provider', '=', False)]}"
|
||||
string="Pull Online Bank Statement"
|
||||
/>
|
||||
</header>
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
<record
|
||||
id="action_online_bank_statements_pull_wizard"
|
||||
model="ir.actions.act_window"
|
||||
>
|
||||
<field name="name">Online Bank Statements Pull Wizard</field>
|
||||
<field name="res_model">online.bank.statement.pull.wizard</field>
|
||||
<field name="target">new</field>
|
||||
<field name="view_mode">form</field>
|
||||
<field name="binding_model_id" ref="account.model_account_journal" />
|
||||
<field name="binding_view_types">list</field>
|
||||
<field name="groups_id" eval="[(4, ref('account.group_account_user'))]" />
|
||||
</record>
|
||||
</odoo>
|
||||
|
||||
19
account_statement_import_online/views/actions.xml
Normal file
19
account_statement_import_online/views/actions.xml
Normal file
@@ -0,0 +1,19 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<!--
|
||||
Copyright 2021 Therp BV (https://therp.nl).
|
||||
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
|
||||
-->
|
||||
<odoo>
|
||||
<record
|
||||
id="action_online_bank_statements_pull_wizard"
|
||||
model="ir.actions.act_window"
|
||||
>
|
||||
<field name="name">Online Bank Statements Pull Wizard</field>
|
||||
<field name="res_model">online.bank.statement.pull.wizard</field>
|
||||
<field name="target">new</field>
|
||||
<field name="view_mode">form</field>
|
||||
<field name="binding_model_id" ref="account.model_account_journal" />
|
||||
<field name="binding_view_types">list</field>
|
||||
<field name="groups_id" eval="[(4, ref('account.group_account_user'))]" />
|
||||
</record>
|
||||
</odoo>
|
||||
@@ -19,6 +19,8 @@ class OnlineBankStatementPullWizard(models.TransientModel):
|
||||
required=True,
|
||||
default=fields.Datetime.now,
|
||||
)
|
||||
# The link to providers is Many2many, because you can select multiple
|
||||
# journals for the action to pull statements.
|
||||
provider_ids = fields.Many2many(
|
||||
string="Providers",
|
||||
comodel_name="online.bank.statement.provider",
|
||||
@@ -29,25 +31,25 @@ class OnlineBankStatementPullWizard(models.TransientModel):
|
||||
|
||||
@api.model
|
||||
def default_get(self, fields_list):
|
||||
"""Retrieve providers from the journals for which this wizard is launched."""
|
||||
res = super().default_get(fields_list)
|
||||
journal_ids = []
|
||||
if self.env.context.get("active_model") == "account.journal":
|
||||
if self.env.context.get("active_ids"):
|
||||
journals = self.env["account.journal"].browse(
|
||||
self.env.context["active_ids"]
|
||||
)
|
||||
res["provider_ids"] = journals.online_bank_statement_provider_id.ids
|
||||
journal_ids = self.env.context["active_ids"]
|
||||
elif self.env.context.get("active_id"):
|
||||
journal = self.env["account.journal"].browse(
|
||||
self.env.context["active_id"]
|
||||
)
|
||||
res["provider_ids"] = [journal.online_bank_statement_provider_id.id]
|
||||
journal_ids = [self.env.context["active_id"]]
|
||||
if journal_ids:
|
||||
journals = self.env["account.journal"].browse(journal_ids)
|
||||
res["provider_ids"] = [journals.online_bank_statement_provider_id.id]
|
||||
return res
|
||||
|
||||
def action_pull(self):
|
||||
"""Pull statements from providers and then show list of statements."""
|
||||
self.ensure_one()
|
||||
self.with_context(
|
||||
active_test=False,
|
||||
).provider_ids._pull(self.date_since, self.date_until)
|
||||
self.with_context(active_test=False).provider_ids._pull(
|
||||
self.date_since, self.date_until
|
||||
)
|
||||
action = self.env.ref("account.action_bank_statement_tree").sudo().read([])[0]
|
||||
if len(self.provider_ids) == 1:
|
||||
action["context"] = {
|
||||
|
||||
@@ -11,7 +11,12 @@
|
||||
<field name="arch" type="xml">
|
||||
<form>
|
||||
<group name="main">
|
||||
<field name="provider_ids" widget="many2many_tags" required="1" />
|
||||
<field
|
||||
name="provider_ids"
|
||||
widget="many2many_tags"
|
||||
required="1"
|
||||
options="{'create': false, 'create_edit': false}"
|
||||
/>
|
||||
<field name="date_since" />
|
||||
<field name="date_until" />
|
||||
</group>
|
||||
@@ -29,11 +34,4 @@
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="online_bank_statement_pull_wizard_action" model="ir.actions.act_window">
|
||||
<field name="name">Pull Online Bank Statement</field>
|
||||
<field name="res_model">online.bank.statement.pull.wizard</field>
|
||||
<field name="view_mode">form</field>
|
||||
<field name="target">new</field>
|
||||
</record>
|
||||
|
||||
</odoo>
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
ref="account_statement_import_online.online_bank_statement_provider_form"
|
||||
/>
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//page[@name='configuration']" position="inside">
|
||||
<xpath expr="//group[@name='main']" position="inside">
|
||||
<group name="ponto" attrs="{'invisible':[('service','!=','ponto')]}">
|
||||
<field name="username" string="Login" />
|
||||
<field name="password" string="Secret Key" />
|
||||
|
||||
@@ -1 +1,2 @@
|
||||
# See https://github.com/OCA/odoo-community.org/blob/master/website/Contribution/CONTRIBUTING.rst#oca_dependencies-txt
|
||||
web
|
||||
|
||||
Reference in New Issue
Block a user