Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
113 changes: 113 additions & 0 deletions partner_middlename/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
.. image:: https://odoo-community.org/readme-banner-image
:target: https://odoo-community.org/get-involved?utm_source=readme
:alt: Odoo Community Association

===================
Partner Middle Name
===================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:2900aece401268fdb58ee940febf3f98852d89e4e490ab88f213ef767038368d
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |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/license-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%2Fpartner--contact-lightgray.png?logo=github
:target: https://github.com/OCA/partner-contact/tree/19.0/partner_middlename
:alt: OCA/partner-contact
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/partner-contact-19-0/partner-contact-19-0-partner_middlename
: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/partner-contact&target_branch=19.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|

Allows to enter contact names using three separate fields, for First
name, Middle Name and Last Name.

NOTE: currently this feature is incompatible with te Partner Second Last
Name (``partner_second_lastname``), please don't install them together
in the same database.

**Table of contents**

.. contents::
:local:

Configuration
=============

At Settings / General Settings / Partner Names Order, select option
"Firstname Middlename Lastname" or " Lastname, Firstname Middlename".

Usage
=====

On the Contact form, create a new contact.

- Set contact to "Individual". The full name will not be directly
editable.
- Set all or any of the First Name, Middle name and Last Name fields.
- The full name should be automatically populated based on the name
fields set, and the general setting selected.

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 to smash it by providing a detailed and welcomed
`feedback <https://github.com/OCA/partner-contact/issues/new?body=module:%20partner_middlename%0Aversion:%2019.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

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

Credits
=======

Authors
-------

* Open Source Integrators

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

- `Open Source Integrators <https://www.opensourceintegrators.com>`__:

- Daniel Reis <dreis@opensourceintegrators.com>
- Nikul Chaudhary <nchaudhary@opensourceintegrators.com>

- `Heliconia Solutions Pvt. Ltd. <https://www.heliconia.io>`__

- Bhavesh Heliconia

- `ACSONE SA/NV <https://https://www.acsone.eu/>`__

- Maxime Franco <maxime.franco@acsone.eu>

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.

