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.

76 lines
3.1 KiB

  1. # -*- coding: utf-8 -*-
  2. """Run test to import MT940 IBAN RABO import."""
  3. ##############################################################################
  4. #
  5. # Copyright (C) 2015 Therp BV <http://therp.nl>.
  6. # All other contributions are (C) by their respective contributors
  7. #
  8. # This program is free software: you can redistribute it and/or modify
  9. # it under the terms of the GNU Affero General Public License as
  10. # published by the Free Software Foundation, either version 3 of the
  11. # License, or (at your option) any later version.
  12. #
  13. # This program is distributed in the hope that it will be useful,
  14. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. # GNU Affero General Public License for more details.
  17. #
  18. # You should have received a copy of the GNU Affero General Public License
  19. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. #
  21. ##############################################################################
  22. from openerp.tests.common import TransactionCase
  23. from openerp.modules.module import get_module_resource
  24. class TestStatementFile(TransactionCase):
  25. """Run test to import MT940 RABO import."""
  26. def test_statement_import(self):
  27. """Test correct creation of single statement.
  28. For this test there is NOT an existing bank-account. Therefore a
  29. bank account should automatically be created in the main company.
  30. """
  31. partner_bank_model = self.env['res.partner.bank']
  32. import_model = self.registry('account.bank.statement.import')
  33. statement_model = self.registry('account.bank.statement')
  34. cr, uid = self.cr, self.uid
  35. statement_path = get_module_resource(
  36. 'bank_statement_parse_nl_rabo_mt940',
  37. 'test_files',
  38. 'test-rabo.swi'
  39. )
  40. statement_file = open(
  41. statement_path, 'rb').read().encode('base64')
  42. bank_statement_id = import_model.create(
  43. cr, uid,
  44. dict(
  45. data_file=statement_file,
  46. )
  47. )
  48. import_model.import_file(cr, uid, [bank_statement_id])
  49. # Check wether bank account has been created:
  50. vals = partner_bank_model.search(
  51. [('acc_number', '=', 'NL34RABO0142623393')])
  52. self.assertEquals(
  53. 1, len(vals),
  54. 'Bank account not created from statement'
  55. )
  56. # statement name is account number + '-' + date of last 62F line:
  57. ids = statement_model.search(
  58. cr, uid, [('name', '=', 'NL34RABO0142623393-2014-01-07')])
  59. self.assertTrue(ids, 'Statement not found after parse.')
  60. statement_id = ids[0]
  61. statement_obj = statement_model.browse(
  62. cr, uid, statement_id)
  63. self.assertTrue(
  64. abs(statement_obj.balance_start - 4433.52) < 0.00001,
  65. 'Start balance %f not equal to 4433.52' %
  66. statement_obj.balance_start
  67. )
  68. self.assertTrue(
  69. abs(statement_obj.balance_end_real - 4798.91) < 0.00001,
  70. 'Real end balance %f not equal to 4798.91' %
  71. statement_obj.balance_end_real
  72. )