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.

58 lines
1.9 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
  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. class HelloWorldParser(models.TransientModel):
  10. _inherit = 'account.bank.statement.import'
  11. @api.model
  12. def _parse_file(self, data_file):
  13. return (
  14. 'EUR',
  15. acc_number,
  16. [{
  17. 'name': '000000123',
  18. 'date': '2013-06-26',
  19. 'transactions': [{
  20. 'name': 'KBC-INVESTERINGSKREDIET 787-5562831-01',
  21. 'date': '2013-06-26',
  22. 'amount': 42,
  23. 'unique_import_id': 'hello',
  24. }],
  25. }],
  26. )
  27. class TestSaveFile(TransactionCase):
  28. def setUp(self):
  29. super(TestSaveFile, self).setUp()
  30. self.currency_eur_id = self.env.ref("base.EUR").id
  31. self.bank_journal_euro = self.env['account.journal'].create(
  32. {'name': 'Bank',
  33. 'type': 'bank',
  34. 'code': 'BNK_test_imp',
  35. 'currency_id': self.currency_eur_id
  36. })
  37. def test_SaveFile(self):
  38. HelloWorldParser._build_model(self.registry, self.cr)
  39. import_wizard = self.env['account.bank.statement.import']
  40. journal_id = self.bank_journal_euro.id
  41. import_wizard_id = import_wizard.with_context(journal_id=journal_id)\
  42. .create(
  43. {'data_file': base64.b64encode(bytes('Hello world'))})
  44. action = import_wizard_id.import_file()
  45. for statement in self.env['account.bank.statement'].browse(
  46. action['context']['statement_ids']):
  47. self.assertEqual(
  48. base64.b64decode(statement.import_file.datas),
  49. 'Hello world')