diff --git a/partner_firstname/models.py b/partner_firstname/models.py index c63d48cae..e33196af7 100644 --- a/partner_firstname/models.py +++ b/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: diff --git a/partner_firstname/tests/test_onchange.py b/partner_firstname/tests/test_onchange.py index 657f9d1eb..cc30aae34 100644 --- a/partner_firstname/tests/test_onchange.py +++ b/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):