Skip to content

Commit b597b30

Browse files
committed
Merge PR #2221 into 17.0
Signed-off-by NL66278
2 parents 9395e43 + fa7b11f commit b597b30

12 files changed

Lines changed: 230 additions & 31 deletions

File tree

partner_contact_address_default/README.rst

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,26 @@ contacts.
3737
.. contents::
3838
:local:
3939

40+
Configuration
41+
=============
42+
43+
1. Go to **Settings**.
44+
45+
2. Under **Contact Category**, configure the following options:
46+
47+
- | **Contact Address Default Allow All Partners**
48+
| Enable this option to allow selecting any partner, instead of
49+
being limited
50+
| to child contacts of the commercial partner.
51+
52+
- | **Contact Shipping Address Delivery & Partner Only**
53+
| Enable this option to restrict the **Shipping address** field to
54+
| delivery-type contacts of the commercial partner and the partner
55+
itself.
56+
| This setting takes precedence over **Contact Address Default
57+
Allow All
58+
Partners** for shipping addresses.
59+
4060
Usage
4161
=====
4262

@@ -65,23 +85,27 @@ Authors
6585
Contributors
6686
------------
6787

68-
- `Tecnativa <https://www.tecnativa.com>`__:
88+
- `Tecnativa <https://www.tecnativa.com>`__:
89+
90+
- Carlos Dauden
91+
- Sergio Teruel
92+
- Juan Carlos Oñate
93+
94+
- `Sygel <https://www.sygel.es>`__:
6995

70-
- Carlos Dauden
71-
- Sergio Teruel
72-
- Juan Carlos Oñate
96+
- Manuel Regidor
7397

74-
- `Sygel <https://www.sygel.es>`__:
98+
- `Studio73 <https://www.studio73.es>`__:
7599

76-
- Manuel Regidor
100+
- Carlos Reyes
77101

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

80-
- Carlos Reyes
104+
- Laura Cazorla
81105

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

84-
- Laura Cazorla
108+
- Aung Ko Ko Lin
85109

86110
Maintainers
87111
-----------

