Skip to content

Commit

Permalink
[IMP] sale_partner_address_restrict: Be able to configure partner add…
Browse files Browse the repository at this point in the history
…ress restriction
  • Loading branch information
rousseldenis authored and JordiMForgeFlow committed Feb 7, 2025
1 parent 30defac commit 7c21efb
Show file tree
Hide file tree
Showing 10 changed files with 110 additions and 18 deletions.
11 changes: 10 additions & 1 deletion sale_partner_address_restrict/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Sale Partner Address Restrict
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:026c9b3f140a8467f57aa94ea7d898de824516f18656d2d7e750a60246399e3b
!! source digest: sha256:8861897ace83b8b0b2d9fea26ce71f146cc21b0b46a00ea4fb331af9a2dcf963
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
Expand Down Expand Up @@ -36,6 +36,15 @@ to only addresses of the selected customer.
.. contents::
:local:

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

- Go to Sales > Configuration > Settings > Quotation & Orders > Sale
Partner Address Restriction
- Check the box if you want to restrict available partners for Delivery
and Invoicing addresses to partners that belong to the selected
Customer.

Bug Tracker
===========

Expand Down
2 changes: 1 addition & 1 deletion sale_partner_address_restrict/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@
"depends": [
"sale",
],
"data": ["views/sale_order_view.xml"],
"data": ["views/sale_order_view.xml", "views/res_config_settings.xml"],
}
2 changes: 2 additions & 0 deletions sale_partner_address_restrict/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
from . import sale_order
from . import res_company
from . import res_config_settings
13 changes: 13 additions & 0 deletions sale_partner_address_restrict/models/res_company.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Copyright 2024 ACSONE SA/NV
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import fields, models


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

sale_partner_address_restriction = fields.Boolean(
help="Check this box if you want to restrict partner addresses selection "
"in sale orders. They should depends on the Customer filled in."
)
13 changes: 13 additions & 0 deletions sale_partner_address_restrict/models/res_config_settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Copyright 2024 ACSONE SA/NV
# 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"

