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.

215 lines
7.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_last_wo_comma(self):
  117. """Create a person setting his first name last and the order as 'last_first'"""
  118. self.env['ir.config_parameter'].set_param(
  119. 'partner_names_order', 'last_first')
  120. self.template = "%(last1)s %(last2)s %(first)s"
  121. self.params = {
  122. "is_company": False,
  123. "name": "%s %s %s" % (self.lastname,
  124. self.lastname2,
  125. self.firstname),
  126. }
  127. def test_firstname_only(self):
  128. """Create a person setting his first name only."""
  129. self.env['ir.config_parameter'].set_param(
  130. 'partner_names_order', 'first_last')
  131. self.firstname = self.lastname2 = False
  132. self.template = "%(last1)s"
  133. self.params = {
  134. "is_company": False,
  135. "name": self.lastname,
  136. }
  137. def test_firstname_lastname_only(self):
  138. """Create a person setting his first name and last name 1 only."""
  139. self.env['ir.config_parameter'].set_param(
  140. 'partner_names_order', 'first_last')
  141. self.lastname2 = False
  142. self.template = "%(first)s %(last1)s"
  143. self.params = {
  144. "is_company": False,
  145. "name": "%s %s" % (self.firstname, self.lastname),
  146. }
  147. def test_lastname_firstname_only(self):
  148. """Create a person setting his last name 1 and first name only."""
  149. self.lastname2 = False
  150. self.template = "%(last1)s, %(first)s"
  151. self.params = {
  152. "is_company": False,
  153. "name": "%s, %s" % (self.lastname, self.firstname),
  154. }
  155. def test_lastname_firstname_only_wo_comma(self):
  156. """Create a person setting his last name 1 and first name only.
  157. Set order to 'last_first' to test name split without comma"""
  158. self.env['ir.config_parameter'].set_param(
  159. 'partner_names_order', 'last_first')
  160. self.lastname2 = False
  161. self.template = "%(last1)s %(first)s"
  162. self.params = {
  163. "is_company": False,
  164. "name": "%s %s" % (self.lastname, self.firstname),
  165. }
  166. def test_separately(self):
  167. """Create a person setting separately all fields."""
  168. self.params = {
  169. "is_company": False,
  170. "firstname": self.firstname,
  171. "lastname": self.lastname,
  172. "lastname2": self.lastname2,
  173. }
  174. class UserCase(PersonCase, MailInstalled):
  175. """Test ``res.users``."""
  176. model = "res.users"
  177. context = {"default_login": "user@example.com"}
  178. def tearDown(self):
  179. # Skip if ``mail`` is installed
  180. if not self.mail_installed():
  181. super(UserCase, self).tearDown()