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
96 changes: 96 additions & 0 deletions partner_owner_company/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
=====================
Partner Owner Company
=====================

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

.. |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-LGPL--3-blue.png
:target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html
:alt: License: LGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fpartner--contact-lightgray.png?logo=github
:target: https://github.com/OCA/partner-contact/tree/17.0/partner_owner_company
: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-17-0/partner-contact-17-0-partner_owner_company
: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=17.0
:alt: Try me on Runboat

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

Add owner_company_id field to contacts as soft alternative to company_id
for tracking company belonging without enforcing access security.

**Table of contents**

.. contents::
:local:

Usage
=====

After installing the module, you'll see a new "Owner Company" field on
contact forms:

When selecting a contact in a dropdown selection field, only the
contacts owned by the current company, or global, are proposed. Contacts
owned by other companies can still be selected, by extact match of name,
reference code, email, or Tax/VAt number.

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_owner_company%0Aversion:%2017.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

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-dreispt| image:: https://github.com/dreispt.png?size=40px
:target: https://github.com/dreispt
:alt: dreispt

Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:

|maintainer-dreispt|

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

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
1 change: 1 addition & 0 deletions partner_owner_company/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
19 changes: 19 additions & 0 deletions partner_owner_company/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Copyright 2026 Open Source Integrators
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).

{
"name": "Partner Owner Company",
"summary": "Add owner_company_id field to contacts as soft alternative "
"to company_id",
"version": "17.0.1.0.0",
"category": "Extra Tools",
"website": "https://github.com/OCA/partner-contact",
"author": "Open Source Integrators, Odoo Community Association (OCA)",
"license": "LGPL-3",
"maintainers": ["dreispt"],
"depends": ["contacts"],
"data": [
"views/res_partner_view.xml",
],
"installable": True,
}
38 changes: 38 additions & 0 deletions partner_owner_company/i18n/fr_FR.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * partner_owner_company
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 17.0+e\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2026-01-21 12:59+0000\n"
"PO-Revision-Date: 2026-01-21 12:59+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_owner_company
#: model:ir.model.fields,help:partner_owner_company.field_res_partner__owner_company_id
#: model:ir.model.fields,help:partner_owner_company.field_res_users__owner_company_id
msgid ""
"Company that owns this contact. This is a soft alternative to company_id "
"that doesn't enforce access security but allows tracking company belonging."
msgstr ""
"Société qui possède ce contact. C'est une alternative douce à company_id "
"qui n'applique pas la sécurité d'accès mais permet de suivre l'appartenance à la société."

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

#. module: partner_owner_company
#: model:ir.model.fields,field_description:partner_owner_company.field_res_partner__owner_company_id
#: model:ir.model.fields,field_description:partner_owner_company.field_res_users__owner_company_id
#: model_terms:ir.ui.view,arch_db:partner_owner_company.view_res_partner_filter_owner_company
msgid "Owner Company"
msgstr "Société propriétaire"
36 changes: 36 additions & 0 deletions partner_owner_company/i18n/partner_owner_company.pot
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * partner_owner_company
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 17.0+e\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2026-01-21 13:00+0000\n"
"PO-Revision-Date: 2026-01-21 13:00+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_owner_company
#: model:ir.model.fields,help:partner_owner_company.field_res_partner__owner_company_id
#: model:ir.model.fields,help:partner_owner_company.field_res_users__owner_company_id
msgid ""
"Company that owns this contact. This is a soft alternative to company_id "
"that doesn't enforce access security but allows tracking company belonging."
msgstr ""

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

#. module: partner_owner_company
#: model:ir.model.fields,field_description:partner_owner_company.field_res_partner__owner_company_id
#: model:ir.model.fields,field_description:partner_owner_company.field_res_users__owner_company_id
#: model_terms:ir.ui.view,arch_db:partner_owner_company.view_res_partner_filter_owner_company
msgid "Owner Company"
msgstr ""
1 change: 1 addition & 0 deletions partner_owner_company/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import res_partner
114 changes: 114 additions & 0 deletions partner_owner_company/models/res_partner.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
# Copyright 2026 Open Source Integrators
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).

from odoo import api, fields, models
from odoo.osv import expression


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

