Skip to content

Commit

Permalink
[ADD] partner_contact_depth
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexPForgeFlow committed Sep 10, 2024
1 parent 52f198a commit ef12550
Show file tree
Hide file tree
Showing 14 changed files with 658 additions and 0 deletions.
90 changes: 90 additions & 0 deletions partner_contact_depth/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
==============
Contacts depth
==============

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:475225e6445c062ab0618f1f796fb131fb912603f6c00e2551613f918796d173
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |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%2Fpartner--contact-lightgray.png?logo=github
:target: https://github.com/OCA/partner-contact/tree/16.0/partner_contact_depth
: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-16-0/partner-contact-16-0-partner_contact_depth
: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=16.0
:alt: Try me on Runboat

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

This module adds the possibility of defining the maximum depth of the hierarchy of contacts

**Table of contents**

.. contents::
:local:

Usage
=====

There is a new system parameter which is called partner_contact_depth. contacts_max_depth

Behaviour:

#. contacts_max_depth = 0, no depth restrictions
#. contacts_max_depth = X, just will be allowed X levels of contacts hierarchy

Example:

#. If contacts_max_depth = 1, If we have Partner0 (depth=0) that his child is Partner1. If we try to add a new child to Partner1(depth=1), Partner2 (depth=2), a Validation Error will be raised as depth from Partner2 is greater that the contacts_max_depth

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_contact_depth%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 S.L.

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

* Àlex París <alex.paris@forgeflow.com>

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.

This module is part of the `OCA/partner-contact <https://github.com/OCA/partner-contact/tree/16.0/partner_contact_depth>`_ 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_contact_depth/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
18 changes: 18 additions & 0 deletions partner_contact_depth/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"name": "Contacts depth",
"summary": "Restricts maximum depth of the hierarchy of contacts",
"version": "16.0.1.0.0",
"category": "Customer Relationship Management",
"website": "https://github.com/OCA/partner-contact",
"author": "ForgeFlow S.L., Odoo Community Association (OCA)",
"license": "AGPL-3",
"application": False,
"installable": True,
"auto_install": False,
"depends": [
"contacts",
],
"data": [
"data/system_parameter.xml",
],
}
7 changes: 7 additions & 0 deletions partner_contact_depth/data/system_parameter.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo noupdate="1">
<record id="contacts_max_depth" model="ir.config_parameter">
<field name="key">partner_contact_depth.contacts_max_depth</field>
<field name="value">0</field>
</record>
</odoo>
1 change: 1 addition & 0 deletions partner_contact_depth/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import res_partner
38 changes: 38 additions & 0 deletions partner_contact_depth/models/res_partner.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
from odoo import _, api, fields, models
from odoo.exceptions import ValidationError


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

@api.depends("parent_id")
def _compute_contact_depth(self):
for partner in self:
depth = 0
parent = partner.parent_id
while parent:
depth += 1
parent = parent.parent_id
partner.depth = depth

depth = fields.Integer(compute="_compute_contact_depth", store=True)

@api.constrains("depth")
def check_maximum_contact_depth(self):
max_depth = int(
self.env["ir.config_parameter"]
.sudo()
.get_param("partner_contact_depth.contacts_max_depth", default=0)
)
for partner in self:
if 0 < max_depth < partner.depth:
raise ValidationError(
_(
"You have reached the maximum depth of contacts. "
"You cannot create childs for this contact."
)
)

def write(self, vals):
self.check_maximum_contact_depth()
return super().write(vals)
1 change: 1 addition & 0 deletions partner_contact_depth/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* Àlex París <alex.paris@forgeflow.com>
1 change: 1 addition & 0 deletions partner_contact_depth/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This module adds the possibility of defining the maximum depth of the hierarchy of contacts
10 changes: 10 additions & 0 deletions partner_contact_depth/readme/USAGE.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
There is a new system parameter which is called partner_contact_depth. contacts_max_depth

Behaviour:

#. contacts_max_depth = 0, no depth restrictions
#. contacts_max_depth = X, just will be allowed X levels of contacts hierarchy

Example:

#. If contacts_max_depth = 1, If we have Partner0 (depth=0) that his child is Partner1. If we try to add a new child to Partner1(depth=1), Partner2 (depth=2), a Validation Error will be raised as depth from Partner2 is greater that the contacts_max_depth
Loading

0 comments on commit ef12550

Please sign in to comment.