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.

69 lines
2.6 KiB

  1. # -*- coding: utf-8 -*-
  2. # Copyright 2016 Grupo ESOC Ingeniería de Servicios, S.L.U. - Jairo Llopis
  3. # Copyright 2016 Tecnativa - Vicent Cubells
  4. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  5. from os import path
  6. from odoo.tests.common import TransactionCase
  7. PATH = path.join(path.dirname(__file__), "import_data", "%s.csv")
  8. OPTIONS = {
  9. "headers": True,
  10. "quoting": '"',
  11. "separator": ",",
  12. }
  13. class ImportCase(TransactionCase):
  14. def _base_import_record(self, res_model, file_name):
  15. """Create and return a ``base_import.import`` record."""
  16. with open(PATH % file_name) as demo_file:
  17. return self.env["base_import.import"].create({
  18. "res_model": res_model,
  19. "file": demo_file.read(),
  20. "file_name": "%s.csv" % file_name,
  21. "file_type": "csv",
  22. })
  23. def test_res_partner_vat(self):
  24. """Change name based on VAT."""
  25. agrolait = self.env.ref("base.res_partner_2")
  26. agrolait.vat = "BE0477472701"
  27. record = self._base_import_record("res.partner", "res_partner_vat")
  28. record.do(["name", "vat", "is_company"], OPTIONS)
  29. agrolait.env.invalidate_all()
  30. self.assertEqual(agrolait.name, "Agrolait Changed")
  31. def test_res_partner_parent_name_is_company(self):
  32. """Change email based on parent_id, name and is_company."""
  33. record = self._base_import_record(
  34. "res.partner", "res_partner_parent_name_is_company")
  35. record.do(["name", "is_company", "parent_id/id", "email"], OPTIONS)
  36. self.assertEqual(
  37. self.env.ref("base.res_partner_address_4").email,
  38. "changed@agrolait.example.com")
  39. def test_res_partner_email(self):
  40. """Change name based on email."""
  41. record = self._base_import_record("res.partner", "res_partner_email")
  42. record.do(["email", "name"], OPTIONS)
  43. self.assertEqual(
  44. self.env.ref("base.res_partner_address_4").name,
  45. "Michel Fletcher Changed")
  46. def test_res_partner_name(self):
  47. """Change function based on name."""
  48. record = self._base_import_record("res.partner", "res_partner_name")
  49. record.do(["function", "name"], OPTIONS)
  50. self.assertEqual(
  51. self.env.ref("base.res_partner_address_4").function,
  52. "Function Changed")
  53. def test_res_users_login(self):
  54. """Change name based on login."""
  55. record = self._base_import_record("res.users", "res_users_login")
  56. record.do(["login", "name"], OPTIONS)
  57. self.assertEqual(
  58. self.env.ref("base.user_demo").name,
  59. "Demo User Changed")