Skip to content

Commit

Permalink
[18.0][MIG] crm_team_parent
Browse files Browse the repository at this point in the history
  • Loading branch information
sbejaoui committed Jan 8, 2025
1 parent 0cd8c48 commit cd9952b
Show file tree
Hide file tree
Showing 13 changed files with 54 additions and 76 deletions.
29 changes: 15 additions & 14 deletions crm_team_parent/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,20 @@ Crm Team Parent
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fcrm-lightgray.png?logo=github
:target: https://github.com/OCA/crm/tree/12.0/crm_team_parent
:target: https://github.com/OCA/crm/tree/18.0/crm_team_parent
:alt: OCA/crm
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/crm-12-0/crm-12-0-crm_team_parent
:target: https://translation.odoo-community.org/projects/crm-18-0/crm-18-0-crm_team_parent
: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/crm&target_branch=12.0
:target: https://runboat.odoo-community.org/builds?repo=OCA/crm&target_branch=18.0
:alt: Try me on Runboat

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

This module adds a 'Parent Team' field on the Sales Team form. This field is also displayed in the Sales Teams list.
Plus, a constraint check is performed in order to avoid loops in the hierarchy.
This module adds a 'Parent Team' field on the Sales Team form. This
field is also displayed in the Sales Teams list. Plus, a constraint
check is performed in order to avoid loops in the hierarchy.

**Table of contents**

Expand All @@ -41,35 +42,35 @@ Usage

To use this module, you need to:

#. Go to *CRM > Configuration > Sales Teams*.
#. Create/edit a sales team.
#. The parent team will be checked for loop in the hierarchy.
1. Go to *CRM > Configuration > Sales Teams*.
2. Create/edit a sales team.
3. The parent team will be checked for loop in the hierarchy.

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

Bugs are tracked on `GitHub Issues <https://github.com/OCA/crm/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/crm/issues/new?body=module:%20crm_team_parent%0Aversion:%2012.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
`feedback <https://github.com/OCA/crm/issues/new?body=module:%20crm_team_parent%0Aversion:%2018.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
~~~~~~~
-------

* ACSONE SA/NV

Contributors
~~~~~~~~~~~~
------------

* Quentin Groulard <quentin.groulard@acsone.eu>
- Quentin Groulard <quentin.groulard@acsone.eu>

Maintainers
~~~~~~~~~~~
-----------

This module is maintained by the OCA.

Expand All @@ -81,6 +82,6 @@ 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/crm <https://github.com/OCA/crm/tree/12.0/crm_team_parent>`_ project on GitHub.
This module is part of the `OCA/crm <https://github.com/OCA/crm/tree/18.0/crm_team_parent>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
2 changes: 1 addition & 1 deletion crm_team_parent/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"name": "Crm Team Parent",
"summary": """
Add a parent field on sales teams.""",
"version": "12.0.1.0.1",
"version": "18.0.1.0.0",
"license": "AGPL-3",
"author": "ACSONE SA/NV,Odoo Community Association (OCA)",
"website": "https://github.com/OCA/crm",
Expand Down
26 changes: 1 addition & 25 deletions crm_team_parent/models/crm_team.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
# Copyright 2018 ACSONE SA/NV
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import api, fields, models, _
from odoo.exceptions import ValidationError


class ParentLoopError(ValidationError):
pass
from odoo import fields, models


class CrmTeam(models.Model):

_inherit = "crm.team"
_parent_store = True
parent_path = fields.Char(index=True)
Expand All @@ -20,21 +14,3 @@ class CrmTeam(models.Model):
inverse_name="parent_id",
string="Children team",
)

@api.constrains("parent_id")
def _constrains_parent_id(self):
def _check_for_loop(new_child, current):
if not current.parent_id:
return True
if current.parent_id == new_child:
return False
return _check_for_loop(new_child, current.parent_id)

for rec in self.filtered("parent_id"):
if not _check_for_loop(rec, rec):
raise ParentLoopError(
_(
"Wrong Parent Team: "
"No loop allowed in the teams' hierarchy."
)
)
3 changes: 3 additions & 0 deletions crm_team_parent/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build-system]
requires = ["whool"]
build-backend = "whool.buildapi"
1 change: 1 addition & 0 deletions crm_team_parent/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Quentin Groulard \<<quentin.groulard@acsone.eu>\>
1 change: 0 additions & 1 deletion crm_team_parent/readme/CONTRIBUTORS.rst

This file was deleted.

3 changes: 3 additions & 0 deletions crm_team_parent/readme/DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
This module adds a 'Parent Team' field on the Sales Team form. This
field is also displayed in the Sales Teams list. Plus, a constraint
check is performed in order to avoid loops in the hierarchy.
2 changes: 0 additions & 2 deletions crm_team_parent/readme/DESCRIPTION.rst

This file was deleted.

5 changes: 5 additions & 0 deletions crm_team_parent/readme/USAGE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
To use this module, you need to:

1. Go to *CRM \> Configuration \> Sales Teams*.
2. Create/edit a sales team.
3. The parent team will be checked for loop in the hierarchy.
5 changes: 0 additions & 5 deletions crm_team_parent/readme/USAGE.rst

This file was deleted.

23 changes: 13 additions & 10 deletions crm_team_parent/static/description/index.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
Expand All @@ -9,10 +8,11 @@

/*
:Author: David Goodger (goodger@python.org)
:Id: $Id: html4css1.css 8954 2022-01-20 10:10:25Z milde $
:Id: $Id: html4css1.css 9511 2024-01-13 09:50:07Z milde $
:Copyright: This stylesheet has been placed in the public domain.
Default cascading style sheet for the HTML output of Docutils.
Despite the name, some widely supported CSS2 features are used.
See https://docutils.sourceforge.io/docs/howto/html-stylesheets.html for how to
customize this style sheet.
Expand Down Expand Up @@ -275,7 +275,7 @@
margin-left: 2em ;
margin-right: 2em }

pre.code .ln { color: grey; } /* line numbers */
pre.code .ln { color: gray; } /* line numbers */
pre.code, code { background-color: #eeeeee }
pre.code .comment, code .comment { color: #5C6576 }
pre.code .keyword, code .keyword { color: #3B0D06; font-weight: bold }
Expand All @@ -301,7 +301,7 @@
span.pre {
white-space: pre }

span.problematic {
span.problematic, pre.problematic {
color: red }

span.section-subtitle {
Expand Down Expand Up @@ -369,9 +369,10 @@ <h1 class="title">Crm Team Parent</h1>
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:bd18df725ebb5ecd3adf6c26bc7889ab49a650a5214ecac36ec2c0d7dce73914
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<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/crm/tree/12.0/crm_team_parent"><img alt="OCA/crm" src="https://img.shields.io/badge/github-OCA%2Fcrm-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/crm-12-0/crm-12-0-crm_team_parent"><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/crm&amp;target_branch=12.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>This module adds a ‘Parent Team’ field on the Sales Team form. This field is also displayed in the Sales Teams list.
Plus, a constraint check is performed in order to avoid loops in the hierarchy.</p>
<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/crm/tree/18.0/crm_team_parent"><img alt="OCA/crm" src="https://img.shields.io/badge/github-OCA%2Fcrm-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/crm-18-0/crm-18-0-crm_team_parent"><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/crm&amp;target_branch=18.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>This module adds a ‘Parent Team’ field on the Sales Team form. This
field is also displayed in the Sales Teams list. Plus, a constraint
check is performed in order to avoid loops in the hierarchy.</p>
<p><strong>Table of contents</strong></p>
<div class="contents local topic" id="contents">
<ul class="simple">
Expand Down Expand Up @@ -399,7 +400,7 @@ <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/crm/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/crm/issues/new?body=module:%20crm_team_parent%0Aversion:%2012.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<a class="reference external" href="https://github.com/OCA/crm/issues/new?body=module:%20crm_team_parent%0Aversion:%2018.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">
Expand All @@ -419,11 +420,13 @@ <h2><a class="toc-backref" href="#toc-entry-5">Contributors</a></h2>
<div class="section" id="maintainers">
<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" /></a>
<a class="reference external image-reference" href="https://odoo-community.org">
<img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" />
</a>
<p>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.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/crm/tree/12.0/crm_team_parent">OCA/crm</a> project on GitHub.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/crm/tree/18.0/crm_team_parent">OCA/crm</a> project on GitHub.</p>
<p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p>
</div>
</div>
Expand Down
7 changes: 3 additions & 4 deletions crm_team_parent/tests/test_crm_team_parent.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
# Copyright 2018 ACSONE SA/NV
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo.exceptions import UserError
from odoo.tests.common import TransactionCase

from ..models.crm_team import ParentLoopError


class TestCrmTeamParent(TransactionCase):
def setUp(self):
super(TestCrmTeamParent, self).setUp()
super().setUp()
self.parent = self.env["crm.team"].create({"name": "Team A"})
self.child = self.env["crm.team"].create(
{"name": "Team B", "parent_id": self.parent.id}
Expand All @@ -22,5 +21,5 @@ def test_add_child(self):
self.assertTrue(grandchild in self.child.child_ids)

def test_hierarchy_loop(self):
with self.assertRaises(ParentLoopError):
with self.assertRaises(UserError):
self.parent.write({"parent_id": self.child.id})
23 changes: 9 additions & 14 deletions crm_team_parent/views/crm_team.xml
Original file line number Diff line number Diff line change
@@ -1,40 +1,35 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8" ?>
<!-- Copyright 2018 ACSONE SA/NV
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -->

<odoo>

<record model="ir.ui.view" id="crm_team_tree_view">
<field name="name">crm.team.tree (in crm_team_parent)</field>
<field name="model">crm.team</field>
<field name="inherit_id" ref="sales_team.crm_team_view_tree"/>
<field name="inherit_id" ref="sales_team.crm_team_view_tree" />
<field name="arch" type="xml">
<xpath expr="//field[@name='user_id']" position="after">
<field name="parent_id"/>
<field name="parent_id" />
</xpath>
</field>
</record>

<record model="ir.ui.view" id="crm_team_form_view">
<field name="name">crm.team.form (in crm_team_parent)</field>
<field name="model">crm.team</field>
<field name="inherit_id" ref="sales_team.crm_team_view_form"/>
<field name="inherit_id" ref="sales_team.crm_team_view_form" />
<field name="arch" type="xml">
<field name="user_id" position="after">
<field name="parent_id" domain="[('id', '!=', id)]"/>
<field name="id" invisible="1"/>
<field name="parent_id" domain="[('id', '!=', id)]" />
<field name="id" invisible="1" />
</field>
<xpath expr="//notebook/page[@name='dashboard']" position="after">
<xpath expr="//notebook" position="inside">
<page string="Children Teams" name="children">
<field name="child_ids">
<tree delete="false" create="false">
<field name="name"/>
<field name="user_id"/>
<field name="name" />
<field name="user_id" />
</tree>
</field>
</page>
</xpath>
</field>
</record>

</odoo>

0 comments on commit cd9952b

Please sign in to comment.