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
44 changes: 34 additions & 10 deletions partner_contact_address_default/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,26 @@ contacts.
.. contents::
:local:

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

1. Go to **Settings**.

2. Under **Contact Category**, configure the following options:

- | **Contact Address Default Allow All Partners**
| Enable this option to allow selecting any partner, instead of
being limited
| to child contacts of the commercial partner.

- | **Contact Shipping Address Delivery & Partner Only**
| Enable this option to restrict the **Shipping address** field to
| delivery-type contacts of the commercial partner and the partner
itself.
| This setting takes precedence over **Contact Address Default
Allow All
Partners** for shipping addresses.

Usage
=====

Expand Down Expand Up @@ -65,23 +85,27 @@ Authors
Contributors
------------

- `Tecnativa <https://www.tecnativa.com>`__:
- `Tecnativa <https://www.tecnativa.com>`__:

- Carlos Dauden
- Sergio Teruel
- Juan Carlos Oñate

- `Sygel <https://www.sygel.es>`__:

- Carlos Dauden
- Sergio Teruel
- Juan Carlos Oñate
- Manuel Regidor

- `Sygel <https://www.sygel.es>`__:
- `Studio73 <https://www.studio73.es>`__:

- Manuel Regidor
- Carlos Reyes

- `Studio73 <https://www.studio73.es>`__:
- `ForgeFlow <https://www.forgeflow.com>`__:

- Carlos Reyes
- Laura Cazorla

- `ForgeFlow <https://www.forgeflow.com>`__:
- `Quartile <https://www.quartile.co>`__:

- Laura Cazorla
- Aung Ko Ko Lin

