Skip to content

Commit

Permalink
Merge pull request #153 from grupoesoc/partner_lastname2
Browse files Browse the repository at this point in the history
Partner lastname 2
  • Loading branch information
rafaelbn committed Oct 29, 2015
2 parents 094d7d7 + 5b87a26 commit 3124dd4
Show file tree
Hide file tree
Showing 15 changed files with 877 additions and 8 deletions.
3 changes: 2 additions & 1 deletion partner_firstname/__openerp__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
'name': 'Partner first name and last name',
'summary': "Split first name and last name for non company partners",
'version': '8.0.2.0.0',
'author': "Camptocamp,Odoo Community Association (OCA)",
'author': "Camptocamp, Odoo Community Association (OCA)",
"license": "AGPL-3",
'maintainer': 'Camptocamp, Acsone',
'category': 'Extra Tools',
'website': 'http://www.camptocamp.com, http://www.acsone.eu',
Expand Down
3 changes: 1 addition & 2 deletions partner_firstname/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# -*- encoding: utf-8 -*-

# -*- coding: utf-8 -*-
# Odoo, Open Source Management Solution
# Copyright (C) 2014-2015 Grupo ESOC <www.grupoesoc.es>
#
Expand Down
7 changes: 4 additions & 3 deletions partner_firstname/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def _inverse_name_after_cleaning_whitespace(self):

@api.model
def _get_inverse_name(self, name, is_company=False):
"""Try to revert the effect of :meth:`._compute_name`.
"""Compute the inverted name.
- If the partner is a company, save it in the lastname.
- Otherwise, make a guess.
Expand All @@ -93,12 +93,13 @@ def _get_inverse_name(self, name, is_company=False):
parts = name.split(" ", 1)
while len(parts) < 2:
parts.append(False)
return parts
return {"lastname": parts[0], "firstname": parts[1]}

@api.one
def _inverse_name(self):
"""Try to revert the effect of :meth:`._compute_name`."""
parts = self._get_inverse_name(self.name, self.is_company)
self.lastname, self.firstname = parts
self.lastname, self.firstname = parts["lastname"], parts["firstname"]

@api.one
@api.constrains("firstname", "lastname")
Expand Down
3 changes: 1 addition & 2 deletions partner_firstname/tests/test_empty.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# -*- encoding: utf-8 -*-

# -*- coding: utf-8 -*-
# Odoo, Open Source Management Solution
# Copyright (C) 2014-2015 Grupo ESOC <www.grupoesoc.es>
#
Expand Down
72 changes: 72 additions & 0 deletions partner_second_lastname/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
:alt: License: AGPL-3

Partner second lastname
=======================

This module was written to extend the functionality of ``partner_firstname`` to
support having a second lastname for contact partners.

In some countries, it's important to have a second last name for contacts.

Contact partners will need to fulfill at least one of the name fields
(*First name*, *First last name* or *Second last name*).

Usage
=====

To use this module, you need to:

* Edit any partner's form.
* Make sure the partner is not a company.
* Enter firstname and lastnames.

If you directly enter the full name instead of entering the other fields
separately (maybe from other form), this module will try to guess the best
match for your input and split it between firstname, lastname and second
lastname.

If the name you enter is in the form *Firstname Lastname1 Lastname2*, it will
be split as such. If you use a comma, it will understand it as *Lastname1
Lastname2, Firstname*.

If you can, always enter it manually please. Automatic guessing could fail for
you easily in some corner cases.

.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
:alt: Try me on Runbot
:target: https://runbot.odoo-community.org/runbot/134/8.0

Bug Tracker
===========

Bugs are tracked on `GitHub Issues
<https://github.com/OCA/partner-contact/issues>`_. In case of trouble, please
check there if your issue has already been reported. If you spotted it first,
help us smashing it by providing a detailed and welcomed feedback `here
<https://github.com/OCA/partner-contact/issues/new?body=module:%20partner_second_lastname%0Aversion:%208.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.


Credits
=======

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

* `Grupo ESOC <http://grupoesoc.es>`_:
* `Jairo Llopis <mailto:j.llopis@grupoesoc.es>`_.

