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.

62 lines
2.3 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. usd = cls.env.ref('base.USD')
  14. cls.journal = cls.env['account.journal'].create({
  15. 'name': 'Paypal Bank',
  16. 'type': 'bank',
  17. 'code': 'PYPAL',
  18. 'currency_id': (
  19. usd.id if cls.env.user.company_id.currency_id != usd else False
  20. ),
  21. })
  22. def _do_import(self, file_name):
  23. file_name = os.path.join(os.path.dirname(__file__), file_name)
  24. return open(file_name).read()
  25. def test_import_header(self):
  26. file = self._do_import('paypal_en.csv')
  27. file = base64.b64encode(file.encode("utf-8"))
  28. wizard = self.env['wizard.paypal.map.create'].with_context({
  29. 'journal_id': self.journal.id,
  30. 'active_ids': [self.map.id],
  31. }).create({'data_file': file})
  32. wizard.create_map_lines()
  33. self.assertEqual(len(self.map.map_line_ids.ids), 18)
  34. def test_import_paypal_file(self):
  35. # Current statements before to run the wizard
  36. old_statements = self.env['account.bank.statement'].search([])
  37. # This journal is for Paypal statements
  38. paypal_map = self.env.ref(
  39. 'account_bank_statement_import_paypal.paypal_map'
  40. )
  41. self.journal.paypal_map_id = paypal_map.id
  42. file = self._do_import('paypal_en.csv')
  43. file = base64.b64encode(file.encode("utf-8"))
  44. wizard = self.env['account.bank.statement.import'].with_context({
  45. 'journal_id': self.journal.id,
  46. }).create({'data_file': file})
  47. wizard.import_file()
  48. staments_now = self.env['account.bank.statement'].search([])
  49. statement = staments_now - old_statements
  50. self.assertEqual(len(statement.line_ids), 3)
  51. self.assertEqual(len(statement.mapped('line_ids').filtered(
  52. lambda x: x.partner_id and x.account_id)), 1)
  53. self.assertAlmostEqual(
  54. sum(statement.mapped('line_ids.amount')), 1489.2
  55. )