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
2.2 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. paypal_map = self.env.ref(
  35. 'account_bank_statement_import_paypal.paypal_map'
  36. )
  37. self.journal.paypal_map_id = paypal_map.id
  38. file = self._do_import('paypal_en.csv')
  39. file = base64.b64encode(file.encode("utf-8"))
  40. wizard = self.env['account.bank.statement.import'].with_context({
  41. 'journal_id': self.journal.id,
  42. }).create({'data_file': file})
  43. wizard.import_file()
  44. staments_now = self.env['account.bank.statement'].search([])
  45. statement = staments_now - old_statements
  46. self.assertEqual(len(statement.line_ids), 3)
  47. self.assertEqual(len(statement.mapped('line_ids').filtered(
  48. lambda x: x.partner_id and x.account_id)), 1)
  49. self.assertAlmostEqual(
  50. sum(statement.mapped('line_ids.amount')), 1489.2
  51. )