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 8219032
Show file tree
Hide file tree
Showing 9 changed files with 128 additions and 69 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
90 changes: 32 additions & 58 deletions partner_industry_secondary/i18n/es.po
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * partner_sector
# * partner_industry_secondary
#
# Translators:
# OCA Transbot <[email protected]>, 2017
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 10.0\n"
"Project-Id-Version: Odoo Server 16.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2017-12-26 15:33+0000\n"
"PO-Revision-Date: 2023-10-12 13:38+0000\n"
"Last-Translator: Ivorra78 <[email protected]>\n"
"Language-Team: Spanish (https://www.transifex.com/oca/teams/23907/es/)\n"
"POT-Creation-Date: 2025-01-13 12:12+0000\n"
"PO-Revision-Date: 2025-01-13 13:13+0100\n"
"Last-Translator: \n"
"Language-Team: \n"
"Language: es\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: nplurals=2; plural=n != 1;\n"
"X-Generator: Weblate 4.17\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
"X-Generator: Poedit 3.4.4\n"

#. module: partner_industry_secondary
#: model:ir.model.fields,field_description:partner_industry_secondary.field_res_partner_industry__child_ids
Expand All @@ -27,13 +25,24 @@ msgstr "Hijos"
#. module: partner_industry_secondary
#: model:ir.model,name:partner_industry_secondary.model_res_config_settings
msgid "Config Settings"
msgstr "Configura los ajustes"
msgstr "Ajustes de configuración"

#. module: partner_industry_secondary
#: model:ir.model,name:partner_industry_secondary.model_res_partner
msgid "Contact"
msgstr "Contacto"

#. module: partner_industry_secondary
#: model:ir.model.fields,field_description:partner_industry_secondary.field_res_config_settings__display_last_child_first
#: model_terms:ir.ui.view,arch_db:partner_industry_secondary.res_config_settings_view_form
msgid "Display Child Industries first"
msgstr "Mostrar Industrias Hijas primero"

#. module: partner_industry_secondary
#: model_terms:ir.ui.view,arch_db:partner_industry_secondary.res_config_settings_view_form
msgid "Display like: Child (Dad &lt; Grampa &lt; Ancestor)"
msgstr "Display like Child (Dad &lt; Grampa &lt; Ancestor)"

#. module: partner_industry_secondary
#: model_terms:ir.ui.view,arch_db:partner_industry_secondary.res_config_settings_view_form
msgid "Enable industries for individuals"
Expand Down Expand Up @@ -61,7 +70,7 @@ msgstr "Sector"
#: model:ir.model.fields,field_description:partner_industry_secondary.field_res_partner__industry_id
#: model:ir.model.fields,field_description:partner_industry_secondary.field_res_users__industry_id
msgid "Main Industry"
msgstr "Sector principal"
msgstr "Sector"

#. module: partner_industry_secondary
#: model:ir.model.fields,field_description:partner_industry_secondary.field_res_partner_industry__name
Expand Down Expand Up @@ -94,6 +103,15 @@ msgstr "Sector"
msgid "Set if you want to be able to use industries for individuals also."
msgstr "Establezca si desea poder usar sectores para individuos también."

#. module: partner_industry_secondary
#: model:ir.model.fields,help:partner_industry_secondary.field_res_config_settings__display_last_child_first
msgid ""
"Set if you want to show the last child industries first when searching for industries.\n"
"Child (Dad < Grampa < Ancestor)"
msgstr ""
"Márcalo si quieres mostrar la última industria hija primero cuando busques por industrias.\n"
"Hija (Padre < Abuelo < Ancestro)"

#. module: partner_industry_secondary
#: model:ir.model.fields,field_description:partner_industry_secondary.field_res_partner__show_partner_industry_for_person
#: model:ir.model.fields,field_description:partner_industry_secondary.field_res_users__show_partner_industry_for_person
Expand All @@ -105,54 +123,10 @@ msgstr "Mostrar socio Industria Para persona"
#: code:addons/partner_industry_secondary/models/res_partner.py:0
#, python-format
msgid "The main industry must be different from the secondary industries."
msgstr ""
"La industria principal debe ser diferente de las industrias secundarias."
msgstr "La industria principal debe ser diferente de las industrias secundarias."

#. module: partner_industry_secondary
#: model:ir.model.fields,field_description:partner_industry_secondary.field_res_config_settings__group_use_partner_industry_for_person
#: model:res.groups,name:partner_industry_secondary.group_use_partner_industry_for_person
msgid "Use industry for individuals"
msgstr "Use el sector para individuos"

#, python-format
#~ msgid "Error! You cannot create recursive industries."
#~ msgstr "Error!. No puede crear sectores recursivos."

#~ msgid "Industry for individual"
#~ msgstr "Sector para personas"

#~ msgid "Partner Industries"
#~ msgstr "Sectores de la empresa"

#~ msgid "Parent Right"
#~ msgstr "Padre derecha"

#~ msgid "Created by"
#~ msgstr "Creado por"

#~ msgid "Created on"
#~ msgstr "Creado en"

