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.

199 lines
6.9 KiB

  1. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  2. # Copyright 2015 Grupo ESOC Ingeniería de Servicios, S.L.U.
  3. # Copyright 2015 Antiun Ingenieria S.L. - Antonio Espinosa
  4. from odoo.tests.common import TransactionCase
  5. from odoo.addons.partner_firstname.tests.base import MailInstalled
  6. class CompanyCase(TransactionCase):
  7. """Test ``res.partner`` when it is a company."""
  8. def setUp(self):
  9. super(CompanyCase, self).setUp()
  10. self.env["ir.config_parameter"].set_param("partner_names_order", "first_last")
  11. def tearDown(self):
  12. try:
  13. new = self.env["res.partner"].create(
  14. {"is_company": True, "name": self.name}
  15. )
  16. # Name should be cleaned of unneeded whitespace
  17. clean_name = " ".join(self.name.split(None))
  18. # Check it's saved OK
  19. self.assertEqual(new.name, clean_name, "Saved company name is wrong.")
  20. # Check it's saved in the lastname
  21. self.assertEqual(
  22. new.lastname,
  23. clean_name,
  24. "Company name should be saved in the lastname field.",
  25. )
  26. # Check that other fields are empty
  27. self.assertEqual(
  28. new.firstname, False, "Company first name must always be empty."
  29. )
  30. self.assertEqual(
  31. new.lastname2, False, "Company last name 2 must always be empty."
  32. )
  33. finally:
  34. super(CompanyCase, self).tearDown()
  35. def test_long_name(self):
  36. """Create a company with a long name."""
  37. self.name = "Söme very lóng nâme"
  38. def test_short_name(self):
  39. """Create a company with a short name."""
  40. self.name = "Shoŕt"
  41. def test_whitespace_before(self):
  42. """Create a company with name prefixed with whitespace."""
  43. self.name = " Wĥitespace befòre"
  44. def test_whitespace_after(self):
  45. """Create a company with name suffixed with whitespace."""
  46. self.name = "Whitespâce aftér "
  47. def test_whitespace_inside(self):
  48. """Create a company with whitespace inside the name."""
  49. self.name = "Whitespacé ïnside"
  50. def test_whitespace_everywhere(self):
  51. """Create a company with whitespace everywhere in the name."""
  52. self.name = " A lot öf whitespace "
  53. class PersonCase(TransactionCase):
  54. """Test ``res.partner`` when it is a person."""
  55. model = "res.partner"
  56. context = dict()
  57. def setUp(self):
  58. super(PersonCase, self).setUp()
  59. self.env["ir.config_parameter"].set_param(
  60. "partner_names_order", "last_first_comma"
  61. )
  62. self.firstname = "Fírstname"
  63. self.lastname = "Làstname1"
  64. self.lastname2 = "Lâstname2"
  65. self.template = "%(last1)s %(last2)s, %(first)s"
  66. def tearDown(self):
  67. try:
  68. new = self.env[self.model].with_context(self.context).create(self.params)
  69. # Check that each individual field matches
  70. self.assertEqual(self.firstname, new.firstname, "First name saved badly.")
  71. self.assertEqual(self.lastname, new.lastname, "Last name 1 saved badly.")
  72. self.assertEqual(self.lastname2, new.lastname2, "Last name 2 saved badly.")
  73. # Check that name gets saved fine
  74. self.assertEqual(
  75. self.template
  76. % (
  77. {
  78. "last1": self.lastname,
  79. "last2": self.lastname2,
  80. "first": self.firstname,
  81. }
  82. ),
  83. new.name,
  84. "Name saved badly.",
  85. )
  86. finally:
  87. super(PersonCase, self).tearDown()
  88. def test_firstname_first(self):
  89. """Create a person setting his first name first."""
  90. self.env["ir.config_parameter"].set_param("partner_names_order", "first_last")
  91. self.template = "%(first)s %(last1)s %(last2)s"
  92. self.params = {
  93. "is_company": False,
  94. "name": "{} {} {}".format(self.firstname, self.lastname, self.lastname2),
  95. }
  96. def test_firstname_last(self):
  97. """Create a person setting his first name last."""
  98. self.params = {
  99. "is_company": False,
  100. "name": "{} {}, {}".format(self.lastname, self.lastname2, self.firstname),
  101. }
  102. def test_firstname_last_wo_comma(self):
  103. """Create a person setting his first name last and the order as 'last_first'"""
  104. self.env["ir.config_parameter"].set_param("partner_names_order", "last_first")
  105. self.template = "%(last1)s %(last2)s %(first)s"
  106. self.params = {
  107. "is_company": False,
  108. "name": "{} {} {}".format(self.lastname, self.lastname2, self.firstname),
  109. }
  110. def test_firstname_only(self):
  111. """Create a person setting his first name only."""
  112. self.env["ir.config_parameter"].set_param("partner_names_order", "first_last")
  113. self.firstname = self.lastname2 = False
  114. self.template = "%(last1)s"
  115. self.params = {
  116. "is_company": False,
  117. "name": self.lastname,
  118. }
  119. def test_firstname_lastname_only(self):
  120. """Create a person setting his first name and last name 1 only."""
  121. self.env["ir.config_parameter"].set_param("partner_names_order", "first_last")
  122. self.lastname2 = False
  123. self.template = "%(first)s %(last1)s"
  124. self.params = {
  125. "is_company": False,
  126. "name": "{} {}".format(self.firstname, self.lastname),
  127. }
  128. def test_lastname_firstname_only(self):
  129. """Create a person setting his last name 1 and first name only."""
  130. self.lastname2 = False
  131. self.template = "%(last1)s, %(first)s"
  132. self.params = {
  133. "is_company": False,
  134. "name": "{}, {}".format(self.lastname, self.firstname),
  135. }
  136. def test_lastname_firstname_only_wo_comma(self):
  137. """Create a person setting his last name 1 and first name only.
  138. Set order to 'last_first' to test name split without comma"""
  139. self.env["ir.config_parameter"].set_param("partner_names_order", "last_first")
  140. self.lastname2 = False
  141. self.template = "%(last1)s %(first)s"
  142. self.params = {
  143. "is_company": False,
  144. "name": "{} {}".format(self.lastname, self.firstname),
  145. }
  146. def test_separately(self):
  147. """Create a person setting separately all fields."""
  148. self.params = {
  149. "is_company": False,
  150. "firstname": self.firstname,
  151. "lastname": self.lastname,
  152. "lastname2": self.lastname2,
  153. }
  154. class UserCase(PersonCase, MailInstalled):
  155. """Test ``res.users``."""
  156. model = "res.users"
  157. context = {"default_login": "user@example.com"}
  158. def tearDown(self):
  159. # Skip if ``mail`` is installed
  160. if not self.mail_installed():
  161. super(UserCase, self).tearDown()