diff --git a/hr_employee_second_lastname/README.rst b/hr_employee_second_lastname/README.rst new file mode 100644 index 00000000000..64f44c68000 --- /dev/null +++ b/hr_employee_second_lastname/README.rst @@ -0,0 +1,94 @@ +========================================= +HR Employee First Name and Two Last Names +========================================= + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:92ab29e1e7ea1d47f493a5619cb6d50b6c2e6df9dfab19ba35547d491dcc7892 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png + :target: https://odoo-community.org/page/development-status + :alt: Beta +.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fhr-lightgray.png?logo=github + :target: https://github.com/OCA/hr/tree/18.0/hr_employee_second_lastname + :alt: OCA/hr +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/hr-18-0/hr-18-0-hr_employee_second_lastname + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png + :target: https://runboat.odoo-community.org/builds?repo=OCA/hr&target_branch=18.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module allows you to add firstname and lastnames (Father an Mother +Last Name) in employee form, and concatenate both in name field. + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +1. Go to *Employees* +2. On the employee form view you will have 3 separate fields, one for + Firstname, second for Lastname, both required and Mother's Last Name + (optional). + +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues `_. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us to smash it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +------- + +* Vauxoo + +Contributors +------------ + +- Luis Escobar +- Hugo Adan + +Maintainers +----------- + +This module is maintained by the OCA. + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +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. + +.. |maintainer-luisg123v| image:: https://github.com/luisg123v.png?size=40px + :target: https://github.com/luisg123v + :alt: luisg123v + +Current `maintainer `__: + +|maintainer-luisg123v| + +This module is part of the `OCA/hr `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/hr_employee_second_lastname/__init__.py b/hr_employee_second_lastname/__init__.py new file mode 100644 index 00000000000..cc6b6354ad8 --- /dev/null +++ b/hr_employee_second_lastname/__init__.py @@ -0,0 +1,2 @@ +from . import models +from .hooks import post_init_hook diff --git a/hr_employee_second_lastname/__manifest__.py b/hr_employee_second_lastname/__manifest__.py new file mode 100644 index 00000000000..5c7f115bb46 --- /dev/null +++ b/hr_employee_second_lastname/__manifest__.py @@ -0,0 +1,17 @@ +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +{ + "name": "HR Employee First Name and Two Last Names", + "version": "18.0.1.0.0", + "author": "Vauxoo, Odoo Community Association (OCA)", + "maintainers": ["luisg123v"], + "website": "https://github.com/OCA/hr", + "license": "AGPL-3", + "category": "Human Resources", + "summary": "Split Name in First Name, Father's Last Name and Mother's Last Name", + "depends": ["hr_employee_firstname"], + "data": ["views/hr_views.xml"], + "post_init_hook": "post_init_hook", + "demo": [], + "test": [], + "installable": True, +} diff --git a/hr_employee_second_lastname/hooks.py b/hr_employee_second_lastname/hooks.py new file mode 100644 index 00000000000..b50a5a72b79 --- /dev/null +++ b/hr_employee_second_lastname/hooks.py @@ -0,0 +1,25 @@ +def post_init_hook(env): + # This SQL statement is necessary to call _install_employee_lastnames() and + # set name fields correctly. + # + # After the installation, previously the dependency hr_employee_firstname + # splitting the name into two parts: firstname and lastname, so for this + # module to be able to process the new field lastmane2 it is necessary to + # reset the values to empty to be able to correctly set the three fields + # (firstname, lastname and lastname2). + # + # For example: + # After install hr_employee_fisrtname and before install + # hr_employee_second_lastname: + # name = 'John Peterson Clinton' + # firstname = 'John' + # lastname = 'Peterson Clinton' + # + # After install hr_employee_second_lastname: + # name = 'John Peterson Clinton' + # firstname = 'John' + # lastname = 'Peterson' + # lastname2 = 'Clinton' + env.cr.execute("UPDATE hr_employee SET firstname = NULL, lastname = NULL") + env["hr.employee"]._install_employee_lastnames() + env["ir.config_parameter"].sudo().set_param("employee_names_order", "first_last") diff --git a/hr_employee_second_lastname/i18n/ca.po b/hr_employee_second_lastname/i18n/ca.po new file mode 100644 index 00000000000..88e6d41daeb --- /dev/null +++ b/hr_employee_second_lastname/i18n/ca.po @@ -0,0 +1,51 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * hr_employee_lastnames +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 14.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2021-05-11 13:47+0000\n" +"Last-Translator: Haftec \n" +"Language-Team: none\n" +"Language: ca\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=n != 1;\n" +"X-Generator: Weblate 4.3.2\n" + +#. module: hr_employee_second_lastname +#: model:ir.model,name:hr_employee_second_lastname.model_hr_employee_base +msgid "Basic Employee" +msgstr "" + +#. module: hr_employee_second_lastname +#: model:ir.model,name:hr_employee_second_lastname.model_hr_employee +msgid "Employee" +msgstr "Empleat" + +#. module: hr_employee_second_lastname +#: model:ir.model.fields,field_description:hr_employee_second_lastname.field_hr_employee__firstname +#: model:ir.model.fields,field_description:hr_employee_second_lastname.field_hr_employee_base__firstname +#: model:ir.model.fields,field_description:hr_employee_second_lastname.field_hr_employee_public__firstname +msgid "First name" +msgstr "Nom" + +#. module: hr_employee_second_lastname +#: model:ir.model.fields,field_description:hr_employee_second_lastname.field_hr_employee__lastname +#: model:ir.model.fields,field_description:hr_employee_second_lastname.field_hr_employee_base__lastname +#: model:ir.model.fields,field_description:hr_employee_second_lastname.field_hr_employee_public__lastname +msgid "Last name" +msgstr "Primer cognom" + +#. module: hr_employee_second_lastname +#: model:ir.model.fields,field_description:hr_employee_second_lastname.field_hr_employee__lastname2 +#: model:ir.model.fields,field_description:hr_employee_second_lastname.field_hr_employee_base__lastname2 +#: model:ir.model.fields,field_description:hr_employee_second_lastname.field_hr_employee_public__lastname2 +msgid "Second last name" +msgstr "Segon cognom" + +#~ msgid "Last Modified on" +#~ msgstr "Darrera modificació el" diff --git a/hr_employee_second_lastname/i18n/es.po b/hr_employee_second_lastname/i18n/es.po new file mode 100644 index 00000000000..d54a19bd4b8 --- /dev/null +++ b/hr_employee_second_lastname/i18n/es.po @@ -0,0 +1,61 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * hr_employee_lastnames +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 10.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2020-08-31 12:31+0000\n" +"PO-Revision-Date: 2023-08-03 21:10+0000\n" +"Last-Translator: Ivorra78 \n" +"Language-Team: \n" +"Language: es\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=n != 1;\n" +"X-Generator: Weblate 4.17\n" + +#. module: hr_employee_second_lastname +#: model:ir.model,name:hr_employee_second_lastname.model_hr_employee_base +msgid "Basic Employee" +msgstr "Empleado Básico" + +#. module: hr_employee_second_lastname +#: model:ir.model,name:hr_employee_second_lastname.model_hr_employee +msgid "Employee" +msgstr "Empleado" + +#. module: hr_employee_second_lastname +#: model:ir.model.fields,field_description:hr_employee_second_lastname.field_hr_employee__firstname +#: model:ir.model.fields,field_description:hr_employee_second_lastname.field_hr_employee_base__firstname +#: model:ir.model.fields,field_description:hr_employee_second_lastname.field_hr_employee_public__firstname +msgid "First name" +msgstr "Nombre Propio" + +#. module: hr_employee_second_lastname +#: model:ir.model.fields,field_description:hr_employee_second_lastname.field_hr_employee__lastname +#: model:ir.model.fields,field_description:hr_employee_second_lastname.field_hr_employee_base__lastname +#: model:ir.model.fields,field_description:hr_employee_second_lastname.field_hr_employee_public__lastname +msgid "Last name" +msgstr "Primer Apellido" + +#. module: hr_employee_second_lastname +#: model:ir.model.fields,field_description:hr_employee_second_lastname.field_hr_employee__lastname2 +#: model:ir.model.fields,field_description:hr_employee_second_lastname.field_hr_employee_base__lastname2 +#: model:ir.model.fields,field_description:hr_employee_second_lastname.field_hr_employee_public__lastname2 +msgid "Second last name" +msgstr "Segundo Apellido" + +#~ msgid "Display Name" +#~ msgstr "Mostrar nombre" + +#~ msgid "ID" +#~ msgstr "ID (identificación)" + +#~ msgid "Last Modified on" +#~ msgstr "Modificado por última vez el" + +#~ msgid "No name set." +#~ msgstr "Sin nombre establecido." diff --git a/hr_employee_second_lastname/i18n/hr.po b/hr_employee_second_lastname/i18n/hr.po new file mode 100644 index 00000000000..bed658b62d1 --- /dev/null +++ b/hr_employee_second_lastname/i18n/hr.po @@ -0,0 +1,47 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * hr_employee_lastnames +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0\n" +"Report-Msgid-Bugs-To: \n" +"Last-Translator: Automatically generated\n" +"Language-Team: none\n" +"Language: hr\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=3; plural=n%10==1 && n%100!=11 ? 0 : n%10>=2 && n" +"%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2;\n" + +#. module: hr_employee_second_lastname +#: model:ir.model,name:hr_employee_second_lastname.model_hr_employee_base +msgid "Basic Employee" +msgstr "" + +#. module: hr_employee_second_lastname +#: model:ir.model,name:hr_employee_second_lastname.model_hr_employee +msgid "Employee" +msgstr "" + +#. module: hr_employee_second_lastname +#: model:ir.model.fields,field_description:hr_employee_second_lastname.field_hr_employee__firstname +#: model:ir.model.fields,field_description:hr_employee_second_lastname.field_hr_employee_base__firstname +#: model:ir.model.fields,field_description:hr_employee_second_lastname.field_hr_employee_public__firstname +msgid "First name" +msgstr "" + +#. module: hr_employee_second_lastname +#: model:ir.model.fields,field_description:hr_employee_second_lastname.field_hr_employee__lastname +#: model:ir.model.fields,field_description:hr_employee_second_lastname.field_hr_employee_base__lastname +#: model:ir.model.fields,field_description:hr_employee_second_lastname.field_hr_employee_public__lastname +msgid "Last name" +msgstr "" + +#. module: hr_employee_second_lastname +#: model:ir.model.fields,field_description:hr_employee_second_lastname.field_hr_employee__lastname2 +#: model:ir.model.fields,field_description:hr_employee_second_lastname.field_hr_employee_base__lastname2 +#: model:ir.model.fields,field_description:hr_employee_second_lastname.field_hr_employee_public__lastname2 +msgid "Second last name" +msgstr "" diff --git a/hr_employee_second_lastname/i18n/hr_employee_lastnames.pot b/hr_employee_second_lastname/i18n/hr_employee_lastnames.pot new file mode 100644 index 00000000000..2efbb4ca4d9 --- /dev/null +++ b/hr_employee_second_lastname/i18n/hr_employee_lastnames.pot @@ -0,0 +1,45 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * hr_employee_lastnames +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0\n" +"Report-Msgid-Bugs-To: \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: hr_employee_lastnames +#: model:ir.model,name:hr_employee_lastnames.model_hr_employee_base +msgid "Basic Employee" +msgstr "" + +#. module: hr_employee_lastnames +#: model:ir.model,name:hr_employee_lastnames.model_hr_employee +msgid "Employee" +msgstr "" + +#. module: hr_employee_lastnames +#: model:ir.model.fields,field_description:hr_employee_lastnames.field_hr_employee__firstname +#: model:ir.model.fields,field_description:hr_employee_lastnames.field_hr_employee_base__firstname +#: model:ir.model.fields,field_description:hr_employee_lastnames.field_hr_employee_public__firstname +msgid "First name" +msgstr "" + +#. module: hr_employee_lastnames +#: model:ir.model.fields,field_description:hr_employee_lastnames.field_hr_employee__lastname +#: model:ir.model.fields,field_description:hr_employee_lastnames.field_hr_employee_base__lastname +#: model:ir.model.fields,field_description:hr_employee_lastnames.field_hr_employee_public__lastname +msgid "Last name" +msgstr "" + +#. module: hr_employee_lastnames +#: model:ir.model.fields,field_description:hr_employee_lastnames.field_hr_employee__lastname2 +#: model:ir.model.fields,field_description:hr_employee_lastnames.field_hr_employee_base__lastname2 +#: model:ir.model.fields,field_description:hr_employee_lastnames.field_hr_employee_public__lastname2 +msgid "Second last name" +msgstr "" diff --git a/hr_employee_second_lastname/i18n/hr_employee_second_lastname.pot b/hr_employee_second_lastname/i18n/hr_employee_second_lastname.pot new file mode 100644 index 00000000000..00442361de8 --- /dev/null +++ b/hr_employee_second_lastname/i18n/hr_employee_second_lastname.pot @@ -0,0 +1,45 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * hr_employee_second_lastname +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 17.0\n" +"Report-Msgid-Bugs-To: \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: hr_employee_second_lastname +#: model:ir.model,name:hr_employee_second_lastname.model_hr_employee_base +msgid "Basic Employee" +msgstr "" + +#. module: hr_employee_second_lastname +#: model:ir.model,name:hr_employee_second_lastname.model_hr_employee +msgid "Employee" +msgstr "" + +#. module: hr_employee_second_lastname +#: model:ir.model.fields,field_description:hr_employee_second_lastname.field_hr_employee__firstname +#: model:ir.model.fields,field_description:hr_employee_second_lastname.field_hr_employee_base__firstname +#: model:ir.model.fields,field_description:hr_employee_second_lastname.field_hr_employee_public__firstname +msgid "First name" +msgstr "" + +#. module: hr_employee_second_lastname +#: model:ir.model.fields,field_description:hr_employee_second_lastname.field_hr_employee__lastname +#: model:ir.model.fields,field_description:hr_employee_second_lastname.field_hr_employee_base__lastname +#: model:ir.model.fields,field_description:hr_employee_second_lastname.field_hr_employee_public__lastname +msgid "Last name" +msgstr "" + +#. module: hr_employee_second_lastname +#: model:ir.model.fields,field_description:hr_employee_second_lastname.field_hr_employee__lastname2 +#: model:ir.model.fields,field_description:hr_employee_second_lastname.field_hr_employee_base__lastname2 +#: model:ir.model.fields,field_description:hr_employee_second_lastname.field_hr_employee_public__lastname2 +msgid "Second last name" +msgstr "" diff --git a/hr_employee_second_lastname/i18n/it.po b/hr_employee_second_lastname/i18n/it.po new file mode 100644 index 00000000000..ce13dcb1563 --- /dev/null +++ b/hr_employee_second_lastname/i18n/it.po @@ -0,0 +1,48 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * hr_employee_lastnames +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2023-05-17 14:35+0000\n" +"Last-Translator: mymage \n" +"Language-Team: none\n" +"Language: it\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=n != 1;\n" +"X-Generator: Weblate 4.14.1\n" + +#. module: hr_employee_second_lastname +#: model:ir.model,name:hr_employee_second_lastname.model_hr_employee_base +msgid "Basic Employee" +msgstr "Dipendente base" + +#. module: hr_employee_second_lastname +#: model:ir.model,name:hr_employee_second_lastname.model_hr_employee +msgid "Employee" +msgstr "Dipendente" + +#. module: hr_employee_second_lastname +#: model:ir.model.fields,field_description:hr_employee_second_lastname.field_hr_employee__firstname +#: model:ir.model.fields,field_description:hr_employee_second_lastname.field_hr_employee_base__firstname +#: model:ir.model.fields,field_description:hr_employee_second_lastname.field_hr_employee_public__firstname +msgid "First name" +msgstr "Nome" + +#. module: hr_employee_second_lastname +#: model:ir.model.fields,field_description:hr_employee_second_lastname.field_hr_employee__lastname +#: model:ir.model.fields,field_description:hr_employee_second_lastname.field_hr_employee_base__lastname +#: model:ir.model.fields,field_description:hr_employee_second_lastname.field_hr_employee_public__lastname +msgid "Last name" +msgstr "Cognome" + +#. module: hr_employee_second_lastname +#: model:ir.model.fields,field_description:hr_employee_second_lastname.field_hr_employee__lastname2 +#: model:ir.model.fields,field_description:hr_employee_second_lastname.field_hr_employee_base__lastname2 +#: model:ir.model.fields,field_description:hr_employee_second_lastname.field_hr_employee_public__lastname2 +msgid "Second last name" +msgstr "Secondo cognome" diff --git a/hr_employee_second_lastname/i18n/pt_BR.po b/hr_employee_second_lastname/i18n/pt_BR.po new file mode 100644 index 00000000000..1e5d78c6041 --- /dev/null +++ b/hr_employee_second_lastname/i18n/pt_BR.po @@ -0,0 +1,57 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * hr_employee_lastnames +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 14.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2022-09-26 16:07+0000\n" +"Last-Translator: Douglas Custódio \n" +"Language-Team: none\n" +"Language: pt_BR\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=n > 1;\n" +"X-Generator: Weblate 4.3.2\n" + +#. module: hr_employee_second_lastname +#: model:ir.model,name:hr_employee_second_lastname.model_hr_employee_base +msgid "Basic Employee" +msgstr "Funcionário Basico" + +#. module: hr_employee_second_lastname +#: model:ir.model,name:hr_employee_second_lastname.model_hr_employee +msgid "Employee" +msgstr "Funcionário" + +#. module: hr_employee_second_lastname +#: model:ir.model.fields,field_description:hr_employee_second_lastname.field_hr_employee__firstname +#: model:ir.model.fields,field_description:hr_employee_second_lastname.field_hr_employee_base__firstname +#: model:ir.model.fields,field_description:hr_employee_second_lastname.field_hr_employee_public__firstname +msgid "First name" +msgstr "Nome" + +#. module: hr_employee_second_lastname +#: model:ir.model.fields,field_description:hr_employee_second_lastname.field_hr_employee__lastname +#: model:ir.model.fields,field_description:hr_employee_second_lastname.field_hr_employee_base__lastname +#: model:ir.model.fields,field_description:hr_employee_second_lastname.field_hr_employee_public__lastname +msgid "Last name" +msgstr "Sobrenome" + +#. module: hr_employee_second_lastname +#: model:ir.model.fields,field_description:hr_employee_second_lastname.field_hr_employee__lastname2 +#: model:ir.model.fields,field_description:hr_employee_second_lastname.field_hr_employee_base__lastname2 +#: model:ir.model.fields,field_description:hr_employee_second_lastname.field_hr_employee_public__lastname2 +msgid "Second last name" +msgstr "Segundo sobrenome" + +#~ msgid "Display Name" +#~ msgstr "Nome de Exibição" + +#~ msgid "ID" +#~ msgstr "ID" + +#~ msgid "Last Modified on" +#~ msgstr "Última Modificação em" diff --git a/hr_employee_second_lastname/models/__init__.py b/hr_employee_second_lastname/models/__init__.py new file mode 100644 index 00000000000..f55d18fa465 --- /dev/null +++ b/hr_employee_second_lastname/models/__init__.py @@ -0,0 +1,2 @@ +from . import hr_employee_base +from . import hr_employee diff --git a/hr_employee_second_lastname/models/hr_employee.py b/hr_employee_second_lastname/models/hr_employee.py new file mode 100644 index 00000000000..edf085ccdda --- /dev/null +++ b/hr_employee_second_lastname/models/hr_employee.py @@ -0,0 +1,160 @@ +import logging + +from odoo import api, models + +from odoo.addons.hr_employee_firstname.models.hr_employee import UPDATE_PARTNER_FIELDS + +_logger = logging.getLogger(__name__) + +UPDATE_PARTNER_FIELDS += ["lastname2"] + + +class HrEmployee(models.Model): + _inherit = "hr.employee" + + @api.model + def _get_name_lastnames(self, lastname, firstname, lastname2=None): + order = self._get_names_order() + names = list() + if order == "first_last": + if firstname: + names.append(firstname) + if lastname: + names.append(lastname) + if lastname2: + names.append(lastname2) + else: + if lastname: + names.append(lastname) + if lastname2: + names.append(lastname2) + if names and firstname and order == "last_first_comma": + names[-1] = names[-1] + "," + if firstname: + names.append(firstname) + return " ".join(names) + + def _prepare_vals_on_create_firstname_lastname(self, vals): + values = vals.copy() + res = super()._prepare_vals_on_create_firstname_lastname(values) + if any([field in vals for field in ("firstname", "lastname", "lastname2")]): + vals["name"] = self._get_name_lastnames( + vals.get("lastname"), vals.get("firstname"), vals.get("lastname2") + ) + elif vals.get("name"): + name_splitted = self.split_name(vals["name"]) + vals["firstname"] = name_splitted["firstname"] + vals["lastname"] = name_splitted["lastname"] + vals["lastname2"] = name_splitted["lastname2"] + return res + + def _prepare_vals_on_write_firstname_lastname(self, vals): + values = vals.copy() + res = super()._prepare_vals_on_write_firstname_lastname(values) + if any([field in vals for field in ("firstname", "lastname", "lastname2")]): + if "lastname" in vals: + lastname = vals["lastname"] + else: + lastname = self.lastname + if "firstname" in vals: + firstname = vals["firstname"] + else: + firstname = self.firstname + if "lastname2" in vals: + lastname2 = vals["lastname2"] + else: + lastname2 = self.lastname2 + vals["name"] = self._get_name_lastnames(lastname, firstname, lastname2) + elif vals.get("name"): + name_splitted = self.split_name(vals["name"]) + vals["lastname"] = name_splitted["lastname"] + vals["firstname"] = name_splitted["firstname"] + vals["lastname2"] = name_splitted["lastname2"] + return res + + def _update_partner_firstname(self): + for employee in self: + partners = employee.mapped("user_id.partner_id") + partners |= employee.mapped("address_home_id") + partners.write( + { + "firstname": employee.firstname, + "lastname": employee.lastname, + "lastname2": employee.lastname2, + } + ) + + @api.model + def _get_inverse_name(self, name): + """Compute the inverted name.""" + result = { + "firstname": False, + "lastname": name or False, + "lastname2": False, + } + + if not name: + return result + + order = self._get_names_order() + result.update(super()._get_inverse_name(name)) + + if order in ("first_last", "last_first_comma"): + parts = self._split_part("lastname", result) + if parts: + result.update({"lastname": parts[0], "lastname2": " ".join(parts[1:])}) + else: + parts = self._split_part("firstname", result) + if parts: + result.update( + {"firstname": parts[-1], "lastname2": " ".join(parts[:-1])} + ) + return result + + def _split_part(self, name_part, name_split): + """Split a given part of a name. + + :param name_split: The parts of the name + :type dict + + :param name_part: The part to split + :type str + """ + name = name_split.get(name_part, False) + parts = name.split(" ", 1) if name else [] + if not name or len(parts) < 2: + return False + return parts + + def _inverse_name(self): + """Try to revert the effect of :method:`._compute_name`.""" + for record in self: + parts = self._get_inverse_name(record.name) + record.write( + { + "lastname": parts["lastname"], + "firstname": parts["firstname"], + "lastname2": parts["lastname2"], + } + ) + + @api.model + def _install_employee_lastnames(self): + """Save names correctly in the database. + Before installing the module, field ``name`` contains all full names. + When installing it, this method parses those names and saves them + correctly into the database. This can be called later too if needed. + """ + # Find records with empty firstname and lastnames + records = self.search([("firstname", "=", False), ("lastname", "=", False)]) + + # Force calculations there + records._inverse_name() + _logger.info("%d employees updated installing module.", len(records)) + + @api.onchange("firstname", "lastname", "lastname2") + def _onchange_firstname_lastname(self): + if self.firstname or self.lastname or self.lastname2: + self.name = self._get_name_lastnames( + self.lastname, self.firstname, self.lastname2 + ) diff --git a/hr_employee_second_lastname/models/hr_employee_base.py b/hr_employee_second_lastname/models/hr_employee_base.py new file mode 100644 index 00000000000..7f630b2e991 --- /dev/null +++ b/hr_employee_second_lastname/models/hr_employee_base.py @@ -0,0 +1,9 @@ +from odoo import fields, models + + +class HrEmployeeBase(models.AbstractModel): + _inherit = "hr.employee.base" + + firstname = fields.Char("First name") + lastname = fields.Char("Last name") + lastname2 = fields.Char("Second last name") diff --git a/hr_employee_second_lastname/pyproject.toml b/hr_employee_second_lastname/pyproject.toml new file mode 100644 index 00000000000..4231d0cccb3 --- /dev/null +++ b/hr_employee_second_lastname/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/hr_employee_second_lastname/readme/CONTRIBUTORS.md b/hr_employee_second_lastname/readme/CONTRIBUTORS.md new file mode 100644 index 00000000000..021f9de3f90 --- /dev/null +++ b/hr_employee_second_lastname/readme/CONTRIBUTORS.md @@ -0,0 +1,2 @@ +- Luis Escobar \<\> +- Hugo Adan \<\> diff --git a/hr_employee_second_lastname/readme/DESCRIPTION.md b/hr_employee_second_lastname/readme/DESCRIPTION.md new file mode 100644 index 00000000000..f8b51331199 --- /dev/null +++ b/hr_employee_second_lastname/readme/DESCRIPTION.md @@ -0,0 +1,2 @@ +This module allows you to add firstname and lastnames (Father an Mother +Last Name) in employee form, and concatenate both in name field. diff --git a/hr_employee_second_lastname/readme/USAGE.md b/hr_employee_second_lastname/readme/USAGE.md new file mode 100644 index 00000000000..4f2fb890ecc --- /dev/null +++ b/hr_employee_second_lastname/readme/USAGE.md @@ -0,0 +1,4 @@ +1. Go to *Employees* +2. On the employee form view you will have 3 separate fields, one for + Firstname, second for Lastname, both required and Mother's Last Name + (optional). diff --git a/hr_employee_second_lastname/static/description/icon.png b/hr_employee_second_lastname/static/description/icon.png new file mode 100644 index 00000000000..297dc71c85c Binary files /dev/null and b/hr_employee_second_lastname/static/description/icon.png differ diff --git a/hr_employee_second_lastname/static/description/index.html b/hr_employee_second_lastname/static/description/index.html new file mode 100644 index 00000000000..ba7fbe517b5 --- /dev/null +++ b/hr_employee_second_lastname/static/description/index.html @@ -0,0 +1,437 @@ + + + + + +HR Employee First Name and Two Last Names + + + +
+

