Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[16.0][MIG] sale_order_partner_restrict #2452

Open
wants to merge 10 commits into
base: 16.0
Choose a base branch
from
101 changes: 101 additions & 0 deletions sale_order_partner_restrict/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
===========================
Sale Order Partner Restrict
===========================

.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |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-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%2Fsale--workflow-lightgray.png?logo=github
:target: https://github.com/OCA/sale-workflow/tree/16.0/sale_order_partner_restrict
:alt: OCA/sale-workflow
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/sale-workflow-16-0/sale-workflow-16-0-sale_order_partner_restrict
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
:target: https://runbot.odoo-community.org/runbot/167/16.0
:alt: Try me on Runbot

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

This module allow you to choose what level of restriction you'd like to apply when selecting from the list of customers.

This configuration is available in Sales / Configuration / Settings, and the options available would be:

* All partners (default)
* Only parent accounts (no contacts)
* Parent accounts and contact persons

**Table of contents**

.. contents::
:local:

Usage
=====

To use this module, you need to:

#. Go to **Sales > Configuration > Settings**
#. Choose the filter you want to apply on partners.
#. Go to **Sales > Orders > Quotations**
#. Create a record and only available partners will appear on the list.

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

Bugs are tracked on `GitHub Issues <https://github.com/OCA/sale-workflow/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us smashing it by providing a detailed and welcomed
`feedback <https://github.com/OCA/sale-workflow/issues/new?body=module:%20sale_order_partner_restrict%0Aversion:%2016.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
~~~~~~~

* ForgeFlow

Contributors
~~~~~~~~~~~~

* Oriol Villamayor <oriol.villamayor@forgeflow.com>

* `Pesol <https://www.pesol.es>`__:

* Jonathan Oscategui Taza <info@pesol.es>

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

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

|maintainer-OriolVForgeFlow|

