diff --git a/account_statement_import_online/__manifest__.py b/account_statement_import_online/__manifest__.py
index 329629fb..f4fd54c8 100644
--- a/account_statement_import_online/__manifest__.py
+++ b/account_statement_import_online/__manifest__.py
@@ -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",
],
diff --git a/account_statement_import_online/models/account_journal.py b/account_statement_import_online/models/account_journal.py
index df89ee1b..edd9857a 100644
--- a/account_statement_import_online/models/account_journal.py
+++ b/account_statement_import_online/models/account_journal.py
@@ -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
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 63ffb315..58675e39 100644
--- a/account_statement_import_online/models/online_bank_statement_provider.py
+++ b/account_statement_import_online/models/online_bank_statement_provider.py
@@ -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):
diff --git a/account_statement_import_online/tests/__init__.py b/account_statement_import_online/tests/__init__.py
index c631b1f0..9f86f27b 100644
--- a/account_statement_import_online/tests/__init__.py
+++ b/account_statement_import_online/tests/__init__.py
@@ -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
diff --git a/account_statement_import_online/tests/test_account_bank_statement_import_online.py b/account_statement_import_online/tests/test_account_bank_statement_import_online.py
index e16ce1f3..70f722e6 100644
--- a/account_statement_import_online/tests/test_account_bank_statement_import_online.py
+++ b/account_statement_import_online/tests/test_account_bank_statement_import_online.py
@@ -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)])
diff --git a/account_statement_import_online/tests/test_account_journal.py b/account_statement_import_online/tests/test_account_journal.py
new file mode 100644
index 00000000..476200a5
--- /dev/null
+++ b/account_statement_import_online/tests/test_account_journal.py
@@ -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])
diff --git a/account_statement_import_online/views/account_journal.xml b/account_statement_import_online/views/account_journal.xml
index fe319292..f2b7bf83 100644
--- a/account_statement_import_online/views/account_journal.xml
+++ b/account_statement_import_online/views/account_journal.xml
@@ -2,6 +2,7 @@