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.

54 lines
2.1 KiB

  1. # Copyright 2019 Tecnativa - Vicent Cubells
  2. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
  3. import os
  4. import base64
  5. from odoo.tests import common
  6. class TestPaypalFile(common.SavepointCase):
  7. @classmethod
  8. def setUpClass(cls):
  9. super(TestPaypalFile, cls).setUpClass()
  10. cls.map = cls.env['account.bank.statement.import.paypal.map'].create({
  11. 'name': 'Paypal Map Test',
  12. })
  13. cls.journal = cls.env['account.journal'].create({
  14. 'name': 'Paypal Bank',
  15. 'type': 'bank',
  16. 'code': 'PYPAL',
  17. })
  18. def _do_import(self, file_name):
  19. file_name = os.path.join(os.path.dirname(__file__), file_name)
  20. return open(file_name).read()
  21. def test_import_header(self):
  22. file = self._do_import('paypal_en.csv')
  23. file = base64.b64encode(file.encode("utf-8"))
  24. wizard = self.env['wizard.paypal.map.create'].with_context({
  25. 'journal_id': self.journal.id,
  26. 'active_ids': [self.map.id],
  27. }).create({'data_file': file})
  28. wizard.create_map_lines()
  29. self.assertEqual(len(self.map.map_line_ids.ids), 18)
  30. def test_import_paypal_file(self):
  31. # Current statements before to run the wizard
  32. old_statements = self.env['account.bank.statement'].search([])
  33. # This journal is for Paypal statements
  34. map = self.env.ref('account_bank_statement_import_paypal.paypal_map')
  35. self.journal.paypal_map_id = map.id
  36. file = self._do_import('paypal_en.csv')
  37. file = base64.b64encode(file.encode("utf-8"))
  38. wizard = self.env['account.bank.statement.import'].with_context({
  39. 'journal_id': self.journal.id,
  40. }).create({'data_file': file})
  41. wizard.import_file()
  42. staments_now = self.env['account.bank.statement'].search([])
  43. statement = staments_now - old_statements
  44. self.assertEqual(len(statement.line_ids), 3)
  45. self.assertEqual(len(statement.mapped('line_ids').filtered(
  46. lambda x: x.partner_id and x.account_id)), 1)
  47. self.assertAlmostEqual(sum(statement.mapped('line_ids.amount')), 489.2)