This module is part of the `OCA/sale-workflow <https://github.com/OCA/sale-workflow/tree/16.0/sale_order_partner_restrict>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
3 changes: 3 additions & 0 deletions sale_order_partner_restrict/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from . import models
14 changes: 14 additions & 0 deletions sale_order_partner_restrict/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
{
"name": "Sale Order Partner Restrict",
"summary": "Apply restrictions when selecting from the list of customers on SO.",
"version": "16.0.1.0.0",
"category": "Sales Management",
"website": "https://github.com/OCA/sale-workflow",
"author": "ForgeFlow, Odoo Community Association (OCA)",
"license": "AGPL-3",
"depends": ["sale_management"],
"data": ["views/res_config_settings_views.xml", "views/sale_order_view.xml"],
"installable": True,
"maintainers": ["OriolVForgeFlow"],
}
64 changes: 64 additions & 0 deletions sale_order_partner_restrict/i18n/sale_order_partner_restrict.pot
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * sale_order_partner_restrict
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 15.0\n"
"Report-Msgid-Bugs-To: \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: sale_order_partner_restrict
#: model:ir.model.fields.selection,name:sale_order_partner_restrict.selection__res_company__sale_order_partner_restrict__all
msgid "All partners"
msgstr ""

#. module: sale_order_partner_restrict
#: model_terms:ir.ui.view,arch_db:sale_order_partner_restrict.res_config_settings_view_form
msgid "Choose Partner Restrictions on Sale Orders"
msgstr ""

#. module: sale_order_partner_restrict
#: model:ir.model,name:sale_order_partner_restrict.model_res_company
msgid "Companies"
msgstr ""

#. module: sale_order_partner_restrict
#: model:ir.model,name:sale_order_partner_restrict.model_res_config_settings
msgid "Config Settings"
msgstr ""

#. module: sale_order_partner_restrict
#: model:ir.model.fields.selection,name:sale_order_partner_restrict.selection__res_company__sale_order_partner_restrict__only_parents
msgid "Only parent accounts (no contacts)"
msgstr ""

#. module: sale_order_partner_restrict
#: model:ir.model.fields.selection,name:sale_order_partner_restrict.selection__res_company__sale_order_partner_restrict__parents_and_contacts
msgid "Parent accounts and contacts"
msgstr ""

#. module: sale_order_partner_restrict
#: model:ir.model.fields,field_description:sale_order_partner_restrict.field_res_company__sale_order_partner_restrict
#: model:ir.model.fields,field_description:sale_order_partner_restrict.field_res_config_settings__sale_order_partner_restrict
#: model:ir.model.fields,field_description:sale_order_partner_restrict.field_sale_order__sale_order_partner_restrict
msgid "Partner Restriction on Sale Orders"
msgstr ""

#. module: sale_order_partner_restrict
#: model:ir.model,name:sale_order_partner_restrict.model_sale_order
msgid "Sales Order"
msgstr ""

#. module: sale_order_partner_restrict
#: code:addons/sale_order_partner_restrict/models/sale.py:0
#, python-format
msgid ""
"The Customer %(partner_name)s is not available for this company "
"(%(company_name)s)."
msgstr ""
5 changes: 5 additions & 0 deletions sale_order_partner_restrict/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from . import res_config_settings
from . import res_company
from . import sale
17 changes: 17 additions & 0 deletions sale_order_partner_restrict/models/res_company.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.

from odoo import fields, models


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

sale_order_partner_restrict = fields.Selection(
[
("all", "All partners"),
("only_parents", "Only parent accounts (no contacts)"),
("parents_and_contacts", "Parent accounts and contacts"),
],
"Partner Restriction on Sale Orders",
default="all",
)
13 changes: 13 additions & 0 deletions sale_order_partner_restrict/models/res_config_settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# 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_order_partner_restrict = fields.Selection(
related="company_id.sale_order_partner_restrict",
string="Partner Restriction on Sale Orders",
readonly=False,
)
74 changes: 74 additions & 0 deletions sale_order_partner_restrict/models/sale.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
from odoo import _, api, fields, models
from odoo.exceptions import ValidationError
from odoo.osv import expression


class SaleOrder(models.Model):
_inherit = "sale.order"

sale_order_partner_restrict = fields.Selection(
related="company_id.sale_order_partner_restrict",
string="Partner Restriction on Sale Orders",
)
sale_order_partner_restrict_ids = fields.Many2many(
comodel_name="res.partner", compute="_compute_sale_order_partner_restrict_ids"
)
partner_id = fields.Many2one(
domain="[('id', 'in', sale_order_partner_restrict_ids)]"
)

def _get_partner_restrict_domain(self):
partner_restrict_domain = []
if (
self.sale_order_partner_restrict == "all"
or self.sale_order_partner_restrict is None
):
partner_restrict_domain = [
"|",
("company_id", "=", False),
("company_id", "=", self.company_id.id),
]
elif self.sale_order_partner_restrict == "only_parents":
partner_restrict_domain = [
"&",
("parent_id", "=", False),
"|",
("company_id", "=", False),
("company_id", "=", self.company_id.id),
]
elif self.sale_order_partner_restrict == "parents_and_contacts":
partner_restrict_domain = [
"&",
"|",
("company_id", "=", False),
("company_id", "=", self.company_id.id),
"|",
("parent_id", "=", False),
("type", "=", "contact"),
]
return partner_restrict_domain

@api.depends("sale_order_partner_restrict")
def _compute_sale_order_partner_restrict_ids(self):
for rec in self:
domain = rec._get_partner_restrict_domain()
partners = self.env["res.partner"].search(domain)
rec.sale_order_partner_restrict_ids = partners.ids

@api.constrains("partner_id")
def _check_order_partner_restrict(self):
for order in self:
domain = order._get_partner_restrict_domain()
if not order.partner_id.search(
expression.AND([[("id", "=", order.partner_id.id)], domain])
):
raise ValidationError(
_(
"The Customer %(partner_name)s is not available for this "
"company (%(company_name)s)."
)
% {
"partner_name": order.partner_id.name,
"company_name": order.company_id.name,
}
)
5 changes: 5 additions & 0 deletions sale_order_partner_restrict/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
* Oriol Villamayor <oriol.villamayor@forgeflow.com>

* `Pesol <https://www.pesol.es>`__:

* Jonathan Oscategui Taza <info@pesol.es>
7 changes: 7 additions & 0 deletions sale_order_partner_restrict/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
This module allow you to choose what level of restriction you'd like to apply when selecting from the list of customers.

This configuration is available in Sales / Configuration / Settings, and the options available would be:

* All partners (default)
* Only parent accounts (no contacts)
* Parent accounts and contact persons
6 changes: 6 additions & 0 deletions sale_order_partner_restrict/readme/USAGE.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
To use this module, you need to:

#. Go to **Sales > Configuration > Settings**
#. Choose the filter you want to apply on partners.
#. Go to **Sales > Orders > Quotations**
#. Create a record and only available partners will appear on the list.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading