Skip to content

Commit

Permalink
[FIX] partner_industry_secondary: Add an option to display Child Indu…
Browse files Browse the repository at this point in the history
…stries first on it's name
  • Loading branch information
Shide committed Jan 13, 2025
1 parent ab50512 commit abc6a21
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 6 deletions.
1 change: 1 addition & 0 deletions partner_industry_secondary/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ Contributors
* Jordi Ballester Alomar <[email protected]>
* Miquel Raïch <[email protected]>
* Cristina Martin R.
* Eduardo de Miguel `Moduon <https://www.moduon.team/>`_

Maintainers
~~~~~~~~~~~
Expand Down
7 changes: 7 additions & 0 deletions partner_industry_secondary/models/res_config_settings.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Copyright 2018 Eficent Business and IT Consulting Services, S.L.
# Copyright 2025 Moduon - Eduardo de Miguel
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).

from odoo import fields, models
Expand All @@ -12,3 +13,9 @@ class ResConfigSettings(models.TransientModel):
help="Set if you want to be able to use industries for individuals also.",
implied_group="partner_industry_secondary.group_use_partner_industry_for_person",
)
display_last_child_first = fields.Boolean(
string="Display Child Industries first",
help="Set if you want to show the last child industries first "
"when searching for industries.\nChild (Dad < Grampa < Ancestor)",
config_parameter="partner_industry_secondary.display_last_child_first",
)
19 changes: 17 additions & 2 deletions partner_industry_secondary/models/res_partner_industry.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# Copyright 2016 Tecnativa S.L. - Pedro M. Baeza
# Copyright 2018 Eficent Business and IT Consulting Services, S.L.
# Copyright 2019 Tecnativa - Cristina Martin R.
# Copyright 2025 Moduon - Eduardo de Miguel
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).

from odoo import _, api, exceptions, fields, models
Expand All @@ -28,11 +29,25 @@ def get_names(cat):
"""Return the list [cat.name, cat.parent_id.name, ...]"""
res = []
while cat:
res.insert(0, cat.name)
res.append(cat.name)
cat = cat.parent_id
return res

return [(cat.id, " / ".join(get_names(cat))) for cat in self]
if (
self.env["ir.config_parameter"]
.sudo()
.get_param("partner_industry_secondary.display_last_child_first")
):
# Display last child first
result = []

Check warning on line 42 in partner_industry_secondary/models/res_partner_industry.py

View check run for this annotation

Codecov / codecov/patch

partner_industry_secondary/models/res_partner_industry.py#L42

Added line #L42 was not covered by tests
for cat in self:
cat_name, *parent_cats = get_names(cat)

Check warning on line 44 in partner_industry_secondary/models/res_partner_industry.py

View check run for this annotation

Codecov / codecov/patch

partner_industry_secondary/models/res_partner_industry.py#L44

Added line #L44 was not covered by tests
if parent_cats:
cat_name = f"{cat_name} ({' < '.join(parent_cats)})"
result.append((cat.id, cat_name))
return result

Check warning on line 48 in partner_industry_secondary/models/res_partner_industry.py

View check run for this annotation

Codecov / codecov/patch

partner_industry_secondary/models/res_partner_industry.py#L46-L48

Added lines #L46 - L48 were not covered by tests
# Default display (Ancestor / Grandpa / Dad / Child)
return [(cat.id, " / ".join(get_names(cat)[::-1])) for cat in self]

@api.constrains("name", "parent_id")
def _check_uniq_name(self):
Expand Down
1 change: 1 addition & 0 deletions partner_industry_secondary/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@
* Jordi Ballester Alomar <[email protected]>
* Miquel Raïch <[email protected]>
* Cristina Martin R.
* Eduardo de Miguel `Moduon <https://www.moduon.team/>`_
12 changes: 8 additions & 4 deletions partner_industry_secondary/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@

/*
:Author: David Goodger ([email protected])
: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 @@ -274,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 @@ -300,7 +301,7 @@
span.pre {
white-space: pre }

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

span.section-subtitle {
Expand Down Expand Up @@ -431,12 +432,15 @@ <h2><a class="toc-backref" href="#toc-entry-6">Contributors</a></h2>
<li>Jordi Ballester Alomar &lt;<a class="reference external" href="mailto:jordi.ballester&#64;eficent.com">jordi.ballester&#64;eficent.com</a>&gt;</li>
<li>Miquel Raïch &lt;<a class="reference external" href="mailto:miquel.raich&#64;eficent.com">miquel.raich&#64;eficent.com</a>&gt;</li>
<li>Cristina Martin R.</li>
<li>Eduardo de Miguel <a class="reference external" href="https://www.moduon.team/">Moduon</a></li>
</ul>
</div>
<div class="section" id="maintainers">
<h2><a class="toc-backref" href="#toc-entry-7">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>
Expand Down
16 changes: 16 additions & 0 deletions partner_industry_secondary/views/res_config_settings.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<!-- Copyright 2018 Eficent Business and IT Consulting Services, S.L.
Copyright 2025 Moduon - Eduardo de Miguel
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). -->
<odoo>
<record id="res_config_settings_view_form" model="ir.ui.view">
Expand Down Expand Up @@ -41,6 +42,21 @@
</div>
</div>
</div>
<div class="o_setting_left_pane">
<field name="display_last_child_first" />
</div>
<div
class="o_setting_right_pane"
id="partner_industry_secondary_show_form_child_settings"
>
<label
string="Display Child Industries first"
for="display_last_child_first"
/>
<div class="text-muted">
Display like: Child (Dad &lt; Grampa &lt; Ancestor)
</div>
</div>
</div>
</div>
</div>
Expand Down

0 comments on commit abc6a21

Please sign in to comment.