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.

64 lines
2.6 KiB

  1. # -*- coding: utf-8 -*-
  2. # © 2017 CompassionCH <http://therp.nl>
  3. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  4. import base64
  5. from odoo.tests.common import TransactionCase
  6. from odoo.tools.misc import file_open
  7. class TestImport(TransactionCase):
  8. """Run test to import camt import."""
  9. def setUp(self):
  10. super(TestImport, self).setUp()
  11. bank = self.env['res.partner.bank'].create({
  12. 'acc_number': 'NL77ABNA0574908765',
  13. 'partner_id': self.env.ref('base.main_partner').id,
  14. 'company_id': self.env.ref('base.main_company').id,
  15. 'bank_id': self.env.ref('base.res_bank_1').id,
  16. })
  17. self.env['account.journal'].create({
  18. 'name': 'Bank Journal - (test camt)',
  19. 'code': 'TBNKCAMT',
  20. 'type': 'bank',
  21. 'bank_account_id': bank.id,
  22. })
  23. def test_statement_import(self):
  24. """Test that transaction details are correctly imported."""
  25. line_details = [
  26. {
  27. 'partner_account': 'NL69ABNA0522123643',
  28. 'partner_bic': 'ABNANL2A',
  29. 'partner_name': '3rd party Media',
  30. 'partner_address': 'SOMESTREET 570-A, 1276 ML HOUSCITY'
  31. },
  32. {
  33. 'partner_account': 'NL46ABNA0499998748',
  34. 'partner_bic': 'ABNANL2A',
  35. 'partner_name': 'Test Customer',
  36. },
  37. {
  38. 'partner_account': 'NL46ABNA0499998748',
  39. 'partner_bic': 'ABNANL2A',
  40. 'partner_name': 'INSURANCE COMPANY TESTX',
  41. 'partner_address': 'TEST STREET 20, 1234 AB TESTCITY'
  42. },
  43. ]
  44. with file_open(
  45. 'account_bank_statement_import_camt/test_files/test-camt053'
  46. ) as testfile:
  47. action = self.env['account.bank.statement.import'].create({
  48. 'data_file': base64.b64encode(testfile.read()),
  49. }).import_file()
  50. statement_lines = self.env['account.bank.statement'].browse(
  51. action['context']['statement_ids']).mapped('line_ids')
  52. for i in range(0, len(line_details)):
  53. line = statement_lines[i]
  54. rec_data = line.get_statement_line_for_reconciliation_widget()
  55. for key, val in line_details[i].iteritems():
  56. # test data is in reconcile data view
  57. if key in ('partner_account', 'partner_address'):
  58. self.assertEqual(val, rec_data.get(key))
  59. # test field is set in model
  60. self.assertEqual(getattr(line, key), val)