Browse Source

Merge PR #274 into 12.0

Signed-off-by alexey-pelykh
12.0
OCA-git-bot 5 years ago
parent
commit
6096707d22
  1. 10
      account_bank_statement_import_online/models/account_journal.py
  2. 10
      account_bank_statement_import_online/models/online_bank_statement_provider.py
  3. 16
      account_bank_statement_import_online/tests/online_bank_statement_provider_dummy.py
  4. 64
      account_bank_statement_import_online/tests/test_account_bank_statement_import_online.py
  5. 2
      account_bank_statement_import_online/views/account_journal.xml
  6. 13
      account_bank_statement_import_online/wizards/online_bank_statement_pull_wizard.py
  7. 5
      account_bank_statement_import_online/wizards/online_bank_statement_pull_wizard.xml

10
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). # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
import logging import logging
@ -37,9 +37,12 @@ class AccountJournal(models.Model):
@api.model @api.model
def values_online_bank_statement_provider(self): def values_online_bank_statement_provider(self):
return self.env[
res = self.env[
'online.bank.statement.provider' 'online.bank.statement.provider'
]._get_available_services() ]._get_available_services()
if self.user_has_groups('base.group_no_one'):
res += [('dummy', 'Dummy')]
return res
@api.multi @api.multi
def _update_online_bank_statement_provider_id(self): def _update_online_bank_statement_provider_id(self):
@ -92,5 +95,6 @@ class AccountJournal(models.Model):
'target': 'new', 'target': 'new',
'context': { 'context': {
'default_provider_ids': [(6, False, provider_ids)], 'default_provider_ids': [(6, False, provider_ids)],
'active_test': False,
}, },
} }

10
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, 'journal_id': provider.journal_id.id,
'date': statement_date, '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 # NOTE: This is needed since create() alters values
statement_values.copy() statement_values.copy()
) )
@ -275,9 +277,9 @@ class OnlineBankStatementProvider(models.Model):
statement_values['balance_start'] = float( statement_values['balance_start'] = float(
statement_values['balance_start'] 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.write(statement_values)
statement_date_since = statement_date_until statement_date_since = statement_date_until

16
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_since -= expand_by * line_step
date_until += 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 balance = balance_start
lines = [] lines = []
date = date_since date = date_since
@ -55,7 +58,10 @@ class OnlineBankStatementProviderDummy(models.Model):
balance += amount balance += amount
date += line_step date += line_step
balance_end = balance 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

64
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[ self.OnlineBankStatementProvider = self.env[
'online.bank.statement.provider' 'online.bank.statement.provider'
] ]
self.OnlineBankStatementPullWizard = self.env[
'online.bank.statement.pull.wizard'
]
self.AccountBankStatement = self.env['account.bank.statement'] self.AccountBankStatement = self.env['account.bank.statement']
self.AccountBankStatementLine = self.env['account.bank.statement.line'] self.AccountBankStatementLine = self.env['account.bank.statement.line']
@ -84,9 +87,9 @@ class TestAccountBankAccountStatementImportOnline(common.TransactionCase):
provider = journal.online_bank_statement_provider_id provider = journal.online_bank_statement_provider_id
provider.active = True provider.active = True
provider.with_context({
'expand_by': 1,
})._pull(
provider.with_context(
expand_by=1,
)._pull(
self.now - relativedelta(hours=1), self.now - relativedelta(hours=1),
self.now, self.now,
) )
@ -363,3 +366,58 @@ class TestAccountBankAccountStatementImportOnline(common.TransactionCase):
self.now - relativedelta(hours=1), self.now - relativedelta(hours=1),
self.now, 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)],
))

2
account_bank_statement_import_online/views/account_journal.xml

@ -31,6 +31,8 @@
attrs="{'required': [('bank_statements_source', '=', 'online')]}" attrs="{'required': [('bank_statements_source', '=', 'online')]}"
class="oe_edit_only" class="oe_edit_only"
groups="account.group_account_user" groups="account.group_account_user"
widget="dynamic_dropdown"
values="values_online_bank_statement_provider"
/> />
<label <label
for="online_bank_statement_provider_id" for="online_bank_statement_provider_id"

13
account_bank_statement_import_online/wizards/online_bank_statement_pull_wizard.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). # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo import fields, models, api from odoo import fields, models, api
@ -24,11 +24,16 @@ class OnlineBankStatementPullWizard(models.TransientModel):
comodel_name='online.bank.statement.provider', comodel_name='online.bank.statement.provider',
column1='wizard_id', column1='wizard_id',
column2='provider_id', column2='provider_id',
relation='online_bank_statement_provider_pull_wizard_rel'
relation='online_bank_statement_provider_pull_wizard_rel',
) )
@api.multi @api.multi
def action_pull(self): def action_pull(self):
self.ensure_one() self.ensure_one()
self.provider_ids._pull(self.date_since, self.date_until)
self.with_context(
active_test=False,
).provider_ids._pull(
self.date_since,
self.date_until
)
return {'type': 'ir.actions.act_window_close'} return {'type': 'ir.actions.act_window_close'}

5
account_bank_statement_import_online/wizards/online_bank_statement_pull_wizard.xml

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8" ?> <?xml version="1.0" encoding="UTF-8" ?>
<!-- <!--
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). License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
--> -->
<odoo> <odoo>
@ -11,6 +11,7 @@
<field name="model">online.bank.statement.pull.wizard</field> <field name="model">online.bank.statement.pull.wizard</field>
<field name="arch" type="xml"> <field name="arch" type="xml">
<form> <form>
<field name="provider_ids" invisible="1"/>
<group name="filter"> <group name="filter">
<group name="date_range" colspan="2"> <group name="date_range" colspan="2">
<group> <group>

Loading…
Cancel
Save