Skip to content

Commit

Permalink
[IMP] allow to fill in names in a more natural way
Browse files Browse the repository at this point in the history
  • Loading branch information
hbrunn committed May 15, 2018
1 parent 1d06f29 commit 8d66a52
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 29 deletions.
6 changes: 6 additions & 0 deletions l10n_nl_partner_name/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ Module Dutch Partner Name
- have initials
- split first and last name (provided by partner_firstname)

Roadmap
-------

- allow to turn on/off initials and infix separately
- add nickname (roepnaam) field to also turn on and off separately

Contributors
------------

Expand Down
4 changes: 3 additions & 1 deletion l10n_nl_partner_name/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
{
'name': 'Dutch partner names',
'version': '10.0.1.0.0',
'version': '10.0.1.1.0',
'author': 'Therp BV, Odoo Community Association (OCA)',
'category': 'Contact management',
'depends': [
'partner_firstname',
'base_view_inheritance_extension',
],
'data': [
'view/res_partner.xml',
"data/ir.config_parameter.xml",
],
'auto_install': False,
'installable': True,
Expand Down
7 changes: 7 additions & 0 deletions l10n_nl_partner_name/data/ir.config_parameter.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<odoo noupdate="1">
<record id="param_name_order" model="ir.config_parameter">
<field name="key">partner_names_order</field>
<field name="value">first_last</field>
</record>
</odoo>
8 changes: 0 additions & 8 deletions l10n_nl_partner_name/model/res_partner.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,3 @@ def _get_computed_name(self, lastname, firstname, initials=None,
'infix': infix,
})
return name if name else ''

@api.model
def _get_inverse_name(self, name, is_company=False):
result = super(ResPartner, self)._get_inverse_name(
name, is_company=is_company)
# super assumes $lastname $firstname, we want it the other way around
return dict(
result, lastname=result['firstname'], firstname=result['lastname'])
11 changes: 11 additions & 0 deletions l10n_nl_partner_name/tests/test_l10n_nl_partner_name.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,14 @@ def test_l10n_nl_partner_name(self):
})
self.assertEqual(partner.firstname, 'Willem-Alexander')
self.assertEqual(partner.lastname, 'van Oranje-Nassau')
onchange_vals = {
'lastname': 'Oranje-Nassau',
'infix': 'van',
}
partner.onchange(
onchange_vals, ['lastname', 'infix'], partner._onchange_spec(),
)
self.assertEqual(
partner.name,
'Willem-Alexander van Oranje-Nassau'
)
71 changes: 51 additions & 20 deletions l10n_nl_partner_name/view/res_partner.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,33 +7,64 @@
ref="partner_firstname.view_partner_simple_form_firstname"
/>
<field name="arch" type="xml">
<data>
<field name="lastname" position="after">
<field name="initials" />
<field name="infix" />
</field>
</data>
<xpath expr="//field[@name='name']/ancestor::h1[1]" position="inside">
<div name="partner_name_dutch" attrs="{'invisible': [('is_company', '=', True)]}">
</div>
</xpath>
<xpath expr="//field[@name='firstname']" position="move" target="//field[@name='name']/ancestor::h1[1]/div[@name='partner_name_dutch']" />
<xpath expr="//field[@name='lastname']" position="move" target="//field[@name='name']/ancestor::h1[1]/div[@name='partner_name_dutch']" />
<xpath expr="//field[@name='lastname']" position="attributes">
<attribute name="placeholder">Last name</attribute>
<attribute name="style">max-width: calc(50% - 2.1em)</attribute>
</xpath>
<xpath expr="//field[@name='firstname']" position="attributes">
<attribute name="placeholder">First name</attribute>
<attribute name="style">max-width: calc(50% - 2.1em)</attribute>
<attribute name="default_focus">1</attribute>
</xpath>
<xpath expr="//field[@name='firstname']" position="after">
<field name="initials" placeholder="Initials" class="oe_inline" style="max-width: 2em" />
</xpath>
<xpath expr="//field[@name='lastname']" position="before">
<field name="infix" placeholder="Infix" class="oe_inline" style="max-width: 2em" />
</xpath>
</field>
</record>

<record id="view_partner_form_firstname" model="ir.ui.view">
<field name="name">res.partner.form.firstname</field>
<field name="model">res.partner</field>
<field name="inherit_id" ref="partner_firstname.view_partner_form_firstname"/>
<field name="arch" type="xml">
<data>
<field name="lastname" position="after">
<field name="initials" />
<field name="infix" />
</field>
<xpath
expr="//field[@name='child_ids']/form/sheet//group/field[@name='lastname']"
position="after"
>
<field name="initials"/>
<field name="infix"/>
</xpath>
</data>
<xpath expr="//field[@name='firstname']" position="move" target="//field[@name='lastname']/ancestor::group[1]/ancestor::div[1]" />
<xpath expr="//field[@name='lastname']" position="move" target="//field[@name='lastname']/ancestor::group[1]/ancestor::div[1]" />
<xpath expr="//field[@name='lastname']/ancestor::div[1]/group" position="attributes">
<attribute name="invisible">1</attribute>
</xpath>
<xpath expr="//field[@name='lastname']/ancestor::div[1]" position="attributes">
<attribute name="attrs">{'invisible': [('is_company', '=', True)]}</attribute>
</xpath>
<xpath expr="//field[@name='lastname']" position="attributes">
<attribute name="placeholder">Last name</attribute>
<attribute name="style">max-width: calc(50% - 2.1em)</attribute>
</xpath>
<xpath expr="//field[@name='firstname']" position="attributes">
<attribute name="placeholder">First name</attribute>
<attribute name="style">max-width: calc(50% - 2.1em)</attribute>
<attribute name="default_focus">1</attribute>
</xpath>
<xpath expr="//field[@name='firstname']" position="after">
<field name="initials" placeholder="Initials" class="oe_inline" style="max-width: 2em" />
</xpath>
<xpath expr="//field[@name='lastname']" position="before">
<field name="infix" placeholder="Infix" class="oe_inline" style="max-width: 2em" />
</xpath>
<xpath
expr="//field[@name='child_ids']/form/sheet//group/field[@name='lastname']"
position="after"
>
<field name="initials"/>
<field name="infix"/>
</xpath>
</field>
</record>
</odoo>

0 comments on commit 8d66a52

Please sign in to comment.