Skip to content

Commit

Permalink
Fix users not being able to create companies.
Browse files Browse the repository at this point in the history
This happened because the invert method was not being called when using
the UI, and because lastname & firstname fields were required while
hidden.
  • Loading branch information
Jairo Llopis committed Jul 1, 2015
1 parent 87171bb commit 2494815
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 12 deletions.
6 changes: 6 additions & 0 deletions partner_firstname/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,12 @@ def _check_name(self):
if not (self.firstname or self.lastname):
raise exceptions.EmptyNamesError(self)

@api.one
@api.onchange("name")
def _onchange_name(self):
"""Ensure :attr:`~.name` is inverted in the UI."""
self._inverse_name_after_cleaning_whitespace()

@api.model
def _install_partner_firstname(self):
"""Save names correctly in the database.
Expand Down
30 changes: 18 additions & 12 deletions partner_firstname/views/res_partner.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@

<xpath expr="//field[@name='category_id']" position="before">
<group attrs="{'invisible': [('is_company', '=', True)]}">
<field name="lastname"
attrs="{'required': [('firstname', '=', False)]}"/>
<field name="firstname"
attrs="{'required': [('lastname', '=', False)]}"/>
<field name="lastname" attrs=
"{'required': [('firstname', '=', False),
('is_company', '=', False)]}"/>
<field name="firstname" attrs=
"{'required': [('lastname', '=', False),
('is_company', '=', False)]}"/>
</group>
</xpath>
</data>
Expand All @@ -42,10 +44,12 @@

<xpath expr="//field[@name='category_id']" position="before">
<group attrs="{'invisible': [('is_company', '=', True)]}">
<field name="lastname"
attrs="{'required': [('firstname', '=', False)]}"/>
<field name="firstname"
attrs="{'required': [('lastname', '=', False)]}"/>
<field name="lastname" attrs=
"{'required': [('firstname', '=', False),
('is_company', '=', False)]}"/>
<field name="firstname" attrs=
"{'required': [('lastname', '=', False),
('is_company', '=', False)]}"/>
</group>
</xpath>

Expand All @@ -54,10 +58,12 @@
//field[@name='category_id']"
position="before">
<group attrs="{'invisible': [('is_company', '=', True)]}">
<field name="lastname"
attrs="{'required': [('firstname', '=', False)]}"/>
<field name="firstname"
attrs="{'required': [('lastname', '=', False)]}"/>
<field name="lastname" attrs=
"{'required': [('firstname', '=', False),
('is_company', '=', False)]}"/>
<field name="firstname" attrs=
"{'required': [('lastname', '=', False),
('is_company', '=', False)]}"/>
</group>
</xpath>

Expand Down

0 comments on commit 2494815

Please sign in to comment.