From be5684180c8b9fbf51a282a75e449504525b3b9d Mon Sep 17 00:00:00 2001 From: JasminSForgeFlow Date: Mon, 8 Jun 2026 07:26:58 +0000 Subject: [PATCH] [ADD] partner_display_ref --- partner_display_ref/README.rst | 116 +++++ partner_display_ref/__init__.py | 1 + partner_display_ref/__manifest__.py | 14 + partner_display_ref/models/__init__.py | 1 + partner_display_ref/models/res_partner.py | 23 + partner_display_ref/pyproject.toml | 3 + partner_display_ref/readme/CONTRIBUTORS.md | 2 + partner_display_ref/readme/DESCRIPTION.md | 10 + partner_display_ref/readme/USAGE.md | 14 + .../static/description/index.html | 461 ++++++++++++++++++ partner_display_ref/tests/__init__.py | 1 + .../tests/test_partner_display_ref.py | 67 +++ 12 files changed, 713 insertions(+) create mode 100644 partner_display_ref/README.rst create mode 100644 partner_display_ref/__init__.py create mode 100644 partner_display_ref/__manifest__.py create mode 100644 partner_display_ref/models/__init__.py create mode 100644 partner_display_ref/models/res_partner.py create mode 100644 partner_display_ref/pyproject.toml create mode 100644 partner_display_ref/readme/CONTRIBUTORS.md create mode 100644 partner_display_ref/readme/DESCRIPTION.md create mode 100644 partner_display_ref/readme/USAGE.md create mode 100644 partner_display_ref/static/description/index.html create mode 100644 partner_display_ref/tests/__init__.py create mode 100644 partner_display_ref/tests/test_partner_display_ref.py diff --git a/partner_display_ref/README.rst b/partner_display_ref/README.rst new file mode 100644 index 00000000000..9468ed2fd7e --- /dev/null +++ b/partner_display_ref/README.rst @@ -0,0 +1,116 @@ +.. image:: https://odoo-community.org/readme-banner-image + :target: https://odoo-community.org/get-involved?utm_source=readme + :alt: Odoo Community Association + +========================= +Partner Display Reference +========================= + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:415030fc2095e1354294c1a59521c1b2f556abd37880cf124b251a8ae3cfc7c7 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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_display_ref + :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_display_ref + :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| + +This module prefixes the customer reference (``res.partner.ref``) to a +partner's ``display_name`` whenever it is rendered inside an opted-in +view — shown as ``[C00123] Acme Corp`` in the dropdown, the selected +value, and list cells alike. + +The decoration is a generic mechanism: it activates only when a view +injects the ``partner_display_ref_field`` context key naming the field +to prefix on a ``res.partner`` field. Contacts, CRM, Invoicing and any +other view that does not opt in continue to see the plain partner name. +Companion modules (e.g. ``sale_partner_display_ref``) wire this +mechanism into specific apps. + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +To opt a view into the reference prefix, add the +``partner_display_ref_field`` context key naming the ``res.partner`` +field to prefix: + +:: + + + +Any ``res.partner`` field can be named (e.g. ``ref``, ``supplier_ref``). +Set a value on that field for a contact. In the opted-in view, the value +is prefixed wherever the partner is shown — the autocomplete dropdown, +the selected value, and list cells: + +:: + + [C00123] Acme Corp + +Views that do not opt in keep the plain partner name, so reports and +exports stay clean. If the named field is not installed, no prefix is +applied. + +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 +------- + +* ForgeFlow + +Contributors +------------ + +- `ForgeFlow `__ + + - Jasmin Solanki + +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 `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/partner_display_ref/__init__.py b/partner_display_ref/__init__.py new file mode 100644 index 00000000000..0650744f6bc --- /dev/null +++ b/partner_display_ref/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/partner_display_ref/__manifest__.py b/partner_display_ref/__manifest__.py new file mode 100644 index 00000000000..8a6040e0d49 --- /dev/null +++ b/partner_display_ref/__manifest__.py @@ -0,0 +1,14 @@ +# Copyright 2026 ForgeFlow S.L. +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +{ + "name": "Partner Display Reference", + "summary": "Prefix the customer reference to partner labels in opted-in views.", + "version": "19.0.1.0.0", + "category": "Tools", + "author": "ForgeFlow, Odoo Community Association (OCA)", + "website": "https://github.com/OCA/partner-contact", + "license": "AGPL-3", + "depends": ["contacts"], + "installable": True, +} diff --git a/partner_display_ref/models/__init__.py b/partner_display_ref/models/__init__.py new file mode 100644 index 00000000000..91fed54d404 --- /dev/null +++ b/partner_display_ref/models/__init__.py @@ -0,0 +1 @@ +from . import res_partner diff --git a/partner_display_ref/models/res_partner.py b/partner_display_ref/models/res_partner.py new file mode 100644 index 00000000000..1076cd32e4b --- /dev/null +++ b/partner_display_ref/models/res_partner.py @@ -0,0 +1,23 @@ +# Copyright 2026 ForgeFlow S.L. +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import api, models + + +class ResPartner(models.Model): + _inherit = "res.partner" + + @api.depends("ref") + @api.depends_context("partner_display_ref_field") + def _compute_display_name(self): + super()._compute_display_name() + ctx = self.env.context + field_name = ctx.get("partner_display_ref_field") + if not field_name: + return + if field_name not in self._fields: + return + for partner in self: + value = partner[field_name] + if value: + partner.display_name = f"[{value}] {partner.display_name}" diff --git a/partner_display_ref/pyproject.toml b/partner_display_ref/pyproject.toml new file mode 100644 index 00000000000..4231d0cccb3 --- /dev/null +++ b/partner_display_ref/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/partner_display_ref/readme/CONTRIBUTORS.md b/partner_display_ref/readme/CONTRIBUTORS.md new file mode 100644 index 00000000000..195652ad1ec --- /dev/null +++ b/partner_display_ref/readme/CONTRIBUTORS.md @@ -0,0 +1,2 @@ +- [ForgeFlow](https://www.forgeflow.com) + - Jasmin Solanki \<\> diff --git a/partner_display_ref/readme/DESCRIPTION.md b/partner_display_ref/readme/DESCRIPTION.md new file mode 100644 index 00000000000..943c3487720 --- /dev/null +++ b/partner_display_ref/readme/DESCRIPTION.md @@ -0,0 +1,10 @@ +This module prefixes the customer reference (`res.partner.ref`) to a partner's +`display_name` whenever it is rendered inside an opted-in view — shown as +`[C00123] Acme Corp` in the dropdown, the selected value, and list cells alike. + +The decoration is a generic mechanism: it activates only when a view injects +the `partner_display_ref_field` context key naming the field to prefix on a +`res.partner` field. Contacts, CRM, +Invoicing and any other view that does not opt in continue to see the plain +partner name. Companion modules (e.g. `sale_partner_display_ref`) wire this +mechanism into specific apps. diff --git a/partner_display_ref/readme/USAGE.md b/partner_display_ref/readme/USAGE.md new file mode 100644 index 00000000000..708dca9c33e --- /dev/null +++ b/partner_display_ref/readme/USAGE.md @@ -0,0 +1,14 @@ +To opt a view into the reference prefix, add the `partner_display_ref_field` +context key naming the `res.partner` field to prefix: + + + +Any `res.partner` field can be named (e.g. `ref`, `supplier_ref`). Set a value +on that field for a contact. In the opted-in view, the value is prefixed +wherever the partner is shown — the autocomplete dropdown, the selected value, +and list cells: + + [C00123] Acme Corp + +Views that do not opt in keep the plain partner name, so reports and exports +stay clean. If the named field is not installed, no prefix is applied. diff --git a/partner_display_ref/static/description/index.html b/partner_display_ref/static/description/index.html new file mode 100644 index 00000000000..c7818b64994 --- /dev/null +++ b/partner_display_ref/static/description/index.html @@ -0,0 +1,461 @@ + + + + + +README.rst + + + +
+ + + +Odoo Community Association + +
+

