Browse Source

Fix UI problem when lastname was u"".

It should be `False` to avoid `required` errors.
pull/139/head
Jairo Llopis 10 years ago
parent
commit
e04623c793
  1. 4
      partner_firstname/models.py
  2. 23
      partner_firstname/tests/test_onchange.py

4
partner_firstname/models.py

@ -78,8 +78,8 @@ class ResPartner(models.Model):
trimmed whitespace.
"""
# Company name goes to the lastname
if self.is_company or self.name is False:
parts = [self.name, False]
if self.is_company or not self.name:
parts = [self.name or False, False]
# Guess name splitting
else:

23
partner_firstname/tests/test_onchange.py

@ -27,6 +27,29 @@ class PartnerCompanyCase(TransactionCase):
self.assertEqual(partner.firstname, False)
self.assertEqual(partner.lastname, name)
def test_empty_name_and_subnames(self):
"""If the user empties ``name``, subnames must be ``False``.
Otherwise, the ``required`` attr will not work as expected.
"""
with self.env.do_in_onchange():
# User presses ``new``
partner = self.env["res.partner"].create({})
# User ensures it is a company
partner.is_company = True
# User sets a name, which triggers onchanges
partner.name = u"Foó"
partner._onchange_name()
# User unsets name, which triggers onchanges
partner.name = u""
partner._onchange_name()
self.assertEqual(partner.firstname, False)
self.assertEqual(partner.lastname, False)
class PartnerContactCase(TransactionCase):
def test_create_from_form_only_firstname(self):

Loading…
Cancel
Save