Browse Source

[ADD] account_bank_statement_import_online: online bank statements

12.0
Alexey Pelykh 6 years ago
parent
commit
00ea4a5c45
  1. 114
      account_bank_statement_import_online/README.rst
  2. 5
      account_bank_statement_import_online/__init__.py
  3. 30
      account_bank_statement_import_online/__manifest__.py
  4. 21
      account_bank_statement_import_online/data/account_bank_statement_import_online.xml
  5. 4
      account_bank_statement_import_online/models/__init__.py
  6. 96
      account_bank_statement_import_online/models/account_journal.py
  7. 388
      account_bank_statement_import_online/models/online_bank_statement_provider.py
  8. 23
      account_bank_statement_import_online/readme/CONFIGURE.rst
  9. 1
      account_bank_statement_import_online/readme/CONTRIBUTORS.rst
  10. 1
      account_bank_statement_import_online/readme/DESCRIPTION.rst
  11. 9
      account_bank_statement_import_online/readme/USAGE.rst
  12. 3
      account_bank_statement_import_online/security/ir.model.access.csv
  13. 16
      account_bank_statement_import_online/security/online_bank_statement_provider.xml
  14. 460
      account_bank_statement_import_online/static/description/index.html
  15. 3
      account_bank_statement_import_online/tests/__init__.py
  16. 55
      account_bank_statement_import_online/tests/online_bank_statement_provider_dummy.py
  17. 343
      account_bank_statement_import_online/tests/test_account_bank_statement_import_online.py
  18. 120
      account_bank_statement_import_online/views/account_journal.xml
  19. 96
      account_bank_statement_import_online/views/online_bank_statement_provider.xml
  20. 3
      account_bank_statement_import_online/wizards/__init__.py
  21. 34
      account_bank_statement_import_online/wizards/online_bank_statement_pull_wizard.py
  22. 32
      account_bank_statement_import_online/wizards/online_bank_statement_pull_wizard.xml
  23. 1
      oca_dependencies.txt

114
account_bank_statement_import_online/README.rst

@ -0,0 +1,114 @@
======================
Online Bank Statements
======================
.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
:target: https://odoo-community.org/page/development-status
:alt: Beta
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fbank--statement--import-lightgray.png?logo=github
:target: https://github.com/OCA/bank-statement-import/tree/12.0/account_bank_statement_import_online
:alt: OCA/bank-statement-import
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/bank-statement-import-12-0/bank-statement-import-12-0-account_bank_statement_import_online
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
:target: https://runbot.odoo-community.org/runbot/174/12.0
:alt: Try me on Runbot
|badge1| |badge2| |badge3| |badge4| |badge5|
This module provides base for building online bank statements providers.
**Table of contents**
.. contents::
:local:
Configuration
=============
To configure online bank statements provider:
#. Go to *Invoicing > Configuration > Bank Accounts*
#. Open bank account to configure and edit it
#. Set *Bank Feeds* to *Online*
#. Select online bank statements provider in *Online Bank Statements (OCA)*
section
#. Save the bank account
#. Click on provider and configure provider-specific settings.
or, alternatively:
#. Go to *Invoicing > Overview*
#. Open settings of the corresponding journal account
#. Switch to *Bank Account* tab
#. Set *Bank Feeds* to *Online*
#. Select online bank statements provider in *Online Bank Statements (OCA)*
section
#. Save the bank account
#. Click on provider and configure provider-specific settings.
**NOTE**: To access these features, user needs to belong to
*Show Full Accounting Features* group.
Usage
=====
To pull historical bank statements:
#. Go to *Invoicing > Configuration > Bank Accounts*
#. Select specific bank accounts
#. Launch *Actions > Online Bank Statements Pull Wizard*
#. Configure date interval and click *Pull*
**NOTE**: To access these features, user needs to belong to
*Show Full Accounting Features* group.
Bug Tracker
===========
Bugs are tracked on `GitHub Issues <https://github.com/OCA/bank-statement-import/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us smashing it by providing a detailed and welcomed
`feedback <https://github.com/OCA/bank-statement-import/issues/new?body=module:%20account_bank_statement_import_online%0Aversion:%2012.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
Do not contact contributors directly about support or help with technical issues.
Credits
=======
Authors
~~~~~~~
* Brainbean Apps
* Dataplug
Contributors
~~~~~~~~~~~~
* Alexey Pelykh <alexey.pelykh@brainbeanapps.com>
Maintainers
~~~~~~~~~~~
This module is maintained by the OCA.
.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org
OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.
This module is part of the `OCA/bank-statement-import <https://github.com/OCA/bank-statement-import/tree/12.0/account_bank_statement_import_online>`_ project on GitHub.
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

5
account_bank_statement_import_online/__init__.py

@ -0,0 +1,5 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from . import models
from . import wizards
from .tests import online_bank_statement_provider_dummy

30
account_bank_statement_import_online/__manifest__.py

@ -0,0 +1,30 @@
# Copyright 2019 Brainbean Apps (https://brainbeanapps.com)
# Copyright 2019 Dataplug (https://dataplug.io)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
{
'name': 'Online Bank Statements',
'version': '12.0.1.0.0',
'author':
'Brainbean Apps, '
'Dataplug, '
'Odoo Community Association (OCA)',
'website': 'https://github.com/OCA/bank-statement-import/',
'license': 'AGPL-3',
'category': 'Accounting',
'summary': 'Online bank statements update',
'depends': [
'account',
'account_bank_statement_import',
'web_widget_dropdown_dynamic',
],
'data': [
'data/account_bank_statement_import_online.xml',
'security/ir.model.access.csv',
'security/online_bank_statement_provider.xml',
'views/account_journal.xml',
'views/online_bank_statement_provider.xml',
'wizards/online_bank_statement_pull_wizard.xml',
],
'installable': True,
}

21
account_bank_statement_import_online/data/account_bank_statement_import_online.xml