Partner Display Reference

+ +

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

+

This module prefixes the customer reference (res.partner.ref) to a +partner’s display_name whenever it is rendered inside an opted-in +view — shown as [C00123] Acme Corp in the dropdown, the selected +value, and list cells alike.

+

The decoration is a generic mechanism: it activates only when a view +injects the partner_display_ref_field context key naming the field +to prefix on a res.partner field. Contacts, CRM, Invoicing and any +other view that does not opt in continue to see the plain partner name. +Companion modules (e.g. sale_partner_display_ref) wire this +mechanism into specific apps.

+

Table of contents

+ +
+

Usage

+

To opt a view into the reference prefix, add the +partner_display_ref_field context key naming the res.partner +field to prefix:

+
+<field name="partner_id" context="{'partner_display_ref_field': 'ref'}" />
+
+

Any res.partner field can be named (e.g. ref, supplier_ref). +Set a value on that field for a contact. In the opted-in view, the value +is prefixed wherever the partner is shown — the autocomplete dropdown, +the selected value, and list cells:

+
+[C00123] Acme Corp
+
+

Views that do not opt in keep the plain partner name, so reports and +exports stay clean. If the named field is not installed, no prefix is +applied.

+
+
+

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

+
    +
  • ForgeFlow
  • +
+
+
+

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.