Maintainer
----------

.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org

This module is maintained by the OCA.

OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.

To contribute to this module, please visit http://odoo-community.org.
5 changes: 5 additions & 0 deletions partner_second_lastname/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# -*- coding: utf-8 -*-
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
# © 2015 Grupo ESOC Ingeniería de Servicios, S.L.U.

from . import models
21 changes: 21 additions & 0 deletions partner_second_lastname/__openerp__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# -*- coding: utf-8 -*-
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
# © 2015 Grupo ESOC Ingeniería de Servicios, S.L.U.

{
"name": "Partner second last name",
"version": "8.0.4.0.0",
"author": "Grupo ESOC, Odoo Community Association (OCA)",
"license": "AGPL-3",
"maintainer": "Odoo Community Association (OCA)",
"category": "Extra Tools",
"website": "http://www.grupoesoc.es",
"depends": [
"partner_firstname"
],
"data": [
"views/res_partner.xml",
"views/res_user.xml",
],
"installable": True,
}
68 changes: 68 additions & 0 deletions partner_second_lastname/i18n/es.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * partner_lastname2
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 8.0-20150327\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2015-08-13 11:16+0100\n"
"PO-Revision-Date: 2015-08-13 11:16+0100\n"
"Last-Translator: Jairo Llopis <j.llopis@grupoesoc.es>\n"
"Language-Team: \n"
"Language: es_ES\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
"X-Generator: Poedit 1.8.1\n"

#. module: partner_second_lastname
#: model:ir.model,name:partner_second_lastname.model_res_partner
msgid "Partner"
msgstr "Empresa"

#. module: partner_second_lastname
#: field:res.partner,lastname2:0
msgid "Second last name"
msgstr "Segundo apellido"

#. module: partner_second_lastname
#: view:res.partner:partner_second_lastname.partner_form
#: view:res.partner:partner_second_lastname.partner_simple_form
msgid ""
"{\n"
" 'required': [('firstname', '=', False),\n"
" ('lastname2', '=', False),\n"
" ('is_company', '=', False)]\n"
" }"
msgstr ""

#. module: partner_second_lastname
#: view:res.users:partner_second_lastname.users_form
msgid ""
"{\n"
" 'required': [('firstname', '=', False),\n"
" ('lastname2', '=', False)]\n"
" }"
msgstr ""

#. module: partner_second_lastname
#: view:res.partner:partner_second_lastname.partner_form
#: view:res.partner:partner_second_lastname.partner_simple_form
msgid ""
"{\n"
" 'required': [('lastname', '=', False),\n"
" ('lastname2', '=', False),\n"
" ('is_company', '=', False)]\n"
" }"
msgstr ""

#. module: partner_second_lastname
#: view:res.users:partner_second_lastname.users_form
msgid ""
"{\n"
" 'required': [('lastname', '=', False),\n"
" ('lastname2', '=', False)]\n"
" }"
msgstr ""
63 changes: 63 additions & 0 deletions partner_second_lastname/i18n/partner_second_lastname.pot
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * partner_second_lastname
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 8.0-20150811\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2015-08-13 09:15+0000\n"
"PO-Revision-Date: 2015-08-13 09:15+0000\n"
"Last-Translator: <>\n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: \n"

#. module: partner_second_lastname
#: model:ir.model,name:partner_second_lastname.model_res_partner
msgid "Partner"
msgstr ""

#. module: partner_second_lastname
#: field:res.partner,lastname2:0
msgid "Second last name"
msgstr ""

#. module: partner_second_lastname
#: view:res.partner:partner_second_lastname.partner_form
#: view:res.partner:partner_second_lastname.partner_simple_form
msgid "{\n"
" 'required': [('firstname', '=', False),\n"
" ('lastname2', '=', False),\n"
" ('is_company', '=', False)]\n"
" }"
msgstr ""

