You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

120 lines
4.8 KiB

  1. # Copyright 2020 Florent de Labarre
  2. # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
  3. from datetime import datetime
  4. from unittest import mock
  5. from odoo import fields
  6. from odoo.tests import common
  7. _module_ns = 'odoo.addons.account_bank_statement_import_online_qonto'
  8. _provider_class = (
  9. _module_ns
  10. + '.models.online_bank_statement_provider_qonto'
  11. + '.OnlineBankStatementProviderQonto'
  12. )
  13. class TestAccountBankAccountStatementImportOnlineQonto(
  14. common.TransactionCase
  15. ):
  16. def setUp(self):
  17. super().setUp()
  18. self.now = fields.Datetime.now()
  19. self.currency_eur = self.env.ref('base.EUR')
  20. self.currency_usd = self.env.ref('base.USD')
  21. self.AccountJournal = self.env['account.journal']
  22. self.ResPartnerBank = self.env['res.partner.bank']
  23. self.OnlineBankStatementProvider = self.env[
  24. 'online.bank.statement.provider'
  25. ]
  26. self.AccountBankStatement = self.env['account.bank.statement']
  27. self.AccountBankStatementLine = self.env['account.bank.statement.line']
  28. self.bank_account = self.ResPartnerBank.create(
  29. {'acc_number': 'FR0214508000302245362775K46',
  30. 'partner_id': self.env.user.company_id.partner_id.id})
  31. self.journal = self.AccountJournal.create({
  32. 'name': 'Bank',
  33. 'type': 'bank',
  34. 'code': 'BANK',
  35. 'currency_id': self.currency_eur.id,
  36. 'bank_statements_source': 'online',
  37. 'online_bank_statement_provider': 'qonto',
  38. 'bank_account_id': self.bank_account.id,
  39. })
  40. self.provider = self.journal.online_bank_statement_provider_id
  41. self.mock_slug = lambda: mock.patch(
  42. _provider_class + '._qonto_get_slug',
  43. return_value={'FR0214508000302245362775K46': 'qonto-1234-bank-account-1'},
  44. )
  45. self.mock_transaction = lambda: mock.patch(
  46. _provider_class + '._qonto_get_transactions',
  47. return_value={
  48. "transactions": [
  49. {"transaction_id": "qonto-1234-1-transaction-3",
  50. "amount": 1200.0,
  51. "amount_cents": 120000,
  52. "attachment_ids": [],
  53. "local_amount": 1200.0,
  54. "local_amount_cents": 120000,
  55. "side": "credit",
  56. "operation_type": "income",
  57. "currency": "EUR",
  58. "local_currency": "EUR",
  59. "label": "INVOICE A",
  60. "settled_at": "2020-04-16T07:01:55.503Z",
  61. "emitted_at": "2020-04-16T05:01:55.000Z",
  62. "updated_at": "2020-04-16T07:04:02.792Z",
  63. "status": "completed",
  64. "note": None,
  65. "reference": "Ref 1233",
  66. "vat_amount": None,
  67. "vat_amount_cents": None,
  68. "vat_rate": None,
  69. "initiator_id": None,
  70. "label_ids": [],
  71. "attachment_lost": False,
  72. "attachment_required": True},
  73. {"transaction_id": "qonto-1234-1-transaction-2",
  74. "amount": 1128.36, "amount_cents": 112836,
  75. "attachment_ids": [],
  76. "local_amount": 1128.36,
  77. "local_amount_cents": 112836,
  78. "side": "debit",
  79. "operation_type": "transfer",
  80. "currency": "EUR",
  81. "local_currency": "EUR",
  82. "label": "BILL A",
  83. "settled_at": "2020-04-16T07:00:30.979Z",
  84. "emitted_at": "2020-04-15T18:22:30.296Z",
  85. "updated_at": "2020-04-16T07:03:01.125Z",
  86. "status": "completed",
  87. "note": None,
  88. "reference": "Invoice",
  89. "vat_amount": None,
  90. "vat_amount_cents": None,
  91. "vat_rate": None,
  92. "initiator_id": "9b783957-85a6-404a-8320-a298781cb5fa",
  93. "label_ids": [],
  94. "attachment_lost": False,
  95. "attachment_required": True}],
  96. "meta": {"current_page": 1,
  97. "next_page": None,
  98. "prev_page": None,
  99. "total_pages": 1,
  100. "total_count": 2,
  101. "per_page": 100}},
  102. )
  103. def test_qonto(self):
  104. with self.mock_transaction(), self.mock_slug():
  105. lines, statement_values = self.provider._obtain_statement_data(
  106. datetime(2020, 4, 15),
  107. datetime(2020, 4, 17),
  108. )
  109. self.assertEqual(len(lines), 2)