+

This module is part of the OCA/partner-contact project on GitHub.

+

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

+
+
+
+
+ + diff --git a/partner_display_ref/tests/__init__.py b/partner_display_ref/tests/__init__.py new file mode 100644 index 00000000000..5c654dfde7c --- /dev/null +++ b/partner_display_ref/tests/__init__.py @@ -0,0 +1 @@ +from . import test_partner_display_ref diff --git a/partner_display_ref/tests/test_partner_display_ref.py b/partner_display_ref/tests/test_partner_display_ref.py new file mode 100644 index 00000000000..bb09b3a3389 --- /dev/null +++ b/partner_display_ref/tests/test_partner_display_ref.py @@ -0,0 +1,67 @@ +# Copyright 2026 ForgeFlow S.L. +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo.tests import TransactionCase, tagged + + +@tagged("post_install", "-at_install") +class TestPartnerDisplayRef(TransactionCase): + """Decoration is gated solely by ``partner_display_ref_field`` naming the + ``res.partner`` field to prefix. + + Opted-in views inject ``partner_display_ref_field`` into the partner field + context. Whenever it lands in ``env.context`` (and the named field exists + and has a value) the ``[value]`` prefix is applied to ``display_name`` in + every context, leaving partners reached without the key untouched. + """ + + @classmethod + def setUpClass(cls): + super().setUpClass() + Partner = cls.env["res.partner"] + cls.prefix = "ZZPDR-" + cls.partner_with_ref = Partner.create( + {"name": f"{cls.prefix}Acme Corp", "ref": "C00123"} + ) + cls.partner_without_ref = Partner.create({"name": f"{cls.prefix}Globex"}) + + def test_field_key_decorates(self): + partner = self.partner_with_ref.with_context(partner_display_ref_field="ref") + self.assertEqual(partner.display_name, "[C00123] ZZPDR-Acme Corp") + + def test_formatted_alone_does_not_decorate(self): + partner = self.partner_with_ref.with_context(formatted_display_name=True) + self.assertEqual(partner.display_name, "ZZPDR-Acme Corp") + + def test_plain_display_name_untouched(self): + self.assertEqual(self.partner_with_ref.display_name, "ZZPDR-Acme Corp") + + def test_no_ref_falls_back_to_name(self): + self.partner_without_ref.ref = False + partner = self.partner_without_ref.with_context(partner_display_ref_field="ref") + self.assertEqual(partner.display_name, "ZZPDR-Globex") + + def test_unknown_field_is_ignored(self): + partner = self.partner_with_ref.with_context( + partner_display_ref_field="this_field_does_not_exist", + ) + self.assertEqual(partner.display_name, "ZZPDR-Acme Corp") + + def test_web_name_search_with_field_key(self): + Partner = self.env["res.partner"].with_context(partner_display_ref_field="ref") + domain = [("name", "=like", f"{self.prefix}%")] + results = Partner.web_name_search( + "Acme", {"display_name": {}}, domain=domain, limit=10 + ) + match = next(r for r in results if r["id"] == self.partner_with_ref.id) + self.assertEqual(match["__formatted_display_name"], "[C00123] ZZPDR-Acme Corp") + self.assertEqual(match["display_name"], "[C00123] ZZPDR-Acme Corp") + + def test_web_name_search_without_context(self): + Partner = self.env["res.partner"] + domain = [("name", "=like", f"{self.prefix}%")] + results = Partner.web_name_search( + "Acme", {"display_name": {}}, domain=domain, limit=10 + ) + match = next(r for r in results if r["id"] == self.partner_with_ref.id) + self.assertEqual(match["__formatted_display_name"], "ZZPDR-Acme Corp")