-
-
Notifications
You must be signed in to change notification settings - Fork 868
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Partner lastname 2 #153
Merged
Partner lastname 2 #153
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 "" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 "" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add
try me on runbot
https://github.com/OCA/maintainer-tools/tree/master/template/module#usage