#. module: partner_second_lastname
#: view:res.users:partner_second_lastname.users_form
msgid "{\n"
" 'required': [('firstname', '=', False),\n"
" ('lastname2', '=', False)]\n"
" }"
msgstr ""

#. module: partner_second_lastname
#: view:res.partner:partner_second_lastname.partner_form
#: view:res.partner:partner_second_lastname.partner_simple_form
msgid "{\n"
" 'required': [('lastname', '=', False),\n"
" ('lastname2', '=', False),\n"
" ('is_company', '=', False)]\n"
" }"
msgstr ""

#. module: partner_second_lastname
#: view:res.users:partner_second_lastname.users_form
msgid "{\n"
" 'required': [('lastname', '=', False),\n"
" ('lastname2', '=', False)]\n"
" }"
msgstr ""

97 changes: 97 additions & 0 deletions partner_second_lastname/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
# -*- coding: utf-8 -*-
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
# © 2015 Grupo ESOC Ingeniería de Servicios, S.L.U.

from openerp import api, fields, models
from openerp.addons.partner_firstname import exceptions


class ResPartner(models.Model):
"""Adds a second last name."""

_inherit = "res.partner"

lastname2 = fields.Char("Second last name")

@api.model
def _get_computed_name(self, lastname, firstname, lastname2=None):
"""Compute the name combined with the second lastname too.
We have 2 lastnames, so lastnames and firstname will be separated by a
comma.
"""
names = list()

if lastname:
names.append(lastname)
if lastname2:
names.append(lastname2)
if names and firstname:
names[-1] = names[-1] + ","
if firstname:
names.append(firstname)

return u" ".join(names)

@api.one
@api.depends("firstname", "lastname", "lastname2")
def _compute_name(self):
"""Write :attr:`~.name` according to splitted data."""
self.name = self._get_computed_name(self.lastname,
self.firstname,
self.lastname2)

@api.one
def _inverse_name(self):
"""Try to revert the effect of :meth:`._compute_name`."""
parts = self._get_inverse_name(self.name, self.is_company)

# Avoid to hit :meth:`~._check_name` with all 3 fields being ``False``
before, after = dict(), dict()
for key, value in parts.iteritems():
(before if value else after)[key] = value
self.update(before)
self.update(after)

@api.model
def _get_inverse_name(self, name, is_company=False):
"""Compute the inverted name.
- If the partner is a company, save it in the lastname.
- Otherwise, make a guess.
"""
# Company name goes to the lastname
if is_company or not name:
parts = [False, name or False, False]

# The comma separates the firstname
elif "," in name:
lastnames, firstname = name.split(",", 1)
parts = [firstname.strip()] + lastnames.split(" ", 1)

# Without comma, the user wrote the firstname first
else:
parts = name.split(" ", 2)

while len(parts) < 3:
parts.append(False)

return {"firstname": parts[0],
"lastname": parts[1],
"lastname2": parts[2]}

@api.one
@api.constrains("firstname", "lastname", "lastname2")
def _check_name(self):
"""Ensure at least one name is set."""
try:
super(ResPartner, self)._check_name()
except exceptions.EmptyNamesError as error:
if not self.lastname2:
raise error

@api.one
@api.onchange("firstname", "lastname", "lastname2")
def _onchange_subnames(self):
"""Trigger onchange with :attr:`~.lastname2` too."""
super(ResPartner, self)._onchange_subnames()
6 changes: 6 additions & 0 deletions partner_second_lastname/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# -*- coding: utf-8 -*-
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
# © 2015 Grupo ESOC Ingeniería de Servicios, S.L.U.

from . import test_name, test_onchange
from openerp.addons.partner_firstname.tests import test_empty
Loading

0 comments on commit 3124dd4

Please sign in to comment.