owner_company_id = fields.Many2one(
"res.company",
string="Owner Company",
help="Company that owns this contact. This is a soft alternative to company_id "
"that doesn't enforce access security but allows tracking company belonging.",
index=True,
)

@api.onchange("parent_id")
def _onchange_owner_company_parent(self):
if self.parent_id:
self.owner_company_id = self.parent_id.owner_company_id

@api.model_create_multi
def create(self, vals_list):
# Apply ownership inheritance to UI, import, and RPC creations alike.
partners = super().create(vals_list)
partners._sync_owner_company()
return partners

def write(self, vals):
# A child cannot override the owner inherited from its parent.
result = super().write(vals)
if "parent_id" in vals or "owner_company_id" in vals:
self._sync_owner_company()
return result

@api.model
def name_search(self, name="", args=None, operator="ilike", limit=100):
"""
Override name_search to prioritize current company contacts unless:
- Full name match
- Exact code/ref match
- Exact email match
"""
args = args or []
# For partial matches, prioritize current company contacts
# Logic: Show contacts where:
# 1. Contact belongs to current company, OR
# 2. Contact's parent belongs to current company, OR
# 3. Contact has no owner company AND
# (no parent OR parent has no owner company)
current_company = self.env.company.id
belongs_to_company = expression.OR(
[
[("owner_company_id", "parent_of", [current_company])],
[("parent_id.owner_company_id", "parent_of", [current_company])],
]
)
no_company_owner = expression.AND(
[
[("owner_company_id", "=", False)],
expression.OR(
[
[("parent_id", "=", False)], # Top-level contact
[
("parent_id.owner_company_id", "=", False)
], # Parent has no owner
]
),
]
)
owner_args = expression.OR([belongs_to_company, no_company_owner])
res = super().name_search(
name, expression.AND([owner_args, args]), operator, limit
)

# If not result, try exact matches (bypasses company filtering)
# Check if search term matches full name, exact code, or exact email
if name and not res:
exact_match_domain = [
"|",
("name", "=ilike", name),
"|",
("ref", "=ilike", name),
"|",
("email", "=ilike", name),
("vat", "=ilike", name),
]
res = super().name_search(name, exact_match_domain + args, operator, limit)

return res

def _sync_owner_company(self):
"""Synchronize ownership from the root, one generation at a time."""
roots = self
if not self.env.context.get("_partner_owner_company_propagating"):
roots = self.browse()
# commercial_partner_id stops at child companies; ownership follows
# the full parent hierarchy, including companies with a parent.
for partner in self:
root = partner
while root.parent_id:
root = root.parent_id
roots |= root
for root in roots:
children = self.with_context(active_test=False).search(
[("parent_id", "=", root.id)]
)
if children:
# Continue downward without restarting from the root on each write.
children.with_context(_partner_owner_company_propagating=True).write(
{"owner_company_id": root.owner_company_id.id}
)
3 changes: 3 additions & 0 deletions partner_owner_company/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build-system]
requires = ["whool"]
build-backend = "whool.buildapi"
1 change: 1 addition & 0 deletions partner_owner_company/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Open Source Integrators
1 change: 1 addition & 0 deletions partner_owner_company/readme/DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add owner_company_id field to contacts as soft alternative to company_id for tracking company belonging without enforcing access security.
14 changes: 14 additions & 0 deletions partner_owner_company/readme/USAGE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
After installing the module, multi-company users will see a new "Owner Company" field on contact forms.

Child contacts inherit their parent's owner company automatically, including when they are moved to another parent.
The owner company is read-only on child contacts. Change it on the top-level contact instead; changes also apply to archived descendants. Synchronization starts from the top-level contact, so all branches of its contact hierarchy use the same owner company.

Clearing a parent's owner company clears it for its descendants.
Removing a contact's parent keeps its last inherited owner company, which can then be edited independently.

When selecting a contact in a dropdown selection field, partial-name searches propose contacts owned by the current company or global contacts.
If no matching contact is found, contacts owned by other companies can still be selected by an exact match of their name, reference code, email, or Tax/VAT number.

This filtering applies only to the dropdown's autocomplete suggestions (`name_search`).
The **Search More** dialog and the Contacts list do not apply this owner-company filtering: partial-name searches there can return contacts owned by other companies, subject to the usual access rights and record rules.
The owner company is not an access restriction.
Loading
Loading