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.

107 lines
4.4 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_external_id(self):
  25. """Change name based on External ID."""
  26. deco_addict = self.env.ref("base.res_partner_2")
  27. record = self._base_import_record("res.partner", "res_partner_external_id")
  28. record.do(["id", "vat", "name"], [], OPTIONS)
  29. deco_addict.env.cache.invalidate()
  30. self.assertEqual(deco_addict.name, "Deco Addict External ID Changed")
  31. def test_res_partner_dbid(self):
  32. """Change name based on DB ID."""
  33. deco_addict = self.env.ref("base.res_partner_2")
  34. record = self._base_import_record("res.partner", "res_partner_dbid")
  35. record.do([".id", "vat", "name"], [], OPTIONS)
  36. deco_addict.env.cache.invalidate()
  37. self.assertEqual(deco_addict.name, "Deco Addict External DBID Changed")
  38. def test_res_partner_vat(self):
  39. """Change name based on VAT."""
  40. deco_addict = self.env.ref("base.res_partner_2")
  41. deco_addict.vat = "BE0477472701"
  42. record = self._base_import_record("res.partner", "res_partner_vat")
  43. record.do(["name", "vat", "is_company"], [], OPTIONS)
  44. deco_addict.env.cache.invalidate()
  45. self.assertEqual(deco_addict.name, "Deco Addict Changed")
  46. def test_res_partner_invalid_combination_vat(self):
  47. """Change name based on VAT."""
  48. deco_addict = self.env.ref("base.res_partner_2")
  49. deco_addict.vat = "BE0477472701"
  50. record = self._base_import_record(
  51. "res.partner", "res_partner_invalid_combination_vat"
  52. )
  53. record.do(["name", "vat", "is_company"], [], OPTIONS)
  54. deco_addict.env.cache.invalidate()
  55. self.assertEqual(deco_addict.name, deco_addict.name)
  56. def test_res_partner_parent_name_is_company(self):
  57. """Change email based on parent_id, name and is_company."""
  58. record = self._base_import_record(
  59. "res.partner", "res_partner_parent_name_is_company"
  60. )
  61. record.do(["name", "is_company", "parent_id/id", "email"], [], OPTIONS)
  62. self.assertEqual(
  63. self.env.ref("base.res_partner_address_4").email,
  64. "floyd.steward34.changed@example.com",
  65. )
  66. def test_res_partner_email(self):
  67. """Change name based on email."""
  68. record = self._base_import_record("res.partner", "res_partner_email")
  69. record.do(["email", "name"], [], OPTIONS)
  70. self.assertEqual(
  71. self.env.ref("base.res_partner_address_4").name, "Floyd Steward Changed"
  72. )
  73. def test_res_partner_name(self):
  74. """Change function based on name."""
  75. record = self._base_import_record("res.partner", "res_partner_name")
  76. record.do(["function", "name"], [], OPTIONS)
  77. self.assertEqual(
  78. self.env.ref("base.res_partner_address_4").function, "Function Changed"
  79. )
  80. def test_res_partner_name_duplicated(self):
  81. """Change function based on name."""
  82. record = self._base_import_record("res.partner", "res_partner_name")
  83. partner_1 = self.env.ref("base.res_partner_address_4")
  84. partner_2 = self.env.ref("base.res_partner_2")
  85. function = partner_1.function
  86. partner_2.name = partner_1.name
  87. record.do(["function", "name"], [], OPTIONS)
  88. self.assertEqual(self.env.ref("base.res_partner_address_4").function, function)
  89. def test_res_users_login(self):
  90. """Change name based on login."""
  91. record = self._base_import_record("res.users", "res_users_login")
  92. record.do(["login", "name"], [], OPTIONS)
  93. self.assertEqual(self.env.ref("base.user_demo").name, "Demo User Changed")