[FIX] account_statement_import_online: further improvements.

This commit is contained in:
Ronald Portier
2021-07-14 11:40:50 +02:00
committed by Carolina Fernandez
parent bbdb843171
commit fe7adc1bdf
12 changed files with 164 additions and 101 deletions

View File

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

View File

@@ -4,7 +4,7 @@
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 13.0\n"
"Project-Id-Version: Odoo Server 14.0\n"
"Report-Msgid-Bugs-To: \n"
"Last-Translator: \n"
"Language-Team: \n"
@@ -34,6 +34,11 @@ msgstr ""
msgid "Api Base"
msgstr ""
#. module: account_statement_import_online
#: model_terms:ir.ui.view,arch_db:account_statement_import_online.online_bank_statement_provider_form
msgid "Archived"
msgstr ""
#. module: account_statement_import_online
#: model:ir.model.fields,field_description:account_statement_import_online.field_online_bank_statement_provider__message_attachment_count
msgid "Attachment Count"
@@ -107,11 +112,7 @@ msgid "Day(s)"
msgstr ""
#. module: account_statement_import_online
#: model_terms:ir.ui.view,arch_db:account_statement_import_online.online_bank_statement_provider_form
msgid "Details"
msgstr ""
#. module: account_statement_import_online
#: model:ir.model.fields,field_description:account_statement_import_online.field_account_journal__display_name
#: model:ir.model.fields,field_description:account_statement_import_online.field_online_bank_statement_provider__display_name
#: model:ir.model.fields,field_description:account_statement_import_online.field_online_bank_statement_pull_wizard__display_name
msgid "Display Name"
@@ -140,12 +141,18 @@ msgstr ""
msgid "Followers (Partners)"
msgstr ""
#. module: account_statement_import_online
#: model:ir.model.fields,field_description:account_statement_import_online.field_online_bank_statement_pull_wizard__date_since
msgid "From"
msgstr ""
#. module: account_statement_import_online
#: model:ir.model.fields.selection,name:account_statement_import_online.selection__online_bank_statement_provider__interval_type__hours
msgid "Hour(s)"
msgstr ""
#. module: account_statement_import_online
#: model:ir.model.fields,field_description:account_statement_import_online.field_account_journal__id
#: model:ir.model.fields,field_description:account_statement_import_online.field_online_bank_statement_provider__id
#: model:ir.model.fields,field_description:account_statement_import_online.field_online_bank_statement_pull_wizard__id
msgid "ID"
@@ -198,6 +205,7 @@ msgid "Key"
msgstr ""
#. module: account_statement_import_online
#: model:ir.model.fields,field_description:account_statement_import_online.field_account_journal____last_update
#: model:ir.model.fields,field_description:account_statement_import_online.field_online_bank_statement_provider____last_update
#: model:ir.model.fields,field_description:account_statement_import_online.field_online_bank_statement_pull_wizard____last_update
msgid "Last Modified on"
@@ -294,32 +302,30 @@ msgstr ""
#. module: account_statement_import_online
#: model:ir.model,name:account_statement_import_online.model_online_bank_statement_provider
#: model:ir.model.fields,field_description:account_statement_import_online.field_account_statement_import_journal_creation__online_bank_statement_provider
#: model:ir.model.fields,field_description:account_statement_import_online.field_account_journal__online_bank_statement_provider
#: model_terms:ir.ui.view,arch_db:account_statement_import_online.online_bank_statement_provider_form
msgid "Online Bank Statement Provider"
msgstr ""
#. module: account_statement_import_online
#: model:ir.actions.act_window,name:account_statement_import_online.online_bank_statement_provider_action
#: model:ir.ui.menu,name:account_statement_import_online.online_bank_statement_provider_menu
#: model_terms:ir.ui.view,arch_db:account_statement_import_online.online_bank_statement_provider_filter
msgid "Online Bank Statement Providers"
msgstr ""
#. module: account_statement_import_online
#: code:addons/account_statement_import_online/models/account_journal.py:0
#: model:ir.model,name:account_statement_import_online.model_online_bank_statement_pull_wizard
#, python-format
msgid "Online Bank Statement Pull Wizard"
msgstr ""
#. module: account_statement_import_online
#: model_terms:ir.ui.view,arch_db:account_statement_import_online.view_account_bank_journal_form
#: model_terms:ir.ui.view,arch_db:account_statement_import_online.view_account_journal_form
msgid "Online Bank Statements (OCA)"
msgstr ""
#. module: account_statement_import_online
#: model:ir.actions.server,name:account_statement_import_online.action_online_bank_statements_pull_wizard
#: model:ir.actions.act_window,name:account_statement_import_online.action_online_bank_statements_pull_wizard
msgid "Online Bank Statements Pull Wizard"
msgstr ""
@@ -344,7 +350,6 @@ msgid "Password"
msgstr ""
#. module: account_statement_import_online
#: model_terms:ir.ui.view,arch_db:account_statement_import_online.view_account_bank_journal_form
#: model_terms:ir.ui.view,arch_db:account_statement_import_online.view_account_journal_form
msgid "Provider"
msgstr ""
@@ -359,6 +364,11 @@ msgstr ""
msgid "Pull"
msgstr ""
#. module: account_statement_import_online
#: model_terms:ir.ui.view,arch_db:account_statement_import_online.view_account_journal_form
msgid "Pull Online Bank Statement"
msgstr ""
#. module: account_statement_import_online
#: model:ir.actions.server,name:account_statement_import_online.ir_cron_account_pull_online_bank_statements_ir_actions_server
#: model:ir.cron,cron_name:account_statement_import_online.ir_cron_account_pull_online_bank_statements
@@ -391,28 +401,30 @@ msgstr ""
msgid "Scheduled update interval must be greater than zero!"
msgstr ""
#. module: account_statement_import_online
#: model:ir.model.fields,help:account_statement_import_online.field_account_journal__online_bank_statement_provider_id
msgid ""
"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."
msgstr ""
#. module: account_statement_import_online
#: model:ir.model.fields,help:account_statement_import_online.field_account_journal__online_bank_statement_provider
msgid "Select the type of service provider (a model)"
msgstr ""
#. module: account_statement_import_online
#: model:ir.model.fields,field_description:account_statement_import_online.field_online_bank_statement_provider__service
#: model_terms:ir.ui.view,arch_db:account_statement_import_online.online_bank_statement_provider_filter
msgid "Service"
msgstr ""
#. module: account_statement_import_online
#: model:ir.model.fields,field_description:account_statement_import_online.field_online_bank_statement_pull_wizard__date_since
msgid "Since"
msgstr ""
#. module: account_statement_import_online
#: model_terms:ir.ui.view,arch_db:account_statement_import_online.online_bank_statement_pull_wizard_form
msgid "Since (at least)"
msgstr ""
#. module: account_statement_import_online
#: model:ir.model.fields,field_description:account_statement_import_online.field_online_bank_statement_provider__statement_creation_mode
msgid "Statement Creation Mode"
msgstr ""
#. module: account_statement_import_online
#: model:ir.model.fields,field_description:account_statement_import_online.field_account_statement_import_journal_creation__online_bank_statement_provider_id
#: model:ir.model.fields,field_description:account_statement_import_online.field_account_journal__online_bank_statement_provider_id
msgid "Statement Provider"
msgstr ""
@@ -434,6 +446,11 @@ msgid ""
"statement."
msgstr ""
#. module: account_statement_import_online
#: model:ir.model.fields,field_description:account_statement_import_online.field_online_bank_statement_pull_wizard__date_until
msgid "To"
msgstr ""
#. module: account_statement_import_online
#: model:ir.model.fields,field_description:account_statement_import_online.field_online_bank_statement_provider__message_unread
msgid "Unread Messages"
@@ -444,16 +461,6 @@ msgstr ""
msgid "Unread Messages Counter"
msgstr ""
#. module: account_statement_import_online
#: model:ir.model.fields,field_description:account_statement_import_online.field_online_bank_statement_pull_wizard__date_until
msgid "Until"
msgstr ""
#. module: account_statement_import_online
#: model_terms:ir.ui.view,arch_db:account_statement_import_online.online_bank_statement_pull_wizard_form
msgid "Until (at least)"
msgstr ""
#. module: account_statement_import_online
#: model:ir.model.fields,field_description:account_statement_import_online.field_online_bank_statement_provider__update_schedule
msgid "Update Schedule"

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -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>
@@ -48,27 +49,15 @@
</group>
</page>
<xpath expr="/form/sheet" position="before">
<header>
<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>

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

