Skip to content

Commit

Permalink
[MIG] partner_industry_secondary: Migration to 17.0
Browse files Browse the repository at this point in the history
[IMP] Fix pre-commit and unit tests

[IMP] partner_industry_secondary: black, isort, prettier

[IMP] partner_industry_secondary: Update unit tests

[IMP] partner_industry_secondary: black, isort, prettier
  • Loading branch information
mmrondon authored and Tisho99 committed May 21, 2024
1 parent fb5a274 commit ba99db2
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 56 deletions.
2 changes: 1 addition & 1 deletion partner_industry_secondary/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
{
"name": "Partner Industry Secondary",
"summary": "Add secondary partner industries",
"version": "16.0.1.0.1",
"version": "17.0.1.0.0",
"category": "Sales",
"website": "https://github.com/OCA/partner-contact",
"author": "Tecnativa, Odoo Community Association (OCA)",
Expand Down
17 changes: 7 additions & 10 deletions partner_industry_secondary/models/res_partner_industry.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,13 @@ class ResPartnerIndustry(models.Model):
)
parent_path = fields.Char(index=True, unaccent=False)

def name_get(self):
def get_names(cat):
"""Return the list [cat.name, cat.parent_id.name, ...]"""
res = []
while cat:
res.insert(0, cat.name)
cat = cat.parent_id
return res

return [(cat.id, " / ".join(get_names(cat))) for cat in self]
@api.depends("name", "parent_id")
def _compute_display_name(self):
for rec in self:
if rec.parent_id:
rec.display_name = rec.parent_id.display_name + " / " + rec.name
else:
rec.display_name = rec.name

@api.constrains("name", "parent_id")
def _check_uniq_name(self):
Expand Down
12 changes: 12 additions & 0 deletions partner_industry_secondary/tests/test_res_partner_industry.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ def setUpClass(cls):
cls.industry_child = cls.industry_model.create(
{"name": "Test child", "parent_id": cls.industry_main.id}
)
cls.env.user.groups_id = [
(
4,
cls.env.ref(
"partner_industry_secondary.group_use_partner_industry_for_person"
).id,
)
]
cls.partner = cls.env["res.partner"].create({"name": "Test partner"})

def test_00_check_industries(self):
Expand Down Expand Up @@ -50,3 +58,7 @@ def test_05_check_partner_industries(self):
self.partner.write(
{"industry_id": main.id, "secondary_industry_ids": [(6, 0, both.ids)]}
)

def test_06_check_show_partner_industry_for_person(self):
self.partner._compute_show_partner_industry_for_person()
self.assertEqual(self.partner.show_partner_industry_for_person, True)
38 changes: 5 additions & 33 deletions partner_industry_secondary/views/res_config_settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,39 +10,11 @@
<field name="inherit_id" ref="base.res_config_settings_view_form" />
<field name="arch" type="xml">
<div id="contacts_settings" position='inside'>
<div class="row mt16 o_settings_container">
<div class="col-lg-6 o_setting_box">
<div class="o_setting_left_pane">
<field name="group_use_partner_industry_for_person" />
</div>
<div
class="o_setting_right_pane"
id="partner_industry_secondary_show_form_settings"
>
<label
string="Enable industries for individuals"
for="group_use_partner_industry_for_person"
/>
<div class="text-muted">
Enable industries for individuals
</div>
<div class="content-group">
<div
class="mt16"
attrs="{'invisible': [('group_use_partner_industry_for_person', '=', False)]}"
>
<button
name="%(base.res_partner_industry_action)d"
icon="fa-arrow-right"
type="action"
string="Industries"
class="btn-link"
/>
</div>
</div>
</div>
</div>
</div>
<block>
<setting string="Enable industries for individuals" help="Enable industries for individuals">
<field name="group_use_partner_industry_for_person" />
</setting>
</block>
</div>
</field>
</record>
Expand Down
20 changes: 8 additions & 12 deletions partner_industry_secondary/views/res_partner_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,13 @@
<field
name="secondary_industry_ids"
widget="many2many_tags"
attrs="{'invisible': [('is_company', '=', False),
('show_partner_industry_for_person', '=', False)]}"
invisible="is_company == False and show_partner_industry_for_person == False"
/>
</field>
<field name="industry_id" position="attributes">
<attribute name="attrs">
{'invisible': [('is_company', '=', False), ('show_partner_industry_for_person', '=', False)]}
</attribute>
<attribute
name="invisible"
>is_company == False and show_partner_industry_for_person == False</attribute>
</field>
<xpath
expr="//field[@name='child_ids']/form//field[@name='title']"
Expand All @@ -32,14 +31,12 @@
name="industry_id"
placeholder="Sector"
options='{"no_open": True}'
attrs="{'invisible': [('is_company', '=', False),
('show_partner_industry_for_person', '=', False)]}"
invisible="is_company == False and show_partner_industry_for_person == False"
/>
<field
name="secondary_industry_ids"
widget="many2many_tags"
attrs="{'invisible': [('is_company', '=', False),
('show_partner_industry_for_person', '=', False)]}"
invisible="is_company == False and show_partner_industry_for_person == False"
/>
</xpath>
</field>
Expand All @@ -52,10 +49,9 @@
<field name="email" position="after">
<field
name="industry_id"
attrs="{'invisible': [('is_company', '=', False),
('show_partner_industry_for_person', '=', False)]}"
invisible="is_company == False and show_partner_industry_for_person == False"
/>
<field name="show_partner_industry_for_person" invisible="1" />
<field name="show_partner_industry_for_person" column_invisible="1" />
</field>
</field>
</record>
Expand Down

0 comments on commit ba99db2

Please sign in to comment.