mirror of
https://github.com/OCA/bank-statement-import.git
synced 2025-01-20 12:37:43 +02:00
@@ -106,6 +106,7 @@ class OnlineBankStatementProvider(models.Model):
|
||||
certificate_public_key = fields.Text()
|
||||
certificate_private_key = fields.Text()
|
||||
certificate_chain = fields.Text()
|
||||
allow_empty_statements = fields.Boolean()
|
||||
|
||||
_sql_constraints = [
|
||||
(
|
||||
@@ -219,6 +220,14 @@ class OnlineBankStatementProvider(models.Model):
|
||||
lines_data = []
|
||||
if not statement_values:
|
||||
statement_values = {}
|
||||
if (
|
||||
not lines_data
|
||||
and not statement_values
|
||||
and not self.allow_empty_statements
|
||||
):
|
||||
# Continue with next possible statement.
|
||||
statement_date_since = statement_date_until
|
||||
continue
|
||||
statement = AccountBankStatement.search([
|
||||
('journal_id', '=', provider.journal_id.id),
|
||||
('state', '=', 'open'),
|
||||
|
||||
@@ -19,5 +19,9 @@ or, alternatively:
|
||||
#. Save the bank account
|
||||
#. Click on provider and configure provider-specific settings.
|
||||
|
||||
If you want to allow empty bank statements to be created every time the
|
||||
information is pulled, you can check the option "Allow empty statements"
|
||||
at the provider configuration level.
|
||||
|
||||
**NOTE**: To access these features, user needs to belong to
|
||||
*Show Full Accounting Features* group.
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
|
||||
|
||||
from datetime import date, datetime
|
||||
from unittest import mock
|
||||
from dateutil.relativedelta import relativedelta
|
||||
from psycopg2 import IntegrityError
|
||||
from urllib.error import HTTPError
|
||||
@@ -10,6 +11,12 @@ from odoo.tests import common
|
||||
from odoo.tools import mute_logger
|
||||
from odoo import fields
|
||||
|
||||
mock_obtain_statement_data = (
|
||||
"odoo.addons.account_bank_statement_import_online.tests."
|
||||
+ "online_bank_statement_provider_dummy.OnlineBankStatementProviderDummy."
|
||||
+ "_obtain_statement_data"
|
||||
)
|
||||
|
||||
|
||||
class TestAccountBankAccountStatementImportOnline(common.TransactionCase):
|
||||
|
||||
@@ -642,3 +649,82 @@ class TestAccountBankAccountStatementImportOnline(common.TransactionCase):
|
||||
self.assertEqual(lines[1].date, date(2020, 4, 18))
|
||||
self.assertEqual(lines[2].date, date(2020, 4, 18))
|
||||
self.assertEqual(lines[3].date, date(2020, 4, 18))
|
||||
|
||||
def _get_statement_line_data(self, statement_date):
|
||||
return [
|
||||
{
|
||||
"name": "payment",
|
||||
"amount": 100,
|
||||
"date": statement_date,
|
||||
"unique_import_id": str(statement_date),
|
||||
"partner_name": "John Doe",
|
||||
"account_number": "XX00 0000 0000 0000",
|
||||
}
|
||||
], {}
|
||||
|
||||
def test_dont_create_empty_statements(self):
|
||||
"""Test the default behavior of not creating empty bank
|
||||
statements ('Allow empty statements' field is uncheck at the
|
||||
provider level.).
|
||||
"""
|
||||
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"
|
||||
with mock.patch(mock_obtain_statement_data) as mock_data:
|
||||
mock_data.side_effect = [
|
||||
self._get_statement_line_data(date(2021, 8, 10)),
|
||||
([], {}), # August 8th, doesn't have statement
|
||||
([], {}), # August 9th, doesn't have statement
|
||||
self._get_statement_line_data(date(2021, 8, 13)),
|
||||
]
|
||||
provider._pull(datetime(2021, 8, 10), datetime(2021, 8, 14))
|
||||
statements = self.AccountBankStatement.search([("journal_id", "=", journal.id)])
|
||||
self.assertEqual(len(statements), 2)
|
||||
self.assertEqual(statements[1].balance_start, 0)
|
||||
self.assertEqual(len(statements[1].line_ids), 1)
|
||||
self.assertEqual(statements[0].balance_start, 100)
|
||||
self.assertEqual(len(statements[0].line_ids), 1)
|
||||
|
||||
def test_create_empty_statements(self):
|
||||
"""Test creating empty bank statements
|
||||
('Allow empty statements' field is check at the provider level).
|
||||
"""
|
||||
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.allow_empty_statements = True
|
||||
provider.statement_creation_mode = "daily"
|
||||
with mock.patch(mock_obtain_statement_data) as mock_data:
|
||||
mock_data.side_effect = [
|
||||
self._get_statement_line_data(date(2021, 8, 10)),
|
||||
([], {}), # August 8th, doesn't have statement
|
||||
([], {}), # August 9th, doesn't have statement
|
||||
self._get_statement_line_data(date(2021, 8, 13)),
|
||||
]
|
||||
provider._pull(datetime(2021, 8, 10), datetime(2021, 8, 14))
|
||||
statements = self.AccountBankStatement.search([("journal_id", "=", journal.id)])
|
||||
# 4 Statements: 2 with movements and 2 empty
|
||||
self.assertEqual(len(statements), 4)
|
||||
# With movement
|
||||
self.assertEqual(statements[3].balance_start, 0)
|
||||
self.assertEqual(len(statements[3].line_ids), 1)
|
||||
# Empty
|
||||
self.assertEqual(statements[2].balance_start, 100)
|
||||
self.assertEqual(len(statements[2].line_ids), 0)
|
||||
|
||||
@@ -80,6 +80,7 @@
|
||||
<group>
|
||||
<field name="statement_creation_mode"/>
|
||||
<field name="tz"/>
|
||||
<field name="allow_empty_statements" />
|
||||
</group>
|
||||
</group>
|
||||
</page>
|
||||
|
||||
Reference in New Issue
Block a user