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.

69 lines
2.5 KiB

  1. # -*- coding: utf-8 -*-
  2. """Run test to import camt.053 import."""
  3. # © 2013-2016 Therp BV <http://therp.nl>
  4. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  5. import base64
  6. from odoo.tests.common import TransactionCase
  7. from odoo.tools.misc import file_open
  8. class TestImport(TransactionCase):
  9. """Run test to import camt import."""
  10. transactions = [
  11. {
  12. 'account_number': 'NL46ABNA0499998748',
  13. 'amount': -754.25,
  14. 'date': '2014-01-05',
  15. 'ref': '435005714488-ABNO33052620',
  16. },
  17. ]
  18. def setUp(self):
  19. super(TestImport, self).setUp()
  20. bank = self.env['res.partner.bank'].create({
  21. 'acc_number': 'NL77ABNA0574908765',
  22. 'partner_id': self.env.ref('base.main_partner').id,
  23. 'company_id': self.env.ref('base.main_company').id,
  24. 'bank_id': self.env.ref('base.res_bank_1').id,
  25. })
  26. self.env['account.journal'].create({
  27. 'name': 'Bank Journal - (test camt)',
  28. 'code': 'TBNKCAMT',
  29. 'type': 'bank',
  30. 'bank_account_id': bank.id,
  31. })
  32. def test_statement_import(self):
  33. """Test correct creation of single statement."""
  34. action = {}
  35. with file_open(
  36. 'account_bank_statement_import_camt/test_files/test-camt053'
  37. ) as testfile:
  38. action = self.env['account.bank.statement.import'].create({
  39. 'data_file': base64.b64encode(testfile.read()),
  40. }).import_file()
  41. for statement in self.env['account.bank.statement'].browse(
  42. action['context']['statement_ids']
  43. ):
  44. self.assertTrue(any(
  45. all(
  46. line[key] == self.transactions[0][key]
  47. for key in ['amount', 'date', 'ref']
  48. ) and
  49. line.bank_account_id.acc_number ==
  50. self.transactions[0]['account_number']
  51. for line in statement.line_ids
  52. ))
  53. def test_zip_import(self):
  54. """Test import of multiple statements from zip file."""
  55. with file_open(
  56. 'account_bank_statement_import_camt/test_files/test-camt053.zip'
  57. ) as testfile:
  58. action = self.env['account.bank.statement.import'].create({
  59. 'data_file': base64.b64encode(testfile.read()),
  60. }).import_file()
  61. for statement in self.env['account.bank.statement'].browse(
  62. action['context']['statement_ids']
  63. ):
  64. self.assertTrue(statement.line_ids)