Odoo: How to add custom category name to app module's search panel?

Viewed 48

For example i have app with

category = "custom_category"

How can i add this category to my search panel in app module ?

enter image description here

When I created a category, I thought it would come here automatically, but it didn't.

I found the file, where these categories are defined: 15.0/odoo/odoo/addons/base/data/ir_module_category_data.xml

But something is not right here! When I delete a record from here, for example:

<!--        <record model="ir.module.category" id="module_category_human_resources">-->
<!--            <field name="name">Human Resources</field>-->
<!--            <field name="sequence">45</field>-->
<!--        </record>-->

And update the base module, this (Human Resources) field is still in this menu !?

Why it is not deleted? Any advice?

2 Answers

Odoo will only show categories that do not have a parent and that one of the subcategories is linked to a module.

If the category_id field is defined in the search panel, Odoo will use a custom domain:

domain = [('parent_id', '=', False), ('child_ids.module_ids', '!=', False)]  

To show the custom category in the search panel:

First, define the module category as follows:

<record model="ir.module.category" id="module_custom_category">
    <field name="name">custom_category</field>
    <field name="sequence">99</field>
</record>

<record model="ir.module.category" id="module_child_category">
    <field name="name">child_category</field>
    <field name="parent_id" ref="module_custom_category"/>
</record>

Then set it in a module __manifest__.py file:

'category': 'custom_category/child_category',

Why Odoo did not remove the category after commenting the XML definition?

Odoo will create two categories with the same name (custom_category) with the following XML IDS:

base.module_category_custom_category
stack15.module_custom_category

And use the first one to show it in the search panel.

When you comment record XML definition and upgrade the module, Odoo will remove the category using the module name as a prefix in its XML id (stack15.module_custom_category) and keep the base category (base.module_category_custom_category), so the custom category will be visible even if you uninstall the module.

Related