This module is part of the `OCA/partner-contact <https://github.com/OCA/partner-contact/tree/19.0/partner_middlename>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
4 changes: 4 additions & 0 deletions partner_middlename/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Copyright (C) 2023 Open Source Integrators
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from . import models
15 changes: 15 additions & 0 deletions partner_middlename/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Copyright (C) 2023 Open Source Integrators
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

{
"name": "Partner Middle Name",
"summary": "Have split Middle",
"version": "19.0.1.0.0",
"license": "AGPL-3",
"website": "https://github.com/OCA/partner-contact",
"author": "Open Source Integrators, Odoo Community Association (OCA)",
"category": "Partner Management",
"depends": ["partner_firstname"],
"data": ["views/res_partner.xml", "views/res_user.xml"],
"installable": True,
}
33 changes: 33 additions & 0 deletions partner_middlename/i18n/it.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * partner_middlename
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 16.0\n"
"Report-Msgid-Bugs-To: \n"
"PO-Revision-Date: 2023-12-27 11:42+0000\n"
"Last-Translator: mymage <stefano.consolaro@mymage.it>\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.17\n"

#. module: partner_middlename
#: model:ir.model,name:partner_middlename.model_res_config_settings
msgid "Config Settings"
msgstr "Impostazioni configurazione"

#. module: partner_middlename
#: model:ir.model,name:partner_middlename.model_res_partner
msgid "Contact"
msgstr "Contatto"

#. module: partner_middlename
#: model:ir.model.fields,field_description:partner_middlename.field_res_partner__middlename
#: model:ir.model.fields,field_description:partner_middlename.field_res_users__middlename
msgid "Middle Name"
msgstr "Secondo nome"
30 changes: 30 additions & 0 deletions partner_middlename/i18n/partner_middlename.pot
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * partner_middlename
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 18.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: partner_middlename
#: model:ir.model,name:partner_middlename.model_res_config_settings
msgid "Config Settings"
msgstr ""

#. module: partner_middlename
#: model:ir.model,name:partner_middlename.model_res_partner
msgid "Contact"
msgstr ""

#. module: partner_middlename
#: model:ir.model.fields,field_description:partner_middlename.field_res_partner__middlename
#: model:ir.model.fields,field_description:partner_middlename.field_res_users__middlename
msgid "Middle Name"
msgstr ""
5 changes: 5 additions & 0 deletions partner_middlename/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Copyright (C) 2023 Open Source Integrators
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from . import res_config_settings
from . import res_partner
26 changes: 26 additions & 0 deletions partner_middlename/models/res_config_settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Copyright (C) 2023 Open Source Integrators
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import models


class ResConfigSettings(models.TransientModel):
_inherit = "res.config.settings"

def _partners_for_recalculating(self):
return self.env["res.partner"].search(
[
("is_company", "=", False),
"|",
"&",
("firstname", "!=", False),
("lastname", "!=", False),
"|",
"&",
("firstname", "!=", False),
("middlename", "!=", False),
"&",
("lastname", "!=", False),
("middlename", "!=", False),
]
)
120 changes: 120 additions & 0 deletions partner_middlename/models/res_partner.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
# Copyright (C) 2023 Open Source Integrators
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import api, fields, models

from odoo.addons.partner_firstname import exceptions


class ResPartner(models.Model):
_inherit = "res.partner"

middlename = fields.Char("Middle Name")

@api.model
def _get_computed_name(self, lastname, firstname, middlename=None):
"""Compute the 'name' field according to splitted data.
You can override this method to change the order of lastname and
firstname and middlename the computed name"""
order = self._get_names_order()
if order == "last_first_comma":
names = list()
if lastname:
names.append(lastname)
if names and firstname:
names[-1] = names[-1] + ","
if firstname:
names.append(firstname)
if middlename:
names.append(middlename)
return " ".join(names)
elif order == "first_last":
return " ".join(p for p in (firstname, middlename, lastname) if p)
else:
return " ".join(p for p in (lastname, firstname, middlename) if p)

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

def _inverse_name(self):
"""Try to revert the effect of :meth:`._compute_name`."""
self.ensure_one()
parts = self._get_inverse_name(self.name, self.is_company)
# Avoid to hit :meth:`~._check_name` with all 3 fields being ``False``
before, after = {}, {}
for key, value in parts.items():
(before if value else after)[key] = value
if any([before[k] != self[k] for k in list(before.keys())]):
self.update(before)
if any([after[k] != self[k] for k in list(after.keys())]):
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.
"""
result = {
"firstname": False,
"lastname": name or False,
"middlename": False,
}

# Company name goes to the lastname
if not name or is_company:
return result

order = self._get_names_order()
result.update(super()._get_inverse_name(name, is_company))

if order == "first_last":
parts = self._split_part("lastname", result)
if parts:
result.update({"middlename": parts[0], "lastname": " ".join(parts[1:])})
elif order == "last_first_comma":
parts = self._split_part("firstname", result)
if parts:
result.update(
{"firstname": parts[0], "middlename": " ".join(parts[1:])}
)
else:
parts = self._split_part("firstname", result)
if parts:
result.update(
{"firstname": parts[-1], "middlename": " ".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

@api.constrains("firstname", "lastname", "middlename")
def _check_firstname_lastname(self):
"""Ensure at least one name is set."""
try:
return super()._check_firstname_lastname()
except exceptions.EmptyNamesError:
for partner in self:
if not partner.middlename:
raise
3 changes: 3 additions & 0 deletions partner_middlename/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build-system]
requires = ["whool"]
build-backend = "whool.buildapi"
2 changes: 2 additions & 0 deletions partner_middlename/readme/CONFIGURE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
At Settings / General Settings / Partner Names Order, select option
"Firstname Middlename Lastname" or " Lastname, Firstname Middlename".
7 changes: 7 additions & 0 deletions partner_middlename/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
- [Open Source Integrators](https://www.opensourceintegrators.com):
- Daniel Reis \<<dreis@opensourceintegrators.com>\>
- Nikul Chaudhary \<<nchaudhary@opensourceintegrators.com>\>
- [Heliconia Solutions Pvt. Ltd.](https://www.heliconia.io)
- Bhavesh Heliconia
- [ACSONE SA/NV](https://https://www.acsone.eu/)
- Maxime Franco \<<maxime.franco@acsone.eu>\>
6 changes: 6 additions & 0 deletions partner_middlename/readme/DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Allows to enter contact names using three separate fields, for First
name, Middle Name and Last Name.

NOTE: currently this feature is incompatible with te Partner Second Last
Name (`partner_second_lastname`), please don't install them together in
the same database.
7 changes: 7 additions & 0 deletions partner_middlename/readme/USAGE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
On the Contact form, create a new contact.

- Set contact to "Individual". The full name will not be directly
editable.
- Set all or any of the First Name, Middle name and Last Name fields.
- The full name should be automatically populated based on the name
fields set, and the general setting selected.
Binary file added partner_middlename/static/description/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading