Skip to content

Commit

Permalink
partner_firstname: Name is not mandatory if partner is an address
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebastien LANGE authored and yvaucher committed Jan 18, 2016
1 parent bee06e5 commit ae0d15e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
3 changes: 2 additions & 1 deletion partner_firstname/models/partner.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,8 @@ def _inverse_name(self):
@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
Expand Down
14 changes: 13 additions & 1 deletion partner_firstname/tests/test_empty.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def test_name_false(self):

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):
Expand All @@ -58,3 +58,15 @@ def tearDown(self):
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": ""})

0 comments on commit ae0d15e

Please sign in to comment.