partner_contact_address_default/__manifest__.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
"license": "AGPL-3",
1515
"application": False,
1616
"installable": True,
17-
"depends": ["base"],
18-
"data": ["views/res_partner_views.xml"],
17+
"depends": ["base_setup"],
18+
"data": [
19+
"views/res_config_settings_views.xml",
20+
"views/res_partner_views.xml",
21+
],
1922
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
2+
from . import res_company
3+
from . import res_config_settings
24
from . import res_partner
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Copyright 2025 Quartile (https://www.quartile.co)
2+
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
3+
4+
from odoo import fields, models
5+
6+
7+
class ResCompany(models.Model):
8+
_inherit = "res.company"
9+
10+
contact_address_default_allow_all_partners = fields.Boolean()
11+
contact_shipping_address_delivery_partner_only = fields.Boolean()
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Copyright 2025 Quartile (https://www.quartile.co)
2+
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
3+
4+
from odoo import fields, models
5+
6+
7+
class ResConfigSettings(models.TransientModel):
8+
_inherit = "res.config.settings"
9+
10+
contact_address_default_allow_all_partners = fields.Boolean(
11+
related="company_id.contact_address_default_allow_all_partners",
12+
readonly=False,
13+
)
14+
contact_shipping_address_delivery_partner_only = fields.Boolean(
15+
related="company_id.contact_shipping_address_delivery_partner_only",
16+
readonly=False,
17+
)

partner_contact_address_default/models/res_partner.py

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
# Copyright 2020 Tecnativa - Sergio Teruel
33
# Copyright 2024 ForgeFlow S.L. (https://www.forgeflow.com)
44
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
5-
from odoo import fields, models
5+
from odoo import api, fields, models
6+
from odoo.osv import expression
67

78

89
class ResPartner(models.Model):
@@ -20,6 +21,39 @@ class ResPartner(models.Model):
2021
comodel_name="res.partner",
2122
string="Default contact",
2223
)
24+
partner_delivery_domain = fields.Binary(compute="_compute_partner_domains")
25+
partner_invoice_domain = fields.Binary(compute="_compute_partner_domains")
26+
partner_contact_domain = fields.Binary(compute="_compute_partner_domains")
27+
28+
@api.depends_context("company")
29+
@api.depends("commercial_partner_id")
30+
def _compute_partner_domains(self):
31+
company = self.env.company
32+
for partner in self:
33+
base_domain = [("id", "child_of", partner.commercial_partner_id.id)]
34+
if company.contact_shipping_address_delivery_partner_only:
35+
partner.partner_delivery_domain = expression.OR(
36+
[
37+
[("id", "=", partner.commercial_partner_id.id)],
38+
expression.AND([base_domain, [("type", "=", "delivery")]]),
39+
]
40+
)
41+
elif company.contact_address_default_allow_all_partners:
42+
partner.partner_delivery_domain = []
43+
else:
44+
partner.partner_delivery_domain = expression.AND(
45+
[base_domain, [("type", "=", "delivery")]]
46+
)
47+
if company.contact_address_default_allow_all_partners:
48+
partner.partner_invoice_domain = []
49+
partner.partner_contact_domain = []
50+
continue
51+
partner.partner_invoice_domain = expression.AND(
52+
[base_domain, [("type", "=", "invoice")]]
53+
)
54+
partner.partner_contact_domain = expression.AND(
55+
[base_domain, [("type", "=", "contact")]]
56+
)
2357

2458
def get_address_default_type(self):
2559
"""This will be the extension method for other contact types"""
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
1. Go to **Settings**.
2+
2. Under **Contact Category**, configure the following options:
3+
4+
* **Contact Address Default Allow All Partners**
5+
Enable this option to allow selecting any partner, instead of being limited
6+
to child contacts of the commercial partner.
7+
8+
* **Contact Shipping Address Delivery & Partner Only**
9+
Enable this option to restrict the **Shipping address** field to
10+
delivery-type contacts of the commercial partner and the partner itself.
11+
This setting takes precedence over **Contact Address Default Allow All
12+
Partners** for shipping addresses.

partner_contact_address_default/readme/CONTRIBUTORS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,5 @@
88
- Carlos Reyes
99
- [ForgeFlow](https://www.forgeflow.com):
1010
- Laura Cazorla
11+
- [Quartile](https://www.quartile.co):
12+
- Aung Ko Ko Lin

partner_contact_address_default/static/description/index.html

Lines changed: 45 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -376,42 +376,71 @@ <h1 class="title">Partner Contact address default</h1>
376376
<p><strong>Table of contents</strong></p>
377377
<div class="contents local topic" id="contents">
378378
<ul class="simple">
379-
<li><a class="reference internal" href="#usage" id="toc-entry-1">Usage</a></li>
380-
<li><a class="reference internal" href="#bug-tracker" id="toc-entry-2">Bug Tracker</a></li>
381-
<li><a class="reference internal" href="#credits" id="toc-entry-3">Credits</a><ul>
382-
<li><a class="reference internal" href="#authors" id="toc-entry-4">Authors</a></li>
383-
<li><a class="reference internal" href="#contributors" id="toc-entry-5">Contributors</a></li>
384-
<li><a class="reference internal" href="#maintainers" id="toc-entry-6">Maintainers</a></li>
379+
<li><a class="reference internal" href="#configuration" id="toc-entry-1">Configuration</a></li>
380+
<li><a class="reference internal" href="#usage" id="toc-entry-2">Usage</a></li>
381+
<li><a class="reference internal" href="#bug-tracker" id="toc-entry-3">Bug Tracker</a></li>
382+
<li><a class="reference internal" href="#credits" id="toc-entry-4">Credits</a><ul>
383+
<li><a class="reference internal" href="#authors" id="toc-entry-5">Authors</a></li>
384+
<li><a class="reference internal" href="#contributors" id="toc-entry-6">Contributors</a></li>
385+
<li><a class="reference internal" href="#maintainers" id="toc-entry-7">Maintainers</a></li>
385386
</ul>
386387
</li>
387388
</ul>
388389
</div>
390+
<div class="section" id="configuration">
391+
<h1><a class="toc-backref" href="#toc-entry-1">Configuration</a></h1>
392+
<ol class="arabic">
393+
<li><p class="first">Go to <strong>Settings</strong>.</p>
394+
</li>
395+
<li><p class="first">Under <strong>Contact Category</strong>, configure the following options:</p>
396+
<ul>
397+
<li><div class="first line-block">
398+
<div class="line"><strong>Contact Address Default Allow All Partners</strong></div>
399+
<div class="line">Enable this option to allow selecting any partner, instead of
400+
being limited</div>
401+
<div class="line">to child contacts of the commercial partner.</div>
402+
</div>
403+
</li>
404+
<li><div class="first line-block">
405+
<div class="line"><strong>Contact Shipping Address Delivery &amp; Partner Only</strong></div>
406+
<div class="line">Enable this option to restrict the <strong>Shipping address</strong> field to</div>
407+
<div class="line">delivery-type contacts of the commercial partner and the partner
408+
itself.</div>
409+
<div class="line">This setting takes precedence over <strong>Contact Address Default
410+
Allow All
411+
Partners</strong> for shipping addresses.</div>
412+
</div>
413+
</li>
414+
</ul>
415+
</li>
416+
</ol>
417+
</div>
389418
<div class="section" id="usage">
390-
<h1><a class="toc-backref" href="#toc-entry-1">Usage</a></h1>
419+
<h1><a class="toc-backref" href="#toc-entry-2">Usage</a></h1>
391420
<ol class="arabic simple">
392421
<li>Go to <em>Contacts</em>.</li>
393422
<li>Select default delivery address, invoice address or contact for
394423
partner.</li>
395424
</ol>
396425
</div>
397426
<div class="section" id="bug-tracker">
398-
<h1><a class="toc-backref" href="#toc-entry-2">Bug Tracker</a></h1>
427+
<h1><a class="toc-backref" href="#toc-entry-3">Bug Tracker</a></h1>
399428
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/partner-contact/issues">GitHub Issues</a>.
400429
In case of trouble, please check there if your issue has already been reported.
401430
If you spotted it first, help us to smash it by providing a detailed and welcomed
402431
<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>
403432
<p>Do not contact contributors directly about support or help with technical issues.</p>
404433
</div>
405434
<div class="section" id="credits">
406-
<h1><a class="toc-backref" href="#toc-entry-3">Credits</a></h1>
435+
<h1><a class="toc-backref" href="#toc-entry-4">Credits</a></h1>
407436
<div class="section" id="authors">
408-
<h2><a class="toc-backref" href="#toc-entry-4">Authors</a></h2>
437+
<h2><a class="toc-backref" href="#toc-entry-5">Authors</a></h2>
409438
<ul class="simple">
410439
<li>Tecnativa</li>
411440
</ul>
412441
</div>
413442
<div class="section" id="contributors">
414-
<h2><a class="toc-backref" href="#toc-entry-5">Contributors</a></h2>
443+
<h2><a class="toc-backref" href="#toc-entry-6">Contributors</a></h2>
415444
<ul class="simple">
416445
<li><a class="reference external" href="https://www.tecnativa.com">Tecnativa</a>:<ul>
417446
<li>Carlos Dauden</li>
@@ -431,10 +460,14 @@ <h2><a class="toc-backref" href="#toc-entry-5">Contributors</a></h2>
431460
<li>Laura Cazorla</li>
432461
</ul>
433462
</li>
463+
<li><a class="reference external" href="https://www.quartile.co">Quartile</a>:<ul>
464+
<li>Aung Ko Ko Lin</li>
465+
</ul>
466+
</li>
434467
</ul>
435468
</div>
436469
<div class="section" id="maintainers">
437-
<h2><a class="toc-backref" href="#toc-entry-6">Maintainers</a></h2>
470+
<h2><a class="toc-backref" href="#toc-entry-7">Maintainers</a></h2>
438471
<p>This module is maintained by the OCA.</p>
439472
<a class="reference external image-reference" href="https://odoo-community.org">
440473
<img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" />

partner_contact_address_default/tests/test_partner_contact_address_default.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
# Copyright 2020 Tecnativa - Carlos Dauden
22
# Copyright 2020 Tecnativa - Sergio Teruel
33
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
4+
5+
from odoo.osv import expression
6+
47
from odoo.addons.base.tests.common import BaseCommon
58

69

@@ -63,3 +66,29 @@ def test_contact_address_archived(self):
6366
self.assertEqual(res["delivery"], self.partner_child_delivery1.id)
6467
self.assertEqual(res["invoice"], self.partner.id)
6568
self.assertEqual(res["contact"], self.partner.id)
69+
70+
def test_partner_domains(self):
71+
self.partner._compute_partner_domains()
72+
expected_base = [("id", "child_of", self.partner.commercial_partner_id.id)]
73+
expected_delivery = expression.AND([expected_base, [("type", "=", "delivery")]])
74+
expected_invoice = expression.AND([expected_base, [("type", "=", "invoice")]])
75+
expected_contact = expression.AND([expected_base, [("type", "=", "contact")]])
76+
self.assertEqual(self.partner.partner_delivery_domain, expected_delivery)
77+
self.assertEqual(self.partner.partner_invoice_domain, expected_invoice)
78+
self.assertEqual(self.partner.partner_contact_domain, expected_contact)
79+
self.env.company.contact_address_default_allow_all_partners = True
80+
self.partner._compute_partner_domains()
81+
self.assertEqual(self.partner.partner_delivery_domain, [])
82+
self.assertEqual(self.partner.partner_invoice_domain, [])
83+
self.assertEqual(self.partner.partner_contact_domain, [])
84+
self.env.company.contact_shipping_address_delivery_partner_only = True
85+
self.partner._compute_partner_domains()
86+
expected_delivery = expression.OR(
87+
[
88+
[("id", "=", self.partner.commercial_partner_id.id)],
89+
expression.AND([expected_base, [("type", "=", "delivery")]]),
90+
]
91+
)
92+
self.assertEqual(self.partner.partner_delivery_domain, expected_delivery)
93+
self.assertEqual(self.partner.partner_invoice_domain, [])
94+
self.assertEqual(self.partner.partner_contact_domain, [])

0 commit comments

Comments
 (0)