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.

70 lines
2.7 KiB

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