diff --git a/partner_firstname/models/partner.py b/partner_firstname/models/partner.py index 3c8c87645..b746c1fc3 100644 --- a/partner_firstname/models/partner.py +++ b/partner_firstname/models/partner.py @@ -146,7 +146,8 @@ class ResPartner(models.Model): @api.constrains("firstname", "lastname") def _check_name(self): """Ensure at least one name is set.""" - if not (self.firstname or self.lastname): + if (self.type == 'contact' or self.company_type == 'company') \ + and not (self.firstname or self.lastname): raise exceptions.EmptyNamesError(self) @api.one diff --git a/partner_firstname/tests/test_empty.py b/partner_firstname/tests/test_empty.py index 1bbdf74dd..255a3ec95 100644 --- a/partner_firstname/tests/test_empty.py +++ b/partner_firstname/tests/test_empty.py @@ -42,7 +42,7 @@ class CompanyCase(TransactionCase): class PersonCase(CompanyCase): """Test ``res.partner`` when it is a person.""" - context = {"default_is_company": False} + context = {"default_is_company": False, "default_type": 'contact'} class UserCase(CompanyCase, MailInstalled): @@ -58,3 +58,15 @@ class UserCase(CompanyCase, MailInstalled): else: # Run tests super(UserCase, self).tearDown() + + +class AddressCase(TransactionCase): + """Test ``res.partner`` when it is a address.""" + + def test_new_empty_address(self): + """Create an empty partner.""" + self.original = self.env["res.partner"].create({ + "is_company": False, + "type": 'invoice', + "lastname": "", + "firstname": ""})