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.

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