From 10f79f94834f99b23145fcb2decff661aca152f2 Mon Sep 17 00:00:00 2001 From: Alexey Pelykh Date: Sat, 11 Apr 2020 10:21:01 +0200 Subject: [PATCH] [IMP] account_bank_statement_import_online: allow pull if archived --- .../models/account_journal.py | 10 ++- .../models/online_bank_statement_provider.py | 10 +-- .../online_bank_statement_provider_dummy.py | 16 +++-- ...st_account_bank_statement_import_online.py | 64 ++++++++++++++++++- .../views/account_journal.xml | 2 + .../online_bank_statement_pull_wizard.py | 13 ++-- .../online_bank_statement_pull_wizard.xml | 5 +- 7 files changed, 99 insertions(+), 21 deletions(-) diff --git a/account_bank_statement_import_online/models/account_journal.py b/account_bank_statement_import_online/models/account_journal.py index cca7974..9fdc230 100644 --- a/account_bank_statement_import_online/models/account_journal.py +++ b/account_bank_statement_import_online/models/account_journal.py @@ -1,5 +1,5 @@ -# Copyright 2019 Brainbean Apps (https://brainbeanapps.com) -# Copyright 2019 Dataplug (https://dataplug.io) +# Copyright 2019-2020 Brainbean Apps (https://brainbeanapps.com) +# Copyright 2019-2020 Dataplug (https://dataplug.io) # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). import logging @@ -37,9 +37,12 @@ class AccountJournal(models.Model): @api.model def values_online_bank_statement_provider(self): - return self.env[ + res = self.env[ 'online.bank.statement.provider' ]._get_available_services() + if self.user_has_groups('base.group_no_one'): + res += [('dummy', 'Dummy')] + return res @api.multi def _update_online_bank_statement_provider_id(self): @@ -92,5 +95,6 @@ class AccountJournal(models.Model): 'target': 'new', 'context': { 'default_provider_ids': [(6, False, provider_ids)], + 'active_test': False, }, } diff --git a/account_bank_statement_import_online/models/online_bank_statement_provider.py b/account_bank_statement_import_online/models/online_bank_statement_provider.py index 30670fd..f5101fe 100644 --- a/account_bank_statement_import_online/models/online_bank_statement_provider.py +++ b/account_bank_statement_import_online/models/online_bank_statement_provider.py @@ -217,7 +217,9 @@ class OnlineBankStatementProvider(models.Model): 'journal_id': provider.journal_id.id, 'date': statement_date, }) - statement = AccountBankStatement.create( + statement = AccountBankStatement.with_context( + journal_id=provider.journal_id.id, + ).create( # NOTE: This is needed since create() alters values statement_values.copy() ) @@ -275,9 +277,9 @@ class OnlineBankStatementProvider(models.Model): statement_values['balance_start'] = float( statement_values['balance_start'] ) - if 'balance_start' in statement_values: - statement_values['balance_start'] = float( - statement_values['balance_start'] + if 'balance_end_real' in statement_values: + statement_values['balance_end_real'] = float( + statement_values['balance_end_real'] ) statement.write(statement_values) statement_date_since = statement_date_until diff --git a/account_bank_statement_import_online/tests/online_bank_statement_provider_dummy.py b/account_bank_statement_import_online/tests/online_bank_statement_provider_dummy.py index 21732b1..d99d5a4 100644 --- a/account_bank_statement_import_online/tests/online_bank_statement_provider_dummy.py +++ b/account_bank_statement_import_online/tests/online_bank_statement_provider_dummy.py @@ -36,7 +36,10 @@ class OnlineBankStatementProviderDummy(models.Model): date_since -= expand_by * line_step date_until += expand_by * line_step - balance_start = randrange(-10000, 10000, 1) * 0.1 + balance_start = self.env.context.get( + 'balance_start', + randrange(-10000, 10000, 1) * 0.1 + ) balance = balance_start lines = [] date = date_since @@ -55,7 +58,10 @@ class OnlineBankStatementProviderDummy(models.Model): balance += amount date += line_step balance_end = balance - return lines, { - 'balance_start': balance_start, - 'balance_end_real': balance_end, - } + statement = {} + if self.env.context.get('balance', True): + statement.update({ + 'balance_start': balance_start, + 'balance_end_real': balance_end, + }) + return lines, statement diff --git a/account_bank_statement_import_online/tests/test_account_bank_statement_import_online.py b/account_bank_statement_import_online/tests/test_account_bank_statement_import_online.py index 00be08f..3e5fe73 100644 --- a/account_bank_statement_import_online/tests/test_account_bank_statement_import_online.py +++ b/account_bank_statement_import_online/tests/test_account_bank_statement_import_online.py @@ -21,6 +21,9 @@ class TestAccountBankAccountStatementImportOnline(common.TransactionCase): self.OnlineBankStatementProvider = self.env[ 'online.bank.statement.provider' ] + self.OnlineBankStatementPullWizard = self.env[ + 'online.bank.statement.pull.wizard' + ] self.AccountBankStatement = self.env['account.bank.statement'] self.AccountBankStatementLine = self.env['account.bank.statement.line'] @@ -84,9 +87,9 @@ class TestAccountBankAccountStatementImportOnline(common.TransactionCase): provider = journal.online_bank_statement_provider_id provider.active = True - provider.with_context({ - 'expand_by': 1, - })._pull( + provider.with_context( + expand_by=1, + )._pull( self.now - relativedelta(hours=1), self.now, ) @@ -363,3 +366,58 @@ class TestAccountBankAccountStatementImportOnline(common.TransactionCase): self.now - relativedelta(hours=1), self.now, ) + + def test_pull_no_balance(self): + journal = self.AccountJournal.create({ + 'name': 'Bank', + 'type': 'bank', + 'code': 'BANK', + 'bank_statements_source': 'online', + 'online_bank_statement_provider': 'dummy', + }) + + provider = journal.online_bank_statement_provider_id + provider.active = True + provider.statement_creation_mode = 'daily' + + provider.with_context( + step={'hours': 2}, + balance_start=0, + balance=False, + )._pull( + self.now - relativedelta(days=1), + self.now, + ) + statements = self.AccountBankStatement.search( + [('journal_id', '=', journal.id)], + order='date asc', + ) + self.assertFalse(statements[0].balance_start) + self.assertFalse(statements[0].balance_end_real) + self.assertTrue(statements[0].balance_end) + self.assertTrue(statements[1].balance_start) + self.assertFalse(statements[1].balance_end_real) + + def test_wizard(self): + journal = self.AccountJournal.create({ + 'name': 'Bank', + 'type': 'bank', + 'code': 'BANK', + 'bank_statements_source': 'online', + 'online_bank_statement_provider': 'dummy', + }) + action = journal.action_online_bank_statements_pull_wizard() + self.assertTrue(action['context']['default_provider_ids'][0][2]) + + wizard = self.OnlineBankStatementPullWizard.with_context( + action['context'] + ).create({ + 'date_since': self.now - relativedelta(hours=1), + 'date_until': self.now, + }) + self.assertTrue(wizard.provider_ids) + + wizard.action_pull() + self.assertTrue(self.AccountBankStatement.search( + [('journal_id', '=', journal.id)], + )) diff --git a/account_bank_statement_import_online/views/account_journal.xml b/account_bank_statement_import_online/views/account_journal.xml index 5810dc7..4b7de78 100644 --- a/account_bank_statement_import_online/views/account_journal.xml +++ b/account_bank_statement_import_online/views/account_journal.xml @@ -31,6 +31,8 @@ attrs="{'required': [('bank_statements_source', '=', 'online')]}" class="oe_edit_only" groups="account.group_account_user" + widget="dynamic_dropdown" + values="values_online_bank_statement_provider" />