View File

@@ -17,7 +17,7 @@
domain="[('active', '=', False)]"
/>
<group name="groupby">
<filter
<filter
name="service_groupby"
string="Service"
context="{'group_by': 'service'}"
@@ -46,13 +46,13 @@
<field name="arch" type="xml">
<form string="Online Bank Statement Provider">
<sheet>
<widget
<widget
name="web_ribbon"
title="Archived"
bg_color="bg-danger"
attrs="{'invisible': [('active', '=', True)]}"
/>
<group name="main" col="2">
<group name="main" col="2">
<group name="params">
<field name="journal_id" />
<field name="currency_id" />
@@ -61,25 +61,25 @@
name="company_id"
groups="base.group_multi_company"
/>
<field
<field
name="service"
widget="dynamic_dropdown"
values="values_service"
/>
<field name="active" invisible="1" />
</group>
</group>
<group name="pull" string="Scheduled Pull">
<label for="interval_number" />
<div class="o_row" id="interval_number">
<field name="interval_number" class="ml8" />
<field name="interval_type" />
</div>
<field name="next_run" />
</group>
<label for="interval_number" />
<div class="o_row" id="interval_number">
<field name="interval_number" class="ml8" />
<field name="interval_type" />
</div>
<field name="next_run" />
</group>
<group name="configuration" string="Configuration">
<field name="statement_creation_mode" />
<field name="tz" />
</group>
<field name="statement_creation_mode" />
<field name="tz" />
</group>
</group>
</sheet>
<div class="oe_chatter">
@@ -88,12 +88,12 @@
</div>
</form>
</field>
</record>
</record>
<record id="online_bank_statement_provider_action" model="ir.actions.act_window">
<field name="name">Online Bank Statement Providers</field>
<field name="res_model">online.bank.statement.provider</field>
<field name="view_mode">tree,form</field>
<record id="online_bank_statement_provider_action" model="ir.actions.act_window">
<field name="name">Online Bank Statement Providers</field>
<field name="res_model">online.bank.statement.provider</field>
<field name="view_mode">tree,form</field>
</record>
<menuitem

View File

@@ -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"] = {

View File

@@ -11,9 +11,14 @@
<field name="arch" type="xml">
<form>
<group name="main">
<field name="provider_ids" widget="many2many_tags" required="1" />
<field name="date_since" />
<field name="date_until" />
<field
name="provider_ids"
widget="many2many_tags"
required="1"
options="{'create': false, 'create_edit': false}"
/>
<field name="date_since" />
<field name="date_until" />
</group>
<footer>
<button
@@ -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>