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.

78 lines
2.9 KiB

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. ##############################################################################
  3. #
  4. # OpenERP, Open Source Management Solution
  5. # This module copyright (C) 2015 Therp BV <http://therp.nl>.
  6. #
  7. # This program is free software: you can redistribute it and/or modify
  8. # it under the terms of the GNU Affero General Public License as
  9. # published by the Free Software Foundation, either version 3 of the
  10. # License, or (at your option) any later version.
  11. #
  12. # This program is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU Affero General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU Affero General Public License
  18. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. #
  20. ##############################################################################
  21. import base64
  22. from openerp import api, models
  23. from openerp.tests.common import TransactionCase
  24. acc_number = 'BE1234567890'
  25. class HelloWorldParser(models.TransientModel):
  26. _inherit = 'account.bank.statement.import'
  27. @api.model
  28. def _parse_file(self, data_file):
  29. return (
  30. 'EUR',
  31. acc_number,
  32. [{
  33. 'name': '000000123',
  34. 'date': '2013-06-26',
  35. 'transactions': [{
  36. 'name': 'KBC-INVESTERINGSKREDIET 787-5562831-01',
  37. 'date': '2013-06-26',
  38. 'amount': 42,
  39. 'unique_import_id': 'hello',
  40. }],
  41. }],
  42. )
  43. class TestSaveFile(TransactionCase):
  44. def test_SaveFile(self):
  45. HelloWorldParser._build_model(self.registry, self.cr)
  46. import_wizard = self.env['account.bank.statement.import']
  47. import_wizard._prepare_setup()
  48. import_wizard._setup_base(False)
  49. import_wizard._setup_fields()
  50. import_wizard._setup_complete()
  51. import_wizard._auto_init()
  52. journal_id = self.env['res.partner.bank'].search([
  53. ('acc_number', '=', acc_number),
  54. ]).journal_id.id
  55. if not journal_id:
  56. account = import_wizard._create_bank_account(acc_number)
  57. journal_id = self.env['account.journal']\
  58. .search([
  59. '|',
  60. ('currency.name', '=', 'EUR'),
  61. ('currency', '=', False)
  62. ]).ids[0]
  63. account.journal_id = journal_id
  64. action = import_wizard.with_context(journal_id=journal_id)\
  65. .create({'data_file': base64.b64encode('hello world')})\
  66. .import_file()
  67. for statement in self.env['account.bank.statement'].browse(
  68. action['context']['statement_ids']):
  69. self.assertEqual(
  70. base64.b64decode(statement.import_file.datas),
  71. 'hello world')