@ -0,0 +1,21 @@
<?xml version="1.0" ?>
<!--
Copyright 2019 Brainbean Apps (https://brainbeanapps.com)
Copyright 2019 Dataplug (https://dataplug.io)
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
-->
<odoo noupdate="1">
<record model="ir.cron" id="ir_cron_account_pull_online_bank_statements">
<field name="name">Pull Online Bank Statements</field>
<field name="interval_number">1</field>
<field name="interval_type">hours</field>
<field name="numbercall">-1</field>
<field name="state">code</field>
<field name="nextcall">2019-01-01 00:10:00</field>
<field name="doall" eval="False"/>
<field name="model_id" ref="account_bank_statement_import_online.model_online_bank_statement_provider"/>
<field name="code">model._scheduled_pull()</field>
</record>
</odoo>

4
account_bank_statement_import_online/models/__init__.py

@ -0,0 +1,4 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from . import account_journal
from . import online_bank_statement_provider

96
account_bank_statement_import_online/models/account_journal.py

@ -0,0 +1,96 @@
# Copyright 2019 Brainbean Apps (https://brainbeanapps.com)
# Copyright 2019 Dataplug (https://dataplug.io)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
import logging
from odoo import models, fields, api, _
_logger = logging.getLogger(__name__)
class AccountJournal(models.Model):
_inherit = 'account.journal'
online_bank_statement_provider = fields.Selection(
selection=lambda self: self.env[
'account.journal'
]._selection_online_bank_statement_provider(),
)
online_bank_statement_provider_id = fields.Many2one(
string='Statement Provider',
comodel_name='online.bank.statement.provider',
ondelete='restrict',
copy=False,
)
def __get_bank_statements_available_sources(self):
result = super().__get_bank_statements_available_sources()
result.append(('online', _('Online (OCA)')))
return result
@api.model
def _selection_online_bank_statement_provider(self):
return self.env[
'online.bank.statement.provider'
]._get_available_services() + [('dummy', 'Dummy')]
@api.model
def values_online_bank_statement_provider(self):
return self.env[
'online.bank.statement.provider'
]._get_available_services()
@api.multi
def _update_online_bank_statement_provider_id(self):
OnlineBankStatementProvider = (
self.env['online.bank.statement.provider']
)
for journal in self.filtered('id'):
provider_id = journal.online_bank_statement_provider_id
if journal.bank_statements_source != 'online':
journal.online_bank_statement_provider_id = False
if provider_id:
provider_id.unlink()
continue
if provider_id.service == journal.online_bank_statement_provider:
continue
journal.online_bank_statement_provider_id = False
if provider_id:
provider_id.unlink()
journal.online_bank_statement_provider_id = (
OnlineBankStatementProvider.create({
'journal_id': journal.id,
'service': journal.online_bank_statement_provider,
})
)
@api.model
def create(self, vals):
rec = super().create(vals)
if 'bank_statements_source' in vals \
or 'online_bank_statement_provider' in vals:
rec._update_online_bank_statement_provider_id()
return rec
@api.multi
def write(self, vals):
res = super().write(vals)
if 'bank_statements_source' in vals \
or 'online_bank_statement_provider' in vals:
self._update_online_bank_statement_provider_id()
return res
@api.multi
def action_online_bank_statements_pull_wizard(self):
provider_ids = self.mapped('online_bank_statement_provider_id').ids
return {
'name': _('Online Bank Statement Pull Wizard'),
'type': 'ir.actions.act_window',
'res_model': 'online.bank.statement.pull.wizard',
'views': [[False, 'form']],
'target': 'new',
'context': {
'default_provider_ids': [(6, False, provider_ids)],
},
}

388
account_bank_statement_import_online/models/online_bank_statement_provider.py

@ -0,0 +1,388 @@
# Copyright 2019 Brainbean Apps (https://brainbeanapps.com)
# Copyright 2019 Dataplug (https://dataplug.io)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from dateutil.relativedelta import relativedelta, MO
from decimal import Decimal
import logging
from odoo import models, fields, api, _
from odoo.addons.base.models.res_bank import sanitize_account_number
_logger = logging.getLogger(__name__)
class OnlineBankStatementProvider(models.Model):
_name = 'online.bank.statement.provider'
_inherit = ['mail.thread']
_description = 'Online Bank Statement Provider'
company_id = fields.Many2one(
related='journal_id.company_id',
store=True,
)
active = fields.Boolean()
name = fields.Char(
string='Name',
compute='_compute_name',
store=True,
)
journal_id = fields.Many2one(
comodel_name='account.journal',
required=True,
readonly=True,
ondelete='cascade',
domain=[
('type', '=', 'bank'),
],
)
currency_id = fields.Many2one(
related='journal_id.currency_id',
)
account_number = fields.Char(
related='journal_id.bank_account_id.acc_number'
)
service = fields.Selection(
selection=lambda self: self._selection_service(),
required=True,
readonly=True,
)
interval_type = fields.Selection(
selection=[
('minutes', 'Minute(s)'),
('hours', 'Hour(s)'),
('days', 'Day(s)'),
('weeks', 'Week(s)'),
],
default='hours',
required=True,
)
interval_number = fields.Integer(
string='Scheduled update interval',
default=1,
required=True,
)
update_schedule = fields.Char(
string='Update Schedule',
compute='_compute_update_schedule',
)
last_successful_run = fields.Datetime(
string='Last successful pull',
)
next_run = fields.Datetime(
string='Next scheduled pull',
default=fields.Datetime.now,
required=True,
)
statement_creation_mode = fields.Selection(
selection=[
('daily', 'Daily statements'),
('weekly', 'Weekly statements'),
('monthly', 'Monthly statements'),
],
default='daily',
required=True,
)
api_base = fields.Char()
origin = fields.Char()
username = fields.Char()
password = fields.Char()
key = fields.Binary()
certificate = fields.Binary()
passphrase = fields.Char()
certificate_public_key = fields.Text()
certificate_private_key = fields.Text()
certificate_chain = fields.Text()
_sql_constraints = [
(
'journal_id_uniq',
'UNIQUE(journal_id)',
'Only one online banking statement provider per journal!'
),
(
'valid_interval_number',
'CHECK(interval_number > 0)',
'Scheduled update interval must be greater than zero!'
)
]
@api.model
def _get_available_services(self):
"""Hook for extension"""
return []
@api.model
def _selection_service(self):
return self._get_available_services() + [('dummy', 'Dummy')]
@api.model
def values_service(self):
return self._get_available_services()
@api.multi
@api.depends('service')
def _compute_name(self):
for provider in self:
provider.name = list(filter(
lambda x: x[0] == provider.service,
self._selection_service()
))[0][1]
@api.multi
@api.depends('active', 'interval_type', 'interval_number')
def _compute_update_schedule(self):
for provider in self:
if not provider.active:
provider.update_schedule = _('Inactive')
continue
provider.update_schedule = _('%(number)s %(type)s') % {
'number': provider.interval_number,
'type': list(filter(
lambda x: x[0] == provider.interval_type,
self._fields['interval_type'].selection
))[0][1],
}
@api.multi
def _pull(self, date_since, date_until):
AccountBankStatement = self.env['account.bank.statement']
is_scheduled = self.env.context.get('scheduled')
if is_scheduled:
AccountBankStatement = AccountBankStatement.with_context(
tracking_disable=True,
)
AccountBankStatementLine = self.env['account.bank.statement.line']
for provider in self:
statement_date_since = provider._get_statement_date_since(
date_since
)
while statement_date_since < date_until:
statement_date_until = (
statement_date_since + provider._get_statement_date_step()
)
try:
data = provider._obtain_statement_data(
statement_date_since,
statement_date_until
)
except Exception as e:
if is_scheduled:
_logger.warning(
'Online Bank Statement Provider "%s" failed to'
' obtain statement data since %s until %s' % (
provider.name,
statement_date_since,
statement_date_until,
),
exc_info=True,
)
provider.message_post(
body=_(
'Online Bank Statement Provider "%s" failed to'
' obtain statement data since %s until %s:\n%s'
) % (
provider.name,
statement_date_since,
statement_date_until,
str(e),
),
subject=_(
'Online Bank Statement Provider failure'
),
)
break
raise
statement_date = provider._get_statement_date(
statement_date_since,
statement_date_until,
)
if not data:
statement_date_since = statement_date_until
continue
lines_data, statement_values = data
statement = AccountBankStatement.search([
('journal_id', '=', provider.journal_id.id),
('state', '=', 'open'),
('date', '=', statement_date),
], limit=1)
if not statement:
statement_values.update({
'name': provider.journal_id.sequence_id.with_context(
ir_sequence_date=statement_date,
).next_by_id(),
'journal_id': provider.journal_id.id,
'date': statement_date,
})
statement = AccountBankStatement.create(
# NOTE: This is needed since create() alters values
statement_values.copy()
)
filtered_lines = []
for line_values in lines_data:
date = fields.Datetime.from_string(line_values['date'])
if date < statement_date_since:
if 'balance_start' in statement_values:
statement_values['balance_start'] = (
Decimal(
statement_values['balance_start']
) + Decimal(
line_values['amount']
)
)
continue
elif date >= statement_date_until:
if 'balance_end_real' in statement_values:
statement_values['balance_end_real'] = (
Decimal(
statement_values['balance_end_real']
) - Decimal(
line_values['amount']
)
)
continue
elif date <= date_since or date > date_until:
continue
unique_import_id = line_values.get('unique_import_id')
if unique_import_id:
unique_import_id = provider._generate_unique_import_id(
unique_import_id
)
line_values.update({
'unique_import_id': unique_import_id,
})
if AccountBankStatementLine.sudo().search(
[('unique_import_id', '=', unique_import_id)],
limit=1):
continue
filtered_lines.append(line_values)
statement_values.update({
'line_ids': [[0, False, line] for line in filtered_lines],
})
if 'balance_start' in statement_values:
statement_values['balance_start'] = float(
statement_values['balance_start']
)
if 'balance_start' in statement_values:
statement_values['balance_start'] = float(
statement_values['balance_start']
)
statement.write(statement_values)
statement_date_since = statement_date_until
if is_scheduled:
provider._schedule_next_run()
@api.multi
def _schedule_next_run(self):
self.ensure_one()
self.last_successful_run = self.next_run
self.next_run += self._get_next_run_period()
@api.multi
def _get_statement_date_since(self, date):
self.ensure_one()
date = date.replace(
hour=0,
minute=0,
second=0,
microsecond=0,
)
if self.statement_creation_mode == 'daily':
return date
elif self.statement_creation_mode == 'weekly':
return date + relativedelta(weekday=MO(-1))
elif self.statement_creation_mode == 'monthly':
return date.replace(
day=1,
)
@api.multi
def _get_statement_date_step(self):
self.ensure_one()
if self.statement_creation_mode == 'daily':
return relativedelta(
days=1,
hour=0,
minute=0,
second=0,
microsecond=0,
)
elif self.statement_creation_mode == 'weekly':
return relativedelta(
weeks=1,
weekday=MO,
hour=0,
minute=0,
second=0,
microsecond=0,
)
elif self.statement_creation_mode == 'monthly':
return relativedelta(
months=1,
day=1,
hour=0,
minute=0,
second=0,
microsecond=0,
)
@api.multi
def _get_statement_date(self, date_since, date_until):
self.ensure_one()
# NOTE: Statement date is treated by Odoo as start of period. Details
# - addons/account/models/account_journal_dashboard.py
# - def get_line_graph_datas()
return date_since.date()
@api.multi
def _generate_unique_import_id(self, unique_import_id):
self.ensure_one()
sanitized_account_number = sanitize_account_number(self.account_number)
return (
sanitized_account_number and sanitized_account_number + '-' or ''
) + str(self.journal_id.id) + '-' + unique_import_id
@api.multi
def _get_next_run_period(self):
self.ensure_one()
if self.interval_type == 'minutes':
return relativedelta(minutes=self.interval_number)
elif self.interval_type == 'hours':
return relativedelta(hours=self.interval_number)
elif self.interval_type == 'days':
return relativedelta(days=self.interval_number)
elif self.interval_type == 'weeks':
return relativedelta(weeks=self.interval_number)
@api.model
def _scheduled_pull(self):
_logger.info('Scheduled pull of online bank statements...')
providers = self.search([
('active', '=', True),
('next_run', '<=', fields.Datetime.now()),
])
if providers:
_logger.info('Pulling online bank statements of: %s' % ', '.join(
providers.mapped('journal_id.name')
))
for provider in providers.with_context({'scheduled': True}):
date_since = (
provider.last_successful_run
) if provider.last_successful_run else (
provider.next_run - provider._get_next_run_period()
)
date_until = provider.next_run
provider._pull(date_since, date_until)
_logger.info('Scheduled pull of online bank statements complete.')
@api.multi
def _obtain_statement_data(
self, date_since, date_until
):
"""Hook for extension"""
# Check tests/online_bank_statement_provider_dummy.py for reference
self.ensure_one()
return []

23
account_bank_statement_import_online/readme/CONFIGURE.rst

@ -0,0 +1,23 @@
To configure online bank statements provider:
#. Go to *Invoicing > Configuration > Bank Accounts*
#. Open bank account to configure and edit it
#. Set *Bank Feeds* to *Online*
#. Select online bank statements provider in *Online Bank Statements (OCA)*
section
#. Save the bank account
#. Click on provider and configure provider-specific settings.
or, alternatively:
#. Go to *Invoicing > Overview*
#. Open settings of the corresponding journal account
#. Switch to *Bank Account* tab
#. Set *Bank Feeds* to *Online*
#. Select online bank statements provider in *Online Bank Statements (OCA)*
section
#. Save the bank account
#. Click on provider and configure provider-specific settings.
**NOTE**: To access these features, user needs to belong to
*Show Full Accounting Features* group.

1
account_bank_statement_import_online/readme/CONTRIBUTORS.rst

@ -0,0 +1 @@
* Alexey Pelykh <alexey.pelykh@brainbeanapps.com>

1
account_bank_statement_import_online/readme/DESCRIPTION.rst

@ -0,0 +1 @@
This module provides base for building online bank statements providers.

9
account_bank_statement_import_online/readme/USAGE.rst

@ -0,0 +1,9 @@
To pull historical bank statements:
#. Go to *Invoicing > Configuration > Bank Accounts*
#. Select specific bank accounts
#. Launch *Actions > Online Bank Statements Pull Wizard*
#. Configure date interval and click *Pull*
**NOTE**: To access these features, user needs to belong to
*Show Full Accounting Features* group.

3
account_bank_statement_import_online/security/ir.model.access.csv

@ -0,0 +1,3 @@
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
access_online_bank_statement_provider_admin,online.bank.statement.provider:base.group_system,model_online_bank_statement_provider,base.group_system,1,1,1,1
access_online_bank_statement_provider_user,online.bank.statement.provider:account.group_account_user,model_online_bank_statement_provider,account.group_account_user,1,1,1,1

16
account_bank_statement_import_online/security/online_bank_statement_provider.xml

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
Copyright 2019 Brainbean Apps (https://brainbeanapps.com)
Copyright 2019 Dataplug (https://dataplug.io)
-->
<odoo noupdate="1">
<record id="online_bank_statement_provider_multicompany" model="ir.rule">
<field name="name">Online Bank Statement Provider multi-company</field>
<field name="model_id" ref="model_online_bank_statement_provider"/>
<field eval="True" name="global"/>
<field name="domain_force">['|', ('company_id', '=', False), ('company_id', 'child_of', [user.company_id.id])]</field>
</record>
</odoo>

460
account_bank_statement_import_online/static/description/index.html

@ -0,0 +1,460 @@
<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="Docutils 0.14: http://docutils.sourceforge.net/" />
<title>Online Bank Statements</title>
<style type="text/css">
/*
:Author: David Goodger (goodger@python.org)
:Id: $Id: html4css1.css 7952 2016-07-26 18:15:59Z milde $
:Copyright: This stylesheet has been placed in the public domain.
Default cascading style sheet for the HTML output of Docutils.
See http://docutils.sf.net/docs/howto/html-stylesheets.html for how to
customize this style sheet.
*/
/* used to remove borders from tables and images */
.borderless, table.borderless td, table.borderless th {
border: 0 }
table.borderless td, table.borderless th {
/* Override padding for "table.docutils td" with "! important".
The right padding separates the table cells. */
padding: 0 0.5em 0 0 ! important }
.first {
/* Override more specific margin styles with "! important". */
margin-top: 0 ! important }
.last, .with-subtitle {
margin-bottom: 0 ! important }
.hidden {
display: none }
.subscript {
vertical-align: sub;
font-size: smaller }
.superscript {
vertical-align: super;
font-size: smaller }
a.toc-backref {
text-decoration: none ;
color: black }
blockquote.epigraph {
margin: 2em 5em ; }
dl.docutils dd {
margin-bottom: 0.5em }
object[type="image/svg+xml"], object[type="application/x-shockwave-flash"] {
overflow: hidden;
}
/* Uncomment (and remove this text!) to get bold-faced definition list terms
dl.docutils dt {
font-weight: bold }
*/
div.abstract {
margin: 2em 5em }
div.abstract p.topic-title {
font-weight: bold ;
text-align: center }
div.admonition, div.attention, div.caution, div.danger, div.error,
div.hint, div.important, div.note, div.tip, div.warning {
margin: 2em ;
border: medium outset ;
padding: 1em }
div.admonition p.admonition-title, div.hint p.admonition-title,
div.important p.admonition-title, div.note p.admonition-title,
div.tip p.admonition-title {
font-weight: bold ;
font-family: sans-serif }
div.attention p.admonition-title, div.caution p.admonition-title,
div.danger p.admonition-title, div.error p.admonition-title,
div.warning p.admonition-title, .code .error {
color: red ;
font-weight: bold ;
font-family: sans-serif }
/* Uncomment (and remove this text!) to get reduced vertical space in
compound paragraphs.
div.compound .compound-first, div.compound .compound-middle {
margin-bottom: 0.5em }
div.compound .compound-last, div.compound .compound-middle {
margin-top: 0.5em }
*/
div.dedication {
margin: 2em 5em ;
text-align: center ;
font-style: italic }
div.dedication p.topic-title {
font-weight: bold ;
font-style: normal }
div.figure {
margin-left: 2em ;
margin-right: 2em }
div.footer, div.header {
clear: both;
font-size: smaller }
div.line-block {
display: block ;
margin-top: 1em ;
margin-bottom: 1em }
div.line-block div.line-block {
margin-top: 0 ;
margin-bottom: 0 ;
margin-left: 1.5em }
div.sidebar {
margin: 0 0 0.5em 1em ;
border: medium outset ;
padding: 1em ;
background-color: #ffffee ;
width: 40% ;
float: right ;
clear: right }
div.sidebar p.rubric {
font-family: sans-serif ;
font-size: medium }
div.system-messages {
margin: 5em }
div.system-messages h1 {
color: red }
div.system-message {
border: medium outset ;
padding: 1em }
div.system-message p.system-message-title {
color: red ;
font-weight: bold }
div.topic {
margin: 2em }
h1.section-subtitle, h2.section-subtitle, h3.section-subtitle,
h4.section-subtitle, h5.section-subtitle, h6.section-subtitle {
margin-top: 0.4em }
h1.title {
text-align: center }
h2.subtitle {
text-align: center }
hr.docutils {
width: 75% }
img.align-left, .figure.align-left, object.align-left, table.align-left {
clear: left ;
float: left ;
margin-right: 1em }
img.align-right, .figure.align-right, object.align-right, table.align-right {
clear: right ;
float: right ;
margin-left: 1em }
img.align-center, .figure.align-center, object.align-center {
display: block;
margin-left: auto;
margin-right: auto;
}
table.align-center {
margin-left: auto;
margin-right: auto;
}
.align-left {
text-align: left }
.align-center {
clear: both ;
text-align: center }
.align-right {
text-align: right }
/* reset inner alignment in figures */
div.align-right {
text-align: inherit }
/* div.align-center * { */
/* text-align: left } */
.align-top {
vertical-align: top }
.align-middle {
vertical-align: middle }
.align-bottom {
vertical-align: bottom }
ol.simple, ul.simple {
margin-bottom: 1em }
ol.arabic {
list-style: decimal }
ol.loweralpha {
list-style: lower-alpha }
ol.upperalpha {
list-style: upper-alpha }
ol.lowerroman {
list-style: lower-roman }
ol.upperroman {
list-style: upper-roman }
p.attribution {
text-align: right ;
margin-left: 50% }
p.caption {
font-style: italic }
p.credits {
font-style: italic ;
font-size: smaller }
p.label {
white-space: nowrap }
p.rubric {
font-weight: bold ;
font-size: larger ;
color: maroon ;
text-align: center }
p.sidebar-title {
font-family: sans-serif ;
font-weight: bold ;
font-size: larger }
p.sidebar-subtitle {
font-family: sans-serif ;
font-weight: bold }
p.topic-title {
font-weight: bold }
pre.address {
margin-bottom: 0 ;
margin-top: 0 ;
font: inherit }
pre.literal-block, pre.doctest-block, pre.math, pre.code {
margin-left: 2em ;
margin-right: 2em }
pre.code .ln { color: grey; } /* line numbers */
pre.code, code { background-color: #eeeeee }
pre.code .comment, code .comment { color: #5C6576 }
pre.code .keyword, code .keyword { color: #3B0D06; font-weight: bold }
pre.code .literal.string, code .literal.string { color: #0C5404 }
pre.code .name.builtin, code .name.builtin { color: #352B84 }
pre.code .deleted, code .deleted { background-color: #DEB0A1}
pre.code .inserted, code .inserted { background-color: #A3D289}
span.classifier {
font-family: sans-serif ;
font-style: oblique }
span.classifier-delimiter {
font-family: sans-serif ;
font-weight: bold }
span.interpreted {
font-family: sans-serif }
span.option {
white-space: nowrap }
span.pre {
white-space: pre }
span.problematic {
color: red }
span.section-subtitle {
/* font-size relative to parent (h1..h6 element) */
font-size: 80% }
table.citation {
border-left: solid 1px gray;
margin-left: 1px }
table.docinfo {
margin: 2em 4em }
table.docutils {
margin-top: 0.5em ;
margin-bottom: 0.5em }
table.footnote {
border-left: solid 1px black;
margin-left: 1px }
table.docutils td, table.docutils th,
table.docinfo td, table.docinfo th {
padding-left: 0.5em ;
padding-right: 0.5em ;
vertical-align: top }
table.docutils th.field-name, table.docinfo th.docinfo-name {
font-weight: bold ;
text-align: left ;
white-space: nowrap ;
padding-left: 0 }
/* "booktabs" style (no vertical lines) */
table.docutils.booktabs {
border: 0px;
border-top: 2px solid;
border-bottom: 2px solid;
border-collapse: collapse;
}
table.docutils.booktabs * {
border: 0px;
}
table.docutils.booktabs th {
border-bottom: thin solid;
text-align: left;
}
h1 tt.docutils, h2 tt.docutils, h3 tt.docutils,
h4 tt.docutils, h5 tt.docutils, h6 tt.docutils {
font-size: 100% }
ul.auto-toc {
list-style-type: none }
</style>
</head>
<body>
<div class="document" id="online-bank-statements">
<h1 class="title">Online Bank Statements</h1>
<!-- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external" href="https://github.com/OCA/bank-statement-import/tree/12.0/account_bank_statement_import_online"><img alt="OCA/bank-statement-import" src="https://img.shields.io/badge/github-OCA%2Fbank--statement--import-lightgray.png?logo=github" /></a> <a class="reference external" href="https://translation.odoo-community.org/projects/bank-statement-import-12-0/bank-statement-import-12-0-account_bank_statement_import_online"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external" href="https://runbot.odoo-community.org/runbot/174/12.0"><img alt="Try me on Runbot" src="https://img.shields.io/badge/runbot-Try%20me-875A7B.png" /></a></p>
<p>This module provides base for building online bank statements providers.</p>
<p><strong>Table of contents</strong></p>
<div class="contents local topic" id="contents">
<ul class="simple">
<li><a class="reference internal" href="#configuration" id="id1">Configuration</a></li>
<li><a class="reference internal" href="#usage" id="id2">Usage</a></li>
<li><a class="reference internal" href="#bug-tracker" id="id3">Bug Tracker</a></li>
<li><a class="reference internal" href="#credits" id="id4">Credits</a><ul>
<li><a class="reference internal" href="#authors" id="id5">Authors</a></li>
<li><a class="reference internal" href="#contributors" id="id6">Contributors</a></li>
<li><a class="reference internal" href="#maintainers" id="id7">Maintainers</a></li>
</ul>
</li>
</ul>
</div>
<div class="section" id="configuration">
<h1><a class="toc-backref" href="#id1">Configuration</a></h1>
<p>To configure online bank statements provider:</p>
<ol class="arabic simple">
<li>Go to <em>Invoicing &gt; Configuration &gt; Bank Accounts</em></li>
<li>Open bank account to configure and edit it</li>
<li>Set <em>Bank Feeds</em> to <em>Online</em></li>
<li>Select online bank statements provider in <em>Online Bank Statements (OCA)</em>
section</li>
<li>Save the bank account</li>
<li>Click on provider and configure provider-specific settings.</li>
</ol>
<p>or, alternatively:</p>
<ol class="arabic simple">
<li>Go to <em>Invoicing &gt; Overview</em></li>
<li>Open settings of the corresponding journal account</li>
<li>Switch to <em>Bank Account</em> tab</li>
<li>Set <em>Bank Feeds</em> to <em>Online</em></li>
<li>Select online bank statements provider in <em>Online Bank Statements (OCA)</em>
section</li>
<li>Save the bank account</li>
<li>Click on provider and configure provider-specific settings.</li>
</ol>
<p><strong>NOTE</strong>: To access these features, user needs to belong to
<em>Show Full Accounting Features</em> group.</p>
</div>
<div class="section" id="usage">
<h1><a class="toc-backref" href="#id2">Usage</a></h1>
<p>To pull historical bank statements:</p>
<ol class="arabic simple">
<li>Go to <em>Invoicing &gt; Configuration &gt; Bank Accounts</em></li>
<li>Select specific bank accounts</li>
<li>Launch <em>Actions &gt; Online Bank Statements Pull Wizard</em></li>
<li>Configure date interval and click <em>Pull</em></li>
</ol>
<p><strong>NOTE</strong>: To access these features, user needs to belong to
<em>Show Full Accounting Features</em> group.</p>
</div>
<div class="section" id="bug-tracker">
<h1><a class="toc-backref" href="#id3">Bug Tracker</a></h1>
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/bank-statement-import/issues">GitHub Issues</a>.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us smashing it by providing a detailed and welcomed
<a class="reference external" href="https://github.com/OCA/bank-statement-import/issues/new?body=module:%20account_bank_statement_import_online%0Aversion:%2012.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<p>Do not contact contributors directly about support or help with technical issues.</p>
</div>
<div class="section" id="credits">
<h1><a class="toc-backref" href="#id4">Credits</a></h1>
<div class="section" id="authors">
<h2><a class="toc-backref" href="#id5">Authors</a></h2>
<ul class="simple">
<li>Brainbean Apps</li>
<li>Dataplug</li>
</ul>
</div>
<div class="section" id="contributors">
<h2><a class="toc-backref" href="#id6">Contributors</a></h2>
<ul class="simple">
<li>Alexey Pelykh &lt;<a class="reference external" href="mailto:alexey.pelykh&#64;brainbeanapps.com">alexey.pelykh&#64;brainbeanapps.com</a>&gt;</li>
</ul>
</div>
<div class="section" id="maintainers">
<h2><a class="toc-backref" href="#id7">Maintainers</a></h2>
<p>This module is maintained by the OCA.</p>
<a class="reference external image-reference" href="https://odoo-community.org"><img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" /></a>
<p>OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/bank-statement-import/tree/12.0/account_bank_statement_import_online">OCA/bank-statement-import</a> project on GitHub.</p>
<p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p>
</div>
</div>
</div>
</body>
</html>

3
account_bank_statement_import_online/tests/__init__.py

@ -0,0 +1,3 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from . import test_account_bank_statement_import_online

55
account_bank_statement_import_online/tests/online_bank_statement_provider_dummy.py

@ -0,0 +1,55 @@
# Copyright 2019 Brainbean Apps (https://brainbeanapps.com)
# Copyright 2019 Dataplug (https://dataplug.io)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from datetime import datetime, timedelta
from dateutil.relativedelta import relativedelta
from random import randrange
from odoo import models, api
class OnlineBankStatementProviderDummy(models.Model):
_inherit = 'online.bank.statement.provider'
@api.multi
def _obtain_statement_data(self, date_since, date_until):
self.ensure_one()
if self.service != 'dummy':
return super()._obtain_statement_data(
date_since,
date_until,
) # pragma: no cover
if self.env.context.get('crash', False):
raise Exception('Expected')
line_step_options = self.env.context.get('step', {
'minutes': 5,
})
line_step = relativedelta(**line_step_options)
expand_by = self.env.context.get('expand_by', 0)
date_since -= expand_by * line_step
date_until += expand_by * line_step
balance_start = randrange(-10000, 10000, 1) * 0.1
balance = balance_start
lines = []
date = date_since
while date < date_until:
amount = randrange(-100, 100, 1) * 0.1
lines.append({
'name': 'payment',
'amount': amount,
'date': date,
'unique_import_id': str(int(
(date - datetime(1970, 1, 1)) / timedelta(seconds=1)
)),
})
balance += amount
date += line_step
balance_end = balance
return lines, {
'balance_start': balance_start,
'balance_end_real': balance_end,
}

343
account_bank_statement_import_online/tests/test_account_bank_statement_import_online.py

@ -0,0 +1,343 @@
# Copyright 2019 Brainbean Apps (https://brainbeanapps.com)
# Copyright 2019 Dataplug (https://dataplug.io)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from dateutil.relativedelta import relativedelta
from psycopg2 import IntegrityError
from odoo.tests import common
from odoo.tools import mute_logger
from odoo import fields
class TestAccountBankAccountStatementImportOnline(common.TransactionCase):
def setUp(self):
super().setUp()
self.now = fields.Datetime.now()
self.AccountJournal = self.env['account.journal']
self.OnlineBankStatementProvider = self.env[
'online.bank.statement.provider'
]
self.AccountBankStatement = self.env['account.bank.statement']
self.AccountBankStatementLine = self.env['account.bank.statement.line']
def test_provider_unlink_restricted(self):
journal = self.AccountJournal.create({
'name': 'Bank',
'type': 'bank',
'code': 'BANK',
})
with common.Form(journal) as journal_form:
journal_form.bank_statements_source = 'online'
journal_form.online_bank_statement_provider = 'dummy'
journal_form.save()
with self.assertRaises(IntegrityError), mute_logger('odoo.sql_db'):
journal.online_bank_statement_provider_id.unlink()
def test_cascade_unlink(self):
journal = self.AccountJournal.create({
'name': 'Bank',
'type': 'bank',
'code': 'BANK',
})
with common.Form(journal) as journal_form:
journal_form.bank_statements_source = 'online'
journal_form.online_bank_statement_provider = 'dummy'
journal_form.save()
self.assertTrue(journal.online_bank_statement_provider_id)
journal.unlink()
self.assertFalse(self.OnlineBankStatementProvider.search([]))
def test_source_change_cleanup(self):
journal = self.AccountJournal.create({
'name': 'Bank',
'type': 'bank',
'code': 'BANK',
})
with common.Form(journal) as journal_form:
journal_form.bank_statements_source = 'online'
journal_form.online_bank_statement_provider = 'dummy'
journal_form.save()
self.assertTrue(journal.online_bank_statement_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([]))
def test_pull_boundary(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.with_context({
'expand_by': 1,
})._pull(
self.now - relativedelta(hours=1),
self.now,
)
statement = self.AccountBankStatement.search(
[('journal_id', '=', journal.id)],
)
self.assertEquals(len(statement), 1)
self.assertEquals(len(statement.line_ids), 12)
def test_pull_mode_daily(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})._pull(
self.now - relativedelta(days=1),
self.now,
)
self.assertEquals(
len(self.AccountBankStatement.search(
[('journal_id', '=', journal.id)]
)),
2
)
def test_pull_mode_weekly(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 = 'weekly'
provider.with_context(step={'hours': 8})._pull(
self.now - relativedelta(weeks=1),
self.now,
)
self.assertEquals(
len(self.AccountBankStatement.search(
[('journal_id', '=', journal.id)]
)),
2
)
def test_pull_mode_monthly(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 = 'monthly'
provider.with_context(step={'hours': 8})._pull(
self.now - relativedelta(months=1),
self.now,
)
self.assertEquals(
len(self.AccountBankStatement.search(
[('journal_id', '=', journal.id)]
)),
2
)
def test_pull_scheduled(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.next_run = (
self.now - relativedelta(days=15)
)
self.assertFalse(self.AccountBankStatement.search(
[('journal_id', '=', journal.id)],
))
provider.with_context(step={'hours': 8})._scheduled_pull()
statement = self.AccountBankStatement.search(
[('journal_id', '=', journal.id)],
)
self.assertEquals(len(statement), 1)
def test_pull_skip_duplicates_by_unique_import_id(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 = 'weekly'
provider.with_context(step={'hours': 8})._pull(
self.now - relativedelta(weeks=2),
self.now,
)
self.assertEquals(
len(self.AccountBankStatementLine.search(
[('journal_id', '=', journal.id)]
)),
14 * (24 / 8)
)
provider.with_context(step={'hours': 8})._pull(
self.now - relativedelta(weeks=3),
self.now - relativedelta(weeks=1),
)
self.assertEquals(
len(self.AccountBankStatementLine.search(
[('journal_id', '=', journal.id)]
)),
21 * (24 / 8)
)
provider.with_context(step={'hours': 8})._pull(
self.now - relativedelta(weeks=1),
self.now,
)
self.assertEquals(
len(self.AccountBankStatementLine.search(
[('journal_id', '=', journal.id)]
)),
21 * (24 / 8)
)
def test_interval_type_minutes(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.interval_type = 'minutes'
provider._compute_update_schedule()
def test_interval_type_hours(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.interval_type = 'hours'
provider._compute_update_schedule()
def test_interval_type_days(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.interval_type = 'days'
provider._compute_update_schedule()
def test_interval_type_weeks(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.interval_type = 'weeks'
provider._compute_update_schedule()
def test_pull_no_crash(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 = 'weekly'
provider.with_context(
crash=True,
scheduled=True,
)._pull(
self.now - relativedelta(hours=1),
self.now,
)
self.assertFalse(self.AccountBankStatement.search(
[('journal_id', '=', journal.id)],
))
def test_pull_crash(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 = 'weekly'
with self.assertRaises(Exception):
provider.with_context(
crash=True,
)._pull(
self.now - relativedelta(hours=1),
self.now,
)

120
account_bank_statement_import_online/views/account_journal.xml

@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright 2019 Brainbean Apps (https://brainbeanapps.com)
Copyright 2019 Dataplug (https://dataplug.io)
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
-->
<odoo>
<record model="ir.ui.view" id="view_account_journal_form">
<field name="name">account.journal.form</field>
<field name="model">account.journal</field>
<field name="inherit_id" ref="account.view_account_journal_form"/>
<field name="arch" type="xml">
<page name="bank_account">
<group
name="online_bank_statements"
string="Online Bank Statements (OCA)"
groups="account.group_account_user"
attrs="{'invisible': [('bank_statements_source', '!=', 'online')]}"
>
<label
for="online_bank_statement_provider"
string="Provider"
attrs="{'required': [('bank_statements_source', '=', 'online')]}"
class="oe_edit_only"
groups="account.group_account_user"
/>
<field
name="online_bank_statement_provider"
nolabel="1"
attrs="{'required': [('bank_statements_source', '=', 'online')]}"
class="oe_edit_only"
groups="account.group_account_user"
/>
<label
for="online_bank_statement_provider_id"
string="Provider"
attrs="{'invisible': [('online_bank_statement_provider_id', '=', False)]}"
class="oe_read_only"
/>
<field
name="online_bank_statement_provider_id"
nolabel="1"
attrs="{'invisible': [('online_bank_statement_provider_id', '=', False)]}"
class="oe_read_only"
/>
</group>
</page>
</field>
</record>
<record model="ir.ui.view" id="view_account_bank_journal_form">
<field name="name">account.journal.form</field>
<field name="model">account.journal</field>
<field name="inherit_id" ref="account.view_account_bank_journal_form"/>
<field name="arch" type="xml">
<group name="bank_statement" position="after">
<group
name="online_bank_statements"
string="Online Bank Statements (OCA)"
groups="account.group_account_user"
attrs="{'invisible': [('bank_statements_source', '!=', 'online')]}"
>
<label
for="online_bank_statement_provider"
string="Provider"
attrs="{'required': [('bank_statements_source', '=', 'online')]}"
class="oe_edit_only"
groups="account.group_account_user"
/>
<field
name="online_bank_statement_provider"
nolabel="1"
attrs="{'required': [('bank_statements_source', '=', 'online')]}"
class="oe_edit_only"
groups="account.group_account_user"
widget="dynamic_dropdown"
values="values_online_bank_statement_provider"
/>
<label
for="online_bank_statement_provider_id"
string="Provider"
attrs="{'invisible': [('online_bank_statement_provider_id', '=', False)]}"
class="oe_read_only"
/>
<field
name="online_bank_statement_provider_id"
nolabel="1"
attrs="{'invisible': [('online_bank_statement_provider_id', '=', False)]}"
class="oe_read_only"
/>
</group>
</group>
</field>
</record>
<record id="account_journal_dashboard_kanban_view" model="ir.ui.view">
<field name="name">account.journal.dashboard.kanban</field>
<field name="model">account.journal</field>
<field name="inherit_id" ref="account.account_journal_dashboard_kanban_view"/>
<field name="arch" type="xml">
<div name="bank_statement_create_button" position="attributes">
<attribute name="t-if">dashboard.bank_statements_source != 'online_sync' and dashboard.bank_statements_source != 'online'</attribute>
</div>
</field>
</record>
<record id="action_online_bank_statements_pull_wizard" model="ir.actions.server">
<field name="name">Online Bank Statements Pull Wizard</field>
<field name="type">ir.actions.server</field>
<field name="model_id" ref="account.model_account_journal"/>
<field name="binding_model_id" ref="account.model_account_journal"/>
<field name="state">code</field>
<field name="code">
if records:
action = records.action_online_bank_statements_pull_wizard()
</field>
</record>
</odoo>

96
account_bank_statement_import_online/views/online_bank_statement_provider.xml

@ -0,0 +1,96 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright 2019 Brainbean Apps (https://brainbeanapps.com)
Copyright 2019 Dataplug (https://dataplug.io)
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
-->
<odoo>
<record model="ir.ui.view" id="online_bank_statement_provider_filter">
<field name="name">online.bank.statement.provider.filter</field>
<field name="model">online.bank.statement.provider</field>
<field name="arch" type="xml">
<search string="Online Bank Statement Providers">
<filter name="active" string="Inactive" domain="[('active', '=', False)]"/>
</search>
</field>
</record>
<record model="ir.ui.view" id="online_bank_statement_provider_tree">
<field name="name">online.bank.statement.provider.tree</field>
<field name="model">online.bank.statement.provider</field>
<field name="arch" type="xml">
<tree>
<field name="journal_id"/>
<field name="company_id" groups="base.group_multi_company"/>
<field name="service"/>
<field name="currency_id"/>
<field name="update_schedule"/>
<field name="next_run"/>
</tree>
</field>
</record>
<record model="ir.ui.view" id="online_bank_statement_provider_form">
<field name="name">online.bank.statement.provider.form</field>
<field name="model">online.bank.statement.provider</field>
<field name="arch" type="xml">
<form string="Online Bank Statement Provider">
<sheet>
<div class="oe_button_box" name="button_box">
<button class="oe_stat_button" type="object" name="toggle_active" icon="fa-archive">
<field name="active" widget="boolean_button" options='{"terminology": "active"}'/>
</button>
</div>
<notebook>
<page name="details" string="Details">
<group>
<group groups="base.group_multi_company">
<field name="company_id"/>
</group>
<group>
<field name="journal_id"/>
<field name="currency_id"/>
<field name="account_number"/>
</group>
<group>
<field
name="service"
widget="dynamic_dropdown"
values="values_service"
/>
</group>
</group>
</page>
<page name="pull" string="Scheduled Pull">
<group>
<group>
<label for="interval_number"/>
<div class="o_row">
<field name="interval_number" class="ml8"/>
<field name="interval_type"/>
</div>
</group>
<group>
<field name="next_run"/>
</group>
</group>
</page>
<page name="configuration" string="Configuration">
<group>
<group>
<field name="statement_creation_mode"/>
</group>
</group>
</page>
</notebook>
</sheet>
<div class="oe_chatter">
<field name="message_follower_ids" widget="mail_followers"/>
<field name="message_ids" widget="mail_thread"/>
</div>
</form>
</field>
</record>
</odoo>

3
account_bank_statement_import_online/wizards/__init__.py

@ -0,0 +1,3 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from . import online_bank_statement_pull_wizard

34
account_bank_statement_import_online/wizards/online_bank_statement_pull_wizard.py

@ -0,0 +1,34 @@
# Copyright 2019 Brainbean Apps (https://brainbeanapps.com)
# Copyright 2019 Dataplug (https://dataplug.io)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo import fields, models, api
class OnlineBankStatementPullWizard(models.TransientModel):
_name = 'online.bank.statement.pull.wizard'
_description = 'Online Bank Statement Pull Wizard'
date_since = fields.Datetime(
string='Since',
required=True,
default=fields.Datetime.now,
)
date_until = fields.Datetime(
string='Until',
required=True,
default=fields.Datetime.now,
)
provider_ids = fields.Many2many(
string='Providers',
comodel_name='online.bank.statement.provider',
column1='wizard_id',
column2='provider_id',
relation='online_bank_statement_provider_pull_wizard_rel'
)
@api.multi
def action_pull(self):
self.ensure_one()
self.provider_ids._pull(self.date_since, self.date_until)
return {'type': 'ir.actions.act_window_close'}

32
account_bank_statement_import_online/wizards/online_bank_statement_pull_wizard.xml

@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!--
Copyright 2019 Brainbean Apps (https://brainbeanapps.com)
Copyright 2019 Dataplug (https://dataplug.io)
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
-->
<odoo>
<record id="online_bank_statement_pull_wizard_form" model="ir.ui.view">
<field name="name">online.bank.statement.pull.wizard.form</field>
<field name="model">online.bank.statement.pull.wizard</field>
<field name="arch" type="xml">
<form>
<group name="filter">
<group name="date_range" colspan="2">
<group>
<field name="date_since"/>
</group>
<group>
<field name="date_until"/>
</group>
</group>
</group>
<footer>
<button name="action_pull" string="Pull" type="object" default_focus="1" class="oe_highlight"/>
<button string="Cancel" class="oe_link" special="cancel" />
</footer>
</form>
</field>
</record>
</odoo>

1
oca_dependencies.txt

@ -0,0 +1 @@
web
Loading…
Cancel
Save