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.

106 lines
3.9 KiB

  1. # Copyright 2015 Grupo ESOC <www.grupoesoc.es>
  2. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  3. """These tests try to mimic the behavior of the UI form.
  4. The form operates in onchange mode, with its limitations.
  5. """
  6. from odoo.tests.common import Form, TransactionCase
  7. from ..exceptions import EmptyNamesError
  8. class PartnerCompanyCase(TransactionCase):
  9. is_company = True
  10. def test_create_from_form(self):
  11. name = "Sôme company"
  12. with Form(self.env["res.partner"]) as partner_form:
  13. partner_form.is_company = self.is_company
  14. partner_form.name = name
  15. self.assertEqual(partner_form.name, name)
  16. self.assertEqual(partner_form.firstname, False)
  17. self.assertEqual(partner_form.lastname, name)
  18. def test_empty_name(self):
  19. """If we empty the name and save the form, EmptyNamesError must
  20. be raised (firstname and lastname are reset...)
  21. """
  22. with Form(
  23. self.env["res.partner"], view="base.view_partner_simple_form"
  24. ) as partner_form:
  25. partner_form.is_company = self.is_company
  26. name = "Foó"
  27. # User sets a name
  28. partner_form.name = name
  29. # call save to trigger the inverse
  30. partner_form.save()
  31. self.assertEqual(partner_form.name, name)
  32. self.assertEqual(partner_form.firstname, False)
  33. self.assertEqual(partner_form.lastname, name)
  34. # User unsets name
  35. partner_form.name = ""
  36. # call save to trigger the inverse and therefore raise an exception
  37. with self.assertRaises(EmptyNamesError), self.env.cr.savepoint():
  38. partner_form.save()
  39. name += " bis"
  40. partner_form.name = name
  41. partner_form.save()
  42. self.assertEqual(partner_form.name, name)
  43. self.assertEqual(partner_form.firstname, False)
  44. # assert below will fail until merge of
  45. # https://github.com/odoo/odoo/pull/45355
  46. # self.assertEqual(partner_form.lastname, name)
  47. class PartnerContactCase(TransactionCase):
  48. is_company = False
  49. def test_create_from_form_only_firstname(self):
  50. """A user creates a contact with only the firstname from the form."""
  51. firstname = "Fïrst"
  52. with Form(self.env["res.partner"]) as partner_form:
  53. partner_form.is_company = self.is_company
  54. # Changes firstname, which triggers compute
  55. partner_form.firstname = firstname
  56. self.assertEqual(partner_form.lastname, False)
  57. self.assertEqual(partner_form.firstname, firstname)
  58. self.assertEqual(partner_form.name, firstname)
  59. def test_create_from_form_only_lastname(self):
  60. """A user creates a contact with only the lastname from the form."""
  61. lastname = "Läst"
  62. with Form(self.env["res.partner"]) as partner_form:
  63. partner_form.is_company = self.is_company
  64. # Changes lastname, which triggers compute
  65. partner_form.lastname = lastname
  66. self.assertEqual(partner_form.firstname, False)
  67. self.assertEqual(partner_form.lastname, lastname)
  68. self.assertEqual(partner_form.name, lastname)
  69. def test_create_from_form_all(self):
  70. """A user creates a contact with all names from the form."""
  71. firstname = "Fïrst"
  72. lastname = "Läst"
  73. with Form(self.env["res.partner"]) as partner_form:
  74. partner_form.is_company = self.is_company
  75. # Changes firstname, which triggers compute
  76. partner_form.firstname = firstname
  77. # Changes lastname, which triggers compute
  78. partner_form.lastname = lastname
  79. self.assertEqual(partner_form.lastname, lastname)
  80. self.assertEqual(partner_form.firstname, firstname)
  81. self.assertEqual(partner_form.name, " ".join((firstname, lastname)))