#~ msgid "Display Name"
#~ msgstr "Nombre mostrado"

#~ msgid "ID"
#~ msgstr "ID"

#~ msgid "Last Modified on"
#~ msgstr "Última modificación el"

#~ msgid "Last Updated by"
#~ msgstr "Última actualización por"

#~ msgid "Last Updated on"
#~ msgstr "Última actualización en"

#~ msgid "Main Sector"
#~ msgstr "Sector principal"

#~ msgid "Partner"
#~ msgstr "Empresa"

#~ msgid "Sectors"
#~ msgstr "Sectores"
20 changes: 20 additions & 0 deletions partner_industry_secondary/i18n/partner_industry_secondary.pot
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 16.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2025-01-13 12:12+0000\n"
"PO-Revision-Date: 2025-01-13 12:12+0000\n"
"Last-Translator: \n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
Expand All @@ -28,6 +30,17 @@ msgstr ""
msgid "Contact"
msgstr ""

#. module: partner_industry_secondary
#: model:ir.model.fields,field_description:partner_industry_secondary.field_res_config_settings__display_last_child_first
#: model_terms:ir.ui.view,arch_db:partner_industry_secondary.res_config_settings_view_form
msgid "Display Child Industries first"
msgstr ""

#. module: partner_industry_secondary
#: model_terms:ir.ui.view,arch_db:partner_industry_secondary.res_config_settings_view_form
msgid "Display like: Child (Dad &lt; Grampa &lt; Ancestor)"
msgstr ""

#. module: partner_industry_secondary
#: model_terms:ir.ui.view,arch_db:partner_industry_secondary.res_config_settings_view_form
msgid "Enable industries for individuals"
Expand Down Expand Up @@ -88,6 +101,13 @@ msgstr ""
msgid "Set if you want to be able to use industries for individuals also."
msgstr ""

#. module: partner_industry_secondary
#: model:ir.model.fields,help:partner_industry_secondary.field_res_config_settings__display_last_child_first
msgid ""
"Set if you want to show the last child industries first when searching for industries.\n"
"Child (Dad < Grampa < Ancestor)"
msgstr ""

#. module: partner_industry_secondary
#: model:ir.model.fields,field_description:partner_industry_secondary.field_res_partner__show_partner_industry_for_person
#: model:ir.model.fields,field_description:partner_industry_secondary.field_res_users__show_partner_industry_for_person
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 = []
for cat in self:
cat_name, *parent_cats = get_names(cat)
if parent_cats:
cat_name = f"{cat_name} ({' < '.join(parent_cats)})"
result.append((cat.id, cat_name))
return result
# 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
31 changes: 26 additions & 5 deletions partner_industry_secondary/tests/test_res_partner_industry.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Copyright 2015 Antiun Ingenieria S.L. - Javier Iniesta
# Copyright 2016 Tecnativa S.L. - Vicent Cubells
# Copyright 2016 Tecnativa S.L. - Pedro M. Baeza
# Copyright 2025 Moduon - Eduardo de Miguel
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).

from odoo.exceptions import UserError, ValidationError
Expand All @@ -13,10 +14,17 @@ def setUpClass(cls):
super(TestResPartnerIndustry, cls).setUpClass()
cls.industry_model = cls.env["res.partner.industry"]
cls.industry_main = cls.industry_model.create({"name": "Test"})
cls.industry_dad = cls.industry_model.create(
{"name": "Test dad", "parent_id": cls.industry_main.id}
)
cls.industry_child = cls.industry_model.create(
{"name": "Test child", "parent_id": cls.industry_main.id}
{"name": "Test child", "parent_id": cls.industry_dad.id}
)
cls.partner = cls.env["res.partner"].create({"name": "Test partner"})
# Ensure the parameter is not set
cls.env["ir.config_parameter"].search(
[("key", "=", "partner_industry_secondary.display_last_child_first")]
).unlink()

def test_00_check_industries(self):
with self.assertRaises(ValidationError):
Expand All @@ -41,12 +49,25 @@ def test_03_check_recursion(self):
self.industry_main.parent_id = self.industry_child.id

def test_04_name(self):
self.assertEqual(self.industry_child.display_name, "Test / Test child")
self.assertEqual(
self.industry_child.display_name, "Test / Test dad / Test child"
)

def test_05_check_partner_industries(self):
main = self.industry_main
both = self.industry_main | self.industry_child
all_industries = self.industry_main | self.industry_dad | self.industry_child
with self.assertRaises(ValidationError):
self.partner.write(
{"industry_id": main.id, "secondary_industry_ids": [(6, 0, both.ids)]}
{
"industry_id": self.industry_main.id,
"secondary_industry_ids": [(6, 0, all_industries.ids)],
}
)

def test_06_child_name_first(self):
self.env["ir.config_parameter"].set_param(
"partner_industry_secondary.display_last_child_first", "True"
)
self.assertEqual(
self.industry_child.display_name,
"Test child (Test dad < Test)",
)
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 8219032

Please sign in to comment.