Maintainers
-----------
Expand Down
7 changes: 5 additions & 2 deletions partner_contact_address_default/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
"license": "AGPL-3",
"application": False,
"installable": True,
"depends": ["base"],
"data": ["views/res_partner_views.xml"],
"depends": ["base_setup"],
"data": [
"views/res_config_settings_views.xml",
"views/res_partner_views.xml",
],
}
2 changes: 2 additions & 0 deletions partner_contact_address_default/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from . import res_company
from . import res_config_settings
from . import res_partner
11 changes: 11 additions & 0 deletions partner_contact_address_default/models/res_company.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Copyright 2025 Quartile (https://www.quartile.co)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import fields, models


class ResCompany(models.Model):
_inherit = "res.company"

contact_address_default_allow_all_partners = fields.Boolean()
contact_shipping_address_delivery_partner_only = fields.Boolean()
17 changes: 17 additions & 0 deletions partner_contact_address_default/models/res_config_settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Copyright 2025 Quartile (https://www.quartile.co)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import fields, models


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

contact_address_default_allow_all_partners = fields.Boolean(
related="company_id.contact_address_default_allow_all_partners",
readonly=False,
)
contact_shipping_address_delivery_partner_only = fields.Boolean(
related="company_id.contact_shipping_address_delivery_partner_only",
readonly=False,
)
36 changes: 35 additions & 1 deletion partner_contact_address_default/models/res_partner.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
# Copyright 2020 Tecnativa - Sergio Teruel
# Copyright 2024 ForgeFlow S.L. (https://www.forgeflow.com)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo import fields, models
from odoo import api, fields, models
from odoo.osv import expression


class ResPartner(models.Model):
Expand All @@ -20,6 +21,39 @@ class ResPartner(models.Model):
comodel_name="res.partner",
string="Default contact",
)
partner_delivery_domain = fields.Binary(compute="_compute_partner_domains")
partner_invoice_domain = fields.Binary(compute="_compute_partner_domains")
partner_contact_domain = fields.Binary(compute="_compute_partner_domains")

@api.depends_context("company")
@api.depends("commercial_partner_id")
def _compute_partner_domains(self):
company = self.env.company
for partner in self:
base_domain = [("id", "child_of", partner.commercial_partner_id.id)]
if company.contact_shipping_address_delivery_partner_only:
partner.partner_delivery_domain = expression.OR(
[
[("id", "=", partner.commercial_partner_id.id)],
expression.AND([base_domain, [("type", "=", "delivery")]]),
]
)
elif company.contact_address_default_allow_all_partners:
partner.partner_delivery_domain = []
else:
partner.partner_delivery_domain = expression.AND(
[base_domain, [("type", "=", "delivery")]]
)
if company.contact_address_default_allow_all_partners:
partner.partner_invoice_domain = []
partner.partner_contact_domain = []
continue
partner.partner_invoice_domain = expression.AND(
[base_domain, [("type", "=", "invoice")]]
)
partner.partner_contact_domain = expression.AND(
[base_domain, [("type", "=", "contact")]]
)

def get_address_default_type(self):
"""This will be the extension method for other contact types"""
Expand Down
12 changes: 12 additions & 0 deletions partner_contact_address_default/readme/CONFIGURE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
1. Go to **Settings**.
2. Under **Contact Category**, configure the following options:

* **Contact Address Default Allow All Partners**
Enable this option to allow selecting any partner, instead of being limited
to child contacts of the commercial partner.

* **Contact Shipping Address Delivery & Partner Only**
Enable this option to restrict the **Shipping address** field to
delivery-type contacts of the commercial partner and the partner itself.
This setting takes precedence over **Contact Address Default Allow All
Partners** for shipping addresses.
2 changes: 2 additions & 0 deletions partner_contact_address_default/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@
- Carlos Reyes
- [ForgeFlow](https://www.forgeflow.com):
- Laura Cazorla
- [Quartile](https://www.quartile.co):
- Aung Ko Ko Lin
57 changes: 45 additions & 12 deletions partner_contact_address_default/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -376,42 +376,71 @@ <h1 class="title">Partner Contact address default</h1>
<p><strong>Table of contents</strong></p>
<div class="contents local topic" id="contents">
<ul class="simple">
<li><a class="reference internal" href="#usage" id="toc-entry-1">Usage</a></li>
<li><a class="reference internal" href="#bug-tracker" id="toc-entry-2">Bug Tracker</a></li>
<li><a class="reference internal" href="#credits" id="toc-entry-3">Credits</a><ul>
<li><a class="reference internal" href="#authors" id="toc-entry-4">Authors</a></li>
<li><a class="reference internal" href="#contributors" id="toc-entry-5">Contributors</a></li>
<li><a class="reference internal" href="#maintainers" id="toc-entry-6">Maintainers</a></li>
<li><a class="reference internal" href="#configuration" id="toc-entry-1">Configuration</a></li>
<li><a class="reference internal" href="#usage" id="toc-entry-2">Usage</a></li>
<li><a class="reference internal" href="#bug-tracker" id="toc-entry-3">Bug Tracker</a></li>
<li><a class="reference internal" href="#credits" id="toc-entry-4">Credits</a><ul>
<li><a class="reference internal" href="#authors" id="toc-entry-5">Authors</a></li>
<li><a class="reference internal" href="#contributors" id="toc-entry-6">Contributors</a></li>
<li><a class="reference internal" href="#maintainers" id="toc-entry-7">Maintainers</a></li>
</ul>
</li>
</ul>
</div>
<div class="section" id="configuration">
<h1><a class="toc-backref" href="#toc-entry-1">Configuration</a></h1>
<ol class="arabic">
<li><p class="first">Go to <strong>Settings</strong>.</p>
</li>
<li><p class="first">Under <strong>Contact Category</strong>, configure the following options:</p>
<ul>
<li><div class="first line-block">
<div class="line"><strong>Contact Address Default Allow All Partners</strong></div>
<div class="line">Enable this option to allow selecting any partner, instead of
being limited</div>
<div class="line">to child contacts of the commercial partner.</div>
</div>
</li>
<li><div class="first line-block">
<div class="line"><strong>Contact Shipping Address Delivery &amp; Partner Only</strong></div>
<div class="line">Enable this option to restrict the <strong>Shipping address</strong> field to</div>
<div class="line">delivery-type contacts of the commercial partner and the partner
itself.</div>
<div class="line">This setting takes precedence over <strong>Contact Address Default
Allow All
Partners</strong> for shipping addresses.</div>
</div>
</li>
</ul>
</li>
</ol>
</div>
<div class="section" id="usage">
<h1><a class="toc-backref" href="#toc-entry-1">Usage</a></h1>
<h1><a class="toc-backref" href="#toc-entry-2">Usage</a></h1>
<ol class="arabic simple">
<li>Go to <em>Contacts</em>.</li>
<li>Select default delivery address, invoice address or contact for
partner.</li>
</ol>
</div>
<div class="section" id="bug-tracker">
<h1><a class="toc-backref" href="#toc-entry-2">Bug Tracker</a></h1>
<h1><a class="toc-backref" href="#toc-entry-3">Bug Tracker</a></h1>
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/partner-contact/issues">GitHub Issues</a>.
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
<a class="reference external" href="https://github.com/OCA/partner-contact/issues/new?body=module:%20partner_contact_address_default%0Aversion:%2017.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<p>Do not contact contributors directly about support or help with technical issues.</p>
</div>
<div class="section" id="credits">
<h1><a class="toc-backref" href="#toc-entry-3">Credits</a></h1>
<h1><a class="toc-backref" href="#toc-entry-4">Credits</a></h1>
<div class="section" id="authors">
<h2><a class="toc-backref" href="#toc-entry-4">Authors</a></h2>
<h2><a class="toc-backref" href="#toc-entry-5">Authors</a></h2>
<ul class="simple">
<li>Tecnativa</li>
</ul>
</div>
<div class="section" id="contributors">
<h2><a class="toc-backref" href="#toc-entry-5">Contributors</a></h2>
<h2><a class="toc-backref" href="#toc-entry-6">Contributors</a></h2>
<ul class="simple">
<li><a class="reference external" href="https://www.tecnativa.com">Tecnativa</a>:<ul>
<li>Carlos Dauden</li>
Expand All @@ -431,10 +460,14 @@ <h2><a class="toc-backref" href="#toc-entry-5">Contributors</a></h2>
<li>Laura Cazorla</li>
</ul>
</li>
<li><a class="reference external" href="https://www.quartile.co">Quartile</a>:<ul>
<li>Aung Ko Ko Lin</li>
</ul>
</li>
</ul>
</div>
<div class="section" id="maintainers">
<h2><a class="toc-backref" href="#toc-entry-6">Maintainers</a></h2>
<h2><a class="toc-backref" href="#toc-entry-7">Maintainers</a></h2>
<p>This module is maintained by the OCA.</p>
<a class="reference external image-reference" href="https://odoo-community.org">
<img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Copyright 2020 Tecnativa - Carlos Dauden
# Copyright 2020 Tecnativa - Sergio Teruel
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).

from odoo.osv import expression

from odoo.addons.base.tests.common import BaseCommon


Expand Down Expand Up @@ -63,3 +66,29 @@ def test_contact_address_archived(self):
self.assertEqual(res["delivery"], self.partner_child_delivery1.id)
self.assertEqual(res["invoice"], self.partner.id)
self.assertEqual(res["contact"], self.partner.id)

def test_partner_domains(self):
self.partner._compute_partner_domains()
expected_base = [("id", "child_of", self.partner.commercial_partner_id.id)]
expected_delivery = expression.AND([expected_base, [("type", "=", "delivery")]])
expected_invoice = expression.AND([expected_base, [("type", "=", "invoice")]])
expected_contact = expression.AND([expected_base, [("type", "=", "contact")]])
self.assertEqual(self.partner.partner_delivery_domain, expected_delivery)
self.assertEqual(self.partner.partner_invoice_domain, expected_invoice)
self.assertEqual(self.partner.partner_contact_domain, expected_contact)
self.env.company.contact_address_default_allow_all_partners = True
self.partner._compute_partner_domains()
self.assertEqual(self.partner.partner_delivery_domain, [])
self.assertEqual(self.partner.partner_invoice_domain, [])
self.assertEqual(self.partner.partner_contact_domain, [])
self.env.company.contact_shipping_address_delivery_partner_only = True
self.partner._compute_partner_domains()
expected_delivery = expression.OR(
[
[("id", "=", self.partner.commercial_partner_id.id)],
expression.AND([expected_base, [("type", "=", "delivery")]]),
]
)
self.assertEqual(self.partner.partner_delivery_domain, expected_delivery)
self.assertEqual(self.partner.partner_invoice_domain, [])
self.assertEqual(self.partner.partner_contact_domain, [])
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<record id="res_config_settings_view_form" model="ir.ui.view">
<field name="name">res.config.settings.view.form.inherit</field>
<field name="model">res.config.settings</field>
<field name="inherit_id" ref="base_setup.res_config_settings_view_form" />
<field name="arch" type="xml">
<xpath expr="//setting[@id='partner_autocomplete']" position="after">
<setting
help="If enabled, the default delivery, invoice, and contact addresses are not limited to the partner’s child contacts—you can select any contact."
id="contact_address_default_allow_all_partners"
>
<field name="contact_address_default_allow_all_partners" />
</setting>
<setting
id="contact_shipping_address_delivery_partner_only"
help="If enabled, the Shipping address field is limited to delivery-type
contacts of the commercial partner and the partner itself. This setting
takes precedence over allowing all partners for shipping addresses."
>
<field name="contact_shipping_address_delivery_partner_only" />
</setting>
</xpath>
</field>
</record>
</odoo>
Loading