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.

103 lines
3.8 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. self.assertEqual(partner_form.lastname, name)
  45. class PartnerContactCase(TransactionCase):
  46. is_company = False
  47. def test_create_from_form_only_firstname(self):
  48. """A user creates a contact with only the firstname from the form."""
  49. firstname = "Fïrst"
  50. with Form(self.env["res.partner"]) as partner_form:
  51. partner_form.is_company = self.is_company
  52. # Changes firstname, which triggers compute
  53. partner_form.firstname = firstname
  54. self.assertEqual(partner_form.lastname, False)
  55. self.assertEqual(partner_form.firstname, firstname)
  56. self.assertEqual(partner_form.name, firstname)
  57. def test_create_from_form_only_lastname(self):
  58. """A user creates a contact with only the lastname from the form."""
  59. lastname = "Läst"
  60. with Form(self.env["res.partner"]) as partner_form:
  61. partner_form.is_company = self.is_company
  62. # Changes lastname, which triggers compute
  63. partner_form.lastname = lastname
  64. self.assertEqual(partner_form.firstname, False)
  65. self.assertEqual(partner_form.lastname, lastname)
  66. self.assertEqual(partner_form.name, lastname)
  67. def test_create_from_form_all(self):
  68. """A user creates a contact with all names from the form."""
  69. firstname = "Fïrst"
  70. lastname = "Läst"
  71. with Form(self.env["res.partner"]) as partner_form:
  72. partner_form.is_company = self.is_company
  73. # Changes firstname, which triggers compute
  74. partner_form.firstname = firstname
  75. # Changes lastname, which triggers compute
  76. partner_form.lastname = lastname
  77. self.assertEqual(partner_form.lastname, lastname)
  78. self.assertEqual(partner_form.firstname, firstname)
  79. self.assertEqual(partner_form.name, " ".join((firstname, lastname)))