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.

192 lines
6.3 KiB

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