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.

91 lines
3.9 KiB

  1. # -*- coding: utf-8 -*-
  2. ##############################################################################
  3. #
  4. # This file is part of account_bank_statement_import,
  5. # an Odoo module.
  6. #
  7. # Copyright (c) 2015 ACSONE SA/NV (<http://acsone.eu>)
  8. #
  9. # account_bank_statement_import is free software:
  10. # you can redistribute it and/or modify it under the terms of the GNU
  11. # Affero General Public License as published by the Free Software
  12. # Foundation,either version 3 of the License, or (at your option) any
  13. # later version.
  14. #
  15. # account_bank_statement_import is distributed
  16. # in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
  17. # even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  18. # PURPOSE. See the GNU Affero General Public License for more details.
  19. #
  20. # You should have received a copy of the GNU Affero General Public License
  21. # along with account_bank_statement_import_coda.
  22. # If not, see <http://www.gnu.org/licenses/>.
  23. #
  24. ##############################################################################
  25. from openerp.tests.common import TransactionCase
  26. from openerp.exceptions import Warning as UserError
  27. class TestAccountBankStatementImport(TransactionCase):
  28. """Tests for import bank statement file import
  29. (account.bank.statement.import)
  30. """
  31. def setUp(self):
  32. super(TestAccountBankStatementImport, self).setUp()
  33. self.statement_import_model = self.env[
  34. 'account.bank.statement.import']
  35. self.account_journal_model = self.env['account.journal']
  36. self.res_users_model = self.env['res.users']
  37. self.journal_id = self.ref('account.bank_journal')
  38. self.base_user_root_id = self.ref('base.user_root')
  39. self.base_user_root = self.res_users_model.browse(
  40. self.base_user_root_id)
  41. # create a new user that belongs to the same company as
  42. # user_root
  43. self.other_partner_id = self.env['res.partner'].create(
  44. {"name": "My other partner",
  45. "is_company": False,
  46. "email": "test@tes.ttest",
  47. })
  48. self.company_id = self.base_user_root.company_id.id
  49. self.other_user_id_a = self.res_users_model.create(
  50. {"partner_id": self.other_partner_id.id,
  51. "company_id": self.company_id,
  52. "company_ids": [(4, self.company_id)],
  53. "login": "my_login a",
  54. "name": "my user",
  55. "groups_id": [(4, self.ref('account.group_account_manager'))]
  56. })
  57. def test_import_preconditions(self):
  58. """Checks that the import raises an exception if:
  59. * no bank account found for the account_number
  60. * no account_journal found on the bank_account
  61. """
  62. stmt_vals = {
  63. 'currency_code': 'EUR',
  64. 'account_number': '123456789'}
  65. with self.assertRaises(UserError) as e:
  66. self.statement_import_model._import_statement(stmt_vals.copy())
  67. self.assertEqual(e.exception.message,
  68. 'Can not find the account number 123456789.')
  69. self.statement_import_model._create_bank_account('123456789')
  70. with self.assertRaises(UserError) as e:
  71. self.statement_import_model._import_statement(stmt_vals.copy())
  72. self.assertEqual(
  73. e.exception.message[:25], 'Can not determine journal'
  74. )
  75. def test_create_bank_account(self):
  76. """Checks that the bank_account created by the import belongs to the
  77. partner linked to the company of the provided journal
  78. """
  79. journal = self.account_journal_model.browse(self.journal_id)
  80. expected_id = journal.company_id.partner_id.id
  81. st_import = self.statement_import_model.sudo(self.other_user_id_a.id)
  82. bank = st_import._create_bank_account(
  83. '001251882303', company_id=self.company_id)
  84. self.assertEqual(bank.partner_id.id, expected_id)