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.

71 lines
2.5 KiB

9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
  1. # -*- coding: utf-8 -*-
  2. # © 2015 Therp BV (<http://therp.nl>).
  3. # © 2017 Today Mourad EL HADJ MIMOUNE <mourad.elhadj.mimoune@akretion.com>
  4. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  5. import base64
  6. from odoo import api, models
  7. from odoo.tests.common import TransactionCase
  8. acc_number = 'BE1234567890'
  9. module_name = 'account_bank_statement_import_save_file'
  10. class HelloWorldParser(models.TransientModel):
  11. """ Fake parser that will return custom data if the file contains the
  12. name of the module. """
  13. _inherit = 'account.bank.statement.import'
  14. @api.model
  15. def _parse_file(self, data_file):
  16. if module_name in data_file:
  17. return self._mock_parse(data_file)
  18. else:
  19. return super(HelloWorldParser, self)._parse_file(data_file)
  20. def _mock_parse(self, data_file):
  21. """ method that can be inherited in other tests to mock a statement
  22. parser. """
  23. return (
  24. 'EUR',
  25. acc_number,
  26. [{
  27. 'name': '000000123',
  28. 'date': '2013-06-26',
  29. 'transactions': [{
  30. 'name': 'KBC-INVESTERINGSKREDIET 787-5562831-01',
  31. 'date': '2013-06-26',
  32. 'amount': 42,
  33. 'unique_import_id': 'hello',
  34. }],
  35. }],
  36. )
  37. class TestSaveFile(TransactionCase):
  38. def setUp(self):
  39. super(TestSaveFile, self).setUp()
  40. self.currency_eur_id = self.env.ref("base.EUR").id
  41. self.bank_journal_euro = self.env['account.journal'].create(
  42. {'name': 'Bank',
  43. 'type': 'bank',
  44. 'code': 'BNK_test_imp',
  45. 'currency_id': self.currency_eur_id
  46. })
  47. def test_SaveFile(self):
  48. HelloWorldParser._build_model(self.registry, self.cr)
  49. import_wizard = self.env['account.bank.statement.import']
  50. journal_id = self.bank_journal_euro.id
  51. import_wizard_id = import_wizard.with_context(journal_id=journal_id)\
  52. .create({
  53. 'data_file': base64.b64encode(bytes(
  54. 'account_bank_statement_import_save_file: Hello world'))
  55. })
  56. action = import_wizard_id.import_file()
  57. for statement in self.env['account.bank.statement'].browse(
  58. action['context']['statement_ids']):
  59. self.assertEqual(
  60. base64.b64decode(statement.import_file.datas),
  61. 'account_bank_statement_import_save_file: Hello world')