HR Employee First Name and Two Last Names

+ + +

Beta License: AGPL-3 OCA/hr Translate me on Weblate Try me on Runboat

+

This module allows you to add firstname and lastnames (Father an Mother +Last Name) in employee form, and concatenate both in name field.

+

Table of contents

+ +
+

Usage

+
    +
  1. Go to Employees
  2. +
  3. On the employee form view you will have 3 separate fields, one for +Firstname, second for Lastname, both required and Mother’s Last Name +(optional).
  4. +
+
+
+

Bug Tracker

+

Bugs are tracked on GitHub Issues. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us to smash it by providing a detailed and welcomed +feedback.

+

Do not contact contributors directly about support or help with technical issues.

+
+
+

Credits

+
+

Authors

+
    +
  • Vauxoo
  • +
+
+
+

Contributors

+ +
+
+

Maintainers

+

This module is maintained by the OCA.

+ +Odoo Community Association + +

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.

+

Current maintainer:

+

luisg123v

+

This module is part of the OCA/hr project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+ + diff --git a/hr_employee_second_lastname/tests/__init__.py b/hr_employee_second_lastname/tests/__init__.py new file mode 100644 index 00000000000..c440b5ff6c1 --- /dev/null +++ b/hr_employee_second_lastname/tests/__init__.py @@ -0,0 +1,3 @@ +# Copyright (C) 2014 Savoir-faire Linux. All Rights Reserved. +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +from . import test_hr_employee_second_lastname diff --git a/hr_employee_second_lastname/tests/test_hr_employee_second_lastname.py b/hr_employee_second_lastname/tests/test_hr_employee_second_lastname.py new file mode 100644 index 00000000000..8f1ff1eb329 --- /dev/null +++ b/hr_employee_second_lastname/tests/test_hr_employee_second_lastname.py @@ -0,0 +1,173 @@ +from odoo import exceptions +from odoo.tests.common import TransactionCase +from odoo.tools.misc import submap + + +class TestEmployeeSecondLastname(TransactionCase): + def setUp(self): + super().setUp() + self.env["ir.config_parameter"].sudo().set_param( + "employee_names_order", "first_last" + ) + self.employee_model = self.env["hr.employee"] + + # Create 3 employees to concatenate the firstname and lastnames + # in name_related + self.employee1_id = self.employee_model.create( + {"firstname": "Manuel", "lastname": "Fernandez", "lastname2": "Gonzalez"} + ) + self.employee2_id = self.employee_model.create( + {"firstname": "Jean-Pierre", "lastname": "Carnaud"} + ) + self.employee3_id = self.employee_model.create( + {"firstname": "Jenssens", "lastname": "Famke"} + ) + + # Create 3 employees for split the name_related to + # firstname and lastnames + self.employee10_id = self.employee_model.create( + {"name": "Manuel Fernandez Gonzalez"} + ) + self.employee20_id = self.employee_model.create({"name": "Jean-Pierre Carnaud"}) + self.employee30_id = self.employee_model.create({"name": "JenssensFamke"}) + + def test_get_name_lastnames(self): + """Validate the _get_name_lastnames method is concatenating + the firstname and lastnames + """ + # Check for employee1 + self.assertEqual(self.employee1_id.name, "Manuel Fernandez Gonzalez") + + # Check for employee2 + self.assertEqual(self.employee2_id.name, "Jean-Pierre Carnaud") + + # Check for employee3 + self.assertEqual(self.employee3_id.name, "Jenssens Famke") + + def test_onchange(self): + """Validate the _get_name_lastnames method is not failing""" + # Check that fields used to generate the name and also name field + # are empty before onchange + fields_spec = self.env["hr.employee"]._get_fields_spec() + self.assertEqual( + submap(fields_spec, ("firstname", "lastname", "lastname2", "name")), + { + "firstname": {}, + "lastname": {}, + "lastname2": {}, + "name": {}, + }, + ) + values = { + "firstname": "Pedro", + "lastname": "Perez", + "lastname2": "Hernandez", + "name": "test employee", + } + for field in self.employee_model._fields: + if field not in values: + values[field] = False + # we work on a temporary record + new_record = self.employee_model.new(values) + + updates = new_record.onchange( + values, ["firstname", "lastname", "lastname2"], fields_spec + ) + values.update(updates.get("value", {})) + self.assertEqual(values["name"], "Pedro Perez Hernandez") + + def test_auto_init_name(self): + """Validate the create method if the name is split + in firstname and lastnames + """ + # Check for employee10 + self.assertEqual(self.employee10_id.firstname, "Manuel") + self.assertEqual(self.employee10_id.lastname, "Fernandez") + self.assertEqual(self.employee10_id.lastname2, "Gonzalez") + + # Check for employee20 + self.assertEqual(self.employee20_id.firstname, "Jean-Pierre") + self.assertEqual(self.employee20_id.lastname, "Carnaud") + self.assertEqual(self.employee20_id.lastname2, False) + + # Check for employee30 + self.assertEqual(self.employee30_id.firstname, False) + self.assertEqual(self.employee30_id.lastname, "JenssensFamke") + self.assertEqual(self.employee30_id.lastname2, False) + + employee_without_name = self.employee_model + with self.assertRaises(exceptions.ValidationError): + employee_without_name = self.employee_model.create( + {"firstname": "", "lastname": ""} + ) + self.assertEqual(employee_without_name, self.employee_model) + + def test_change_name(self): + self.employee1_id.write({"name": "Pedro Martinez Torres"}) + self.employee1_id.invalidate_recordset() + + self.assertEqual(self.employee1_id.firstname, "Pedro") + self.assertEqual(self.employee1_id.lastname, "Martinez") + self.assertEqual(self.employee1_id.lastname2, "Torres") + + def test_change_name_with_space(self): + self.employee1_id.write({"name": " Jean-Pierre Carnaud-Eyck"}) + self.employee1_id.invalidate_recordset() + + self.assertEqual(self.employee1_id.firstname, "Jean-Pierre") + self.assertEqual(self.employee1_id.lastname, "Carnaud-Eyck") + self.assertEqual(self.employee1_id.lastname2, False) + + def test_change_firstname(self): + self.employee1_id.write({"firstname": "Pedro"}) + self.employee1_id.invalidate_recordset() + + self.assertEqual(self.employee1_id.name, "Pedro Fernandez Gonzalez") + + def test_change_lastname(self): + self.employee1_id.write({"lastname": "Lopez"}) + self.employee1_id.invalidate_recordset() + + self.assertEqual(self.employee1_id.name, "Manuel Lopez Gonzalez") + + def test_change_firstname_and_lastnames(self): + self.employee1_id.write({"firstname": "Jean-Pierre", "lastname2": "Carnaud"}) + self.employee1_id.invalidate_recordset() + + self.assertEqual(self.employee1_id.name, "Jean-Pierre Fernandez Carnaud") + + def test_change_lastname_with_set_last_first(self): + self.env["ir.config_parameter"].sudo().set_param( + "employee_names_order", "last_first" + ) + self.employee1_id.write({"lastname": "Lopez"}) + self.employee1_id.invalidate_recordset() + + self.assertEqual(self.employee1_id.name, "Lopez Gonzalez Manuel") + + def test_change_name_with_set_last_first(self): + self.env["ir.config_parameter"].sudo().set_param( + "employee_names_order", "last_first" + ) + self.employee1_id.write({"name": "Martinez Torres Pedro"}) + self.employee1_id.invalidate_recordset() + + self.assertEqual(self.employee1_id.firstname, "Pedro") + self.assertEqual(self.employee1_id.lastname, "Martinez") + self.assertEqual(self.employee1_id.lastname2, "Torres") + + self.employee1_id.write({"name": ""}) + self.employee1_id.invalidate_recordset() + + self.assertEqual(self.employee1_id.firstname, "Pedro") + self.assertEqual(self.employee1_id.lastname, "Martinez") + self.assertEqual(self.employee1_id.lastname2, "Torres") + + def test_change_lastname_with_set_last_first_comma(self): + self.env["ir.config_parameter"].sudo().set_param( + "employee_names_order", "last_first_comma" + ) + self.employee1_id.write({"lastname": "Lopez"}) + self.employee1_id.invalidate_recordset() + + self.assertEqual(self.employee1_id.name, "Lopez Gonzalez, Manuel") diff --git a/hr_employee_second_lastname/views/hr_views.xml b/hr_employee_second_lastname/views/hr_views.xml new file mode 100644 index 00000000000..aaf04db184b --- /dev/null +++ b/hr_employee_second_lastname/views/hr_views.xml @@ -0,0 +1,15 @@ + + + + hr.employee.form.firstname.inherit + hr.employee + + + + + + + + + +