mirror of
https://github.com/OCA/bank-statement-import.git
synced 2025-01-20 12:37:43 +02:00
[IMP] account_statement_import_online: don't import empty statements.
This commit is contained in:
@@ -56,6 +56,10 @@ or, alternatively:
|
|||||||
#. Save the bank account
|
#. Save the bank account
|
||||||
#. Click on provider and configure provider-specific settings.
|
#. 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
|
**NOTE**: To access these features, user needs to belong to
|
||||||
*Show Full Accounting Features* group.
|
*Show Full Accounting Features* group.
|
||||||
|
|
||||||
|
|||||||
@@ -95,6 +95,7 @@ class OnlineBankStatementProvider(models.Model):
|
|||||||
certificate_public_key = fields.Text()
|
certificate_public_key = fields.Text()
|
||||||
certificate_private_key = fields.Text()
|
certificate_private_key = fields.Text()
|
||||||
certificate_chain = fields.Text()
|
certificate_chain = fields.Text()
|
||||||
|
allow_empty_statements = fields.Boolean(string="Allow empty statements")
|
||||||
|
|
||||||
_sql_constraints = [
|
_sql_constraints = [
|
||||||
(
|
(
|
||||||
@@ -204,6 +205,8 @@ class OnlineBankStatementProvider(models.Model):
|
|||||||
)
|
)
|
||||||
if not data:
|
if not data:
|
||||||
data = ([], {})
|
data = ([], {})
|
||||||
|
if not data[0] and not data[1] and not self.allow_empty_statements:
|
||||||
|
return
|
||||||
lines_data, statement_values = data
|
lines_data, statement_values = data
|
||||||
if not lines_data:
|
if not lines_data:
|
||||||
lines_data = []
|
lines_data = []
|
||||||
|
|||||||
@@ -19,5 +19,9 @@ or, alternatively:
|
|||||||
#. Save the bank account
|
#. Save the bank account
|
||||||
#. Click on provider and configure provider-specific settings.
|
#. 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
|
**NOTE**: To access these features, user needs to belong to
|
||||||
*Show Full Accounting Features* group.
|
*Show Full Accounting Features* group.
|
||||||
|
|||||||
@@ -406,6 +406,9 @@ section</li>
|
|||||||
<li>Save the bank account</li>
|
<li>Save the bank account</li>
|
||||||
<li>Click on provider and configure provider-specific settings.</li>
|
<li>Click on provider and configure provider-specific settings.</li>
|
||||||
</ol>
|
</ol>
|
||||||
|
<p>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.</p>
|
||||||
<p><strong>NOTE</strong>: To access these features, user needs to belong to
|
<p><strong>NOTE</strong>: To access these features, user needs to belong to
|
||||||
<em>Show Full Accounting Features</em> group.</p>
|
<em>Show Full Accounting Features</em> group.</p>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
# 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 datetime import date, datetime
|
from datetime import date, datetime
|
||||||
|
from unittest import mock
|
||||||
from urllib.error import HTTPError
|
from urllib.error import HTTPError
|
||||||
|
|
||||||
from dateutil.relativedelta import relativedelta
|
from dateutil.relativedelta import relativedelta
|
||||||
@@ -12,6 +13,12 @@ from odoo import fields
|
|||||||
from odoo.tests import common
|
from odoo.tests import common
|
||||||
from odoo.tools import mute_logger
|
from odoo.tools import mute_logger
|
||||||
|
|
||||||
|
mock_obtain_statement_data = (
|
||||||
|
"odoo.addons.account_statement_import_online.tests."
|
||||||
|
+ "online_bank_statement_provider_dummy.OnlineBankStatementProviderDummy."
|
||||||
|
+ "_obtain_statement_data"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class TestAccountBankAccountStatementImportOnline(common.TransactionCase):
|
class TestAccountBankAccountStatementImportOnline(common.TransactionCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
@@ -657,3 +664,94 @@ class TestAccountBankAccountStatementImportOnline(common.TransactionCase):
|
|||||||
self.assertEqual(lines[1].date, date(2020, 4, 18))
|
self.assertEqual(lines[1].date, date(2020, 4, 18))
|
||||||
self.assertEqual(lines[2].date, date(2020, 4, 18))
|
self.assertEqual(lines[2].date, date(2020, 4, 18))
|
||||||
self.assertEqual(lines[3].date, date(2020, 4, 18))
|
self.assertEqual(lines[3].date, date(2020, 4, 18))
|
||||||
|
|
||||||
|
def _get_statement_line_data(self, statement_date):
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
"payment_ref": "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(statements[1].balance_end_real, 100)
|
||||||
|
self.assertEqual(len(statements[1].line_ids), 1)
|
||||||
|
self.assertEqual(statements[0].balance_start, 100)
|
||||||
|
self.assertEqual(statements[0].balance_end_real, 200)
|
||||||
|
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(statements[3].balance_end_real, 100)
|
||||||
|
self.assertEqual(len(statements[3].line_ids), 1)
|
||||||
|
# Empty
|
||||||
|
self.assertEqual(statements[2].balance_start, 100)
|
||||||
|
self.assertEqual(statements[2].balance_end_real, 100)
|
||||||
|
self.assertEqual(len(statements[2].line_ids), 0)
|
||||||
|
# Empty
|
||||||
|
self.assertEqual(statements[1].balance_start, 100)
|
||||||
|
self.assertEqual(statements[1].balance_end_real, 100)
|
||||||
|
self.assertEqual(len(statements[1].line_ids), 0)
|
||||||
|
# With movement
|
||||||
|
self.assertEqual(statements[0].balance_start, 100)
|
||||||
|
self.assertEqual(statements[0].balance_end_real, 200)
|
||||||
|
self.assertEqual(len(statements[0].line_ids), 1)
|
||||||
|
|||||||
@@ -79,6 +79,7 @@
|
|||||||
<group name="configuration" string="Configuration">
|
<group name="configuration" string="Configuration">
|
||||||
<field name="statement_creation_mode" />
|
<field name="statement_creation_mode" />
|
||||||
<field name="tz" />
|
<field name="tz" />
|
||||||
|
<field name="allow_empty_statements" />
|
||||||
</group>
|
</group>
|
||||||
</group>
|
</group>
|
||||||
</sheet>
|
</sheet>
|
||||||
|
|||||||
Reference in New Issue
Block a user