Browse Source

[FIX] *_online_ponto: tests should run OK now

12.0
Ronald Portier (Therp BV) 2 years ago
parent
commit
a33edfb75f
No known key found for this signature in database GPG Key ID: A181F8124D7101D3
  1. 1
      account_bank_statement_import_online_ponto/models/online_bank_statement_provider_ponto.py
  2. 3
      account_bank_statement_import_online_ponto/readme/CONTRIBUTORS.rst
  3. 62
      account_bank_statement_import_online_ponto/tests/test_account_statement_import_online_ponto.py

1
account_bank_statement_import_online_ponto/models/online_bank_statement_provider_ponto.py

@ -30,7 +30,6 @@ class OnlineBankStatementProviderPonto(models.Model):
@api.multi
def _pull(self, date_since, date_until):
"""Override pull to first retrieve data from Ponto."""
self.ensure_one()
if self.service == "ponto":
self._ponto_retrieve_data()
super()._pull(date_since, date_until)

3
account_bank_statement_import_online_ponto/readme/CONTRIBUTORS.rst

@ -2,6 +2,3 @@
* `Tecnativa <https://www.tecnativa.com>`__:
* Pedro M. Baeza
* `Therp BV <https://therp.nl>`__:
* Ronald Portier

62
account_bank_statement_import_online_ponto/tests/test_account_statement_import_online_ponto.py

@ -28,9 +28,10 @@ class TestBankAccountStatementImportOnlinePonto(common.TransactionCase):
self.AccountJournal = self.env["account.journal"]
self.ResPartnerBank = self.env["res.partner.bank"]
self.OnlineBankStatementProvider = self.env["online.bank.statement.provider"]
self.AccountAccount = self.env["account.account"]
self.AccountBankStatement = self.env["account.bank.statement"]
self.AccountBankStatementLine = self.env["account.bank.statement.line"]
self.AccStatemenPull = self.env["online.bank.statement.pull.wizard"]
self.AccountStatementPull = self.env["online.bank.statement.pull.wizard"]
self.bank_account = self.ResPartnerBank.create(
{
@ -49,6 +50,14 @@ class TestBankAccountStatementImportOnlinePonto(common.TransactionCase):
"bank_account_id": self.bank_account.id,
}
)
self.receivable_account = self.AccountAccount.create(
{
"code": "1325",
"name": "Test receivable account",
"user_type_id": self.env.ref("account.data_account_type_payable").id,
"reconcile": True,
}
)
self.provider = self.journal.online_bank_statement_provider_id
self.mock_login = lambda: mock.patch(
@ -68,9 +77,10 @@ class TestBankAccountStatementImportOnlinePonto(common.TransactionCase):
_interface_class + "._ponto_synchronisation",
return_value=None,
)
# return list of transactions on first call, empty list on second call.
self.mock_get_transactions = lambda: mock.patch(
_interface_class + "._get_transactions",
return_value=[
side_effect=[[
{
"type": "transaction",
"relationships": {
@ -143,7 +153,7 @@ class TestBankAccountStatementImportOnlinePonto(common.TransactionCase):
"amount": 5.83,
},
},
],
], [], ]
)
def test_balance_start(self):
@ -155,22 +165,23 @@ class TestBankAccountStatementImportOnlinePonto(common.TransactionCase):
line_form.name = "test move"
line_form.amount = 100
initial_statement = st_form.save()
initial_statement.button_confirm_bank() # button_post in 14.0.
with (
self.mock_login(),
self.mock_synchronisation(),
self.mock_set_access_account(),
self.mock_get_transactions()
): # noqa: B950
initial_statement.line_ids[0].account_id = self.receivable_account
initial_statement.button_confirm_bank()
with self.mock_login(), \
self.mock_synchronisation(), \
self.mock_set_access_account(), \
self.mock_get_transactions(): # noqa: B950
vals = {
"provider_ids": self.provider.ids,
"provider_ids": [(4, self.provider.id)],
"date_since": datetime(2019, 11, 4),
"date_until": datetime(2019, 11, 5),
}
wizard = self.AccStatemenPull.with_context(
wizard = self.AccountStatementPull.with_context(
active_model="account.journal",
active_id=self.journal.id,
).create(vals)
# For some reason the provider is not set in the create.
wizard.provider_ids = self.provider
wizard.action_pull()
statements = self.AccountBankStatement.search(
[("journal_id", "=", self.journal.id)]
@ -178,31 +189,36 @@ class TestBankAccountStatementImportOnlinePonto(common.TransactionCase):
new_statement = statements - initial_statement
self.assertEqual(len(new_statement.line_ids), 1)
self.assertEqual(new_statement.balance_start, 100)
self.assertEqual(new_statement.balance_end_real, 105.83)
self.assertEqual(new_statement.balance_end, 105.83)
# Ponto does not give balance info in transactions.
# self.assertEqual(new_statement.balance_end_real, 105.83)
def test_ponto(self):
with (
self.mock_login(),
self.mock_synchronisation(),
self.mock_set_access_account(),
self.mock_get_transactions()
): # noqa: B950
with self.mock_login(), \
self.mock_synchronisation(), \
self.mock_set_access_account(), \
self.mock_get_transactions(): # noqa: B950
vals = {
"provider_ids": self.provider.ids,
"provider_ids": [(4, self.provider.id)],
"date_since": datetime(2019, 11, 3),
"date_until": datetime(2019, 11, 17),
}
wizard = self.AccStatemenPull.with_context(
wizard = self.AccountStatementPull.with_context(
active_model="account.journal",
active_id=self.journal.id,
).create(vals)
# To get all the moves at once
self.provider.statement_creation_mode = "monthly"
# For some reason the provider is not set in the create.
wizard.provider_ids = self.provider
wizard.action_pull()
statement = self.AccountBankStatement.search(
[("journal_id", "=", self.journal.id)]
)
self.assertEqual(len(statement), 1)
self.assertEqual(len(statement.line_ids), 3)
self.assertEqual(statement.line_ids.mapped("amount"), [6.08, 5.48, 5.83])
self.assertEqual(statement.balance_end_real, 17.39)
sorted_amounts = sorted(statement.line_ids.mapped("amount"))
self.assertEqual(sorted_amounts, [5.48, 5.83, 6.08])
self.assertEqual(statement.balance_end, 17.39)
# Ponto does not give balance info in transactions.
# self.assertEqual(statement.balance_end_real, 17.39)
Loading…
Cancel
Save