sale_partner_address_restriction = fields.Boolean(
related="company_id.sale_partner_address_restriction",
readonly=False,
)
13 changes: 10 additions & 3 deletions sale_partner_address_restrict/models/sale_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,16 @@ class SaleOrder(models.Model):
@api.constrains("partner_id", "partner_invoice_id", "partner_shipping_id")
def _check_partner_addresses(self):
for order in self:
if order.partner_id and (
(order.partner_invoice_id.commercial_partner_id != order.partner_id)
or (order.partner_shipping_id.commercial_partner_id != order.partner_id)
if (
order.company_id.sale_partner_address_restriction
and order.partner_id
and (
(order.partner_invoice_id.commercial_partner_id != order.partner_id)
or (
order.partner_shipping_id.commercial_partner_id
!= order.partner_id
)
)
):
raise ValidationError(
_(
Expand Down
3 changes: 3 additions & 0 deletions sale_partner_address_restrict/readme/CONFIGURE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
- Go to Sales \> Configuration \> Settings \> Quotation & Orders \> Sale Partner Address Restriction
- Check the box if you want to restrict available partners for Delivery and Invoicing addresses to
partners that belong to the selected Customer.
33 changes: 22 additions & 11 deletions sale_partner_address_restrict/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -367,47 +367,58 @@ <h1 class="title">Sale Partner Address Restrict</h1>
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:026c9b3f140a8467f57aa94ea7d898de824516f18656d2d7e750a60246399e3b
!! source digest: sha256:8861897ace83b8b0b2d9fea26ce71f146cc21b0b46a00ea4fb331af9a2dcf963
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/partner-contact/tree/17.0/sale_partner_address_restrict"><img alt="OCA/partner-contact" src="https://img.shields.io/badge/github-OCA%2Fpartner--contact-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/partner-contact-17-0/partner-contact-17-0-sale_partner_address_restrict"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/partner-contact&amp;target_branch=17.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>This module restricts the addresses to be used in the sales order form
to only addresses of the selected customer.</p>
<p><strong>Table of contents</strong></p>
<div class="contents local topic" id="contents">
<ul class="simple">
<li><a class="reference internal" href="#bug-tracker" id="toc-entry-1">Bug Tracker</a></li>
<li><a class="reference internal" href="#credits" id="toc-entry-2">Credits</a><ul>
<li><a class="reference internal" href="#authors" id="toc-entry-3">Authors</a></li>
<li><a class="reference internal" href="#contributors" id="toc-entry-4">Contributors</a></li>
<li><a class="reference internal" href="#maintainers" id="toc-entry-5">Maintainers</a></li>
<li><a class="reference internal" href="#configuration" id="toc-entry-1">Configuration</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>
</ul>
</li>
</ul>
</div>
<div class="section" id="configuration">
<h1><a class="toc-backref" href="#toc-entry-1">Configuration</a></h1>
<ul class="simple">
<li>Go to Sales &gt; Configuration &gt; Settings &gt; Quotation &amp; Orders &gt; Sale
Partner Address Restriction</li>
<li>Check the box if you want to restrict available partners for Delivery
and Invoicing addresses to partners that belong to the selected
Customer.</li>
</ul>
</div>
<div class="section" id="bug-tracker">
<h1><a class="toc-backref" href="#toc-entry-1">Bug Tracker</a></h1>
<h1><a class="toc-backref" href="#toc-entry-2">Bug Tracker</a></h1>
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/sale-workflow/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/sale-workflow/issues/new?body=module:%20sale_partner_address_restrict%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-2">Credits</a></h1>
<h1><a class="toc-backref" href="#toc-entry-3">Credits</a></h1>
<div class="section" id="authors">
<h2><a class="toc-backref" href="#toc-entry-3">Authors</a></h2>
<h2><a class="toc-backref" href="#toc-entry-4">Authors</a></h2>
<ul class="simple">
<li>ForgeFlow</li>
</ul>
</div>
<div class="section" id="contributors">
<h2><a class="toc-backref" href="#toc-entry-4">Contributors</a></h2>
<h2><a class="toc-backref" href="#toc-entry-5">Contributors</a></h2>
<ul class="simple">
<li>Marina Alapont &lt;<a class="reference external" href="mailto:marina.alapont&#64;forgeflow.com">marina.alapont&#64;forgeflow.com</a>&gt;</li>
</ul>
</div>
<div class="section" id="maintainers">
<h2><a class="toc-backref" href="#toc-entry-5">Maintainers</a></h2>
<h2><a class="toc-backref" href="#toc-entry-6">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
16 changes: 14 additions & 2 deletions sale_partner_address_restrict/tests/test_sale_order.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from odoo.exceptions import ValidationError
from odoo.tests import Form
from odoo.tests.common import TransactionCase

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

class TestSaleOrder(TransactionCase):

class TestSaleOrder(BaseCommon):
@classmethod
def setUpClass(cls):
super().setUpClass()
Expand All @@ -17,6 +18,7 @@ def setUpClass(cls):

cls.partner2 = cls.env["res.partner"].create({"name": "Test Partner 2"})
cls.partner3 = cls.env["res.partner"].create({"name": "Test Partner 3"})
cls.env.company.sale_partner_address_restriction = True

def test_sale_order_address_domain(self):
order_form = Form(self.env["sale.order"])
Expand Down Expand Up @@ -53,3 +55,13 @@ def test_sale_order_address_constraint(self):
"partner_shipping_id": self.child_2.id,
}
)

def test_sale_order_address_no_constraint(self):
self.env.company.sale_partner_address_restriction = False
self.env["sale.order"].create(
{
"partner_id": self.partner1.id,
"partner_invoice_id": self.partner2.id,
"partner_shipping_id": self.child_2.id,
}
)
22 changes: 22 additions & 0 deletions sale_partner_address_restrict/views/res_config_settings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8" ?>
<!-- Copyright 2025 ACSONE SA/NV
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -->
<odoo>
<record id="res_config_settings_view_form" model="ir.ui.view">
<field name="name">res.config.settings.view.form.inherit.sale</field>
<field name="model">res.config.settings</field>
<field name="priority" eval="10" />
<field name="inherit_id" ref="base.res_config_settings_view_form" />
<field name="arch" type="xml">
<setting id="quotation_validity_days" position="after">
<setting
id="sale_partner_address_restrict"
help="Check this if you want to restrict the address selection to contacts of same company."
title="Address restriction"
>
<field name="sale_partner_address_restriction" />
</setting>
</setting>
</field>
</record>
</odoo>

0 comments on commit 7c21efb

Please sign in to comment.