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.

83 lines
3.3 KiB

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