This question has been flagged
3 Replies
15131 Views

In product.product_category_form_view


<?xml version="1.0"?>
<form class="oe_form_configuration">
    <sheet>
        <div class="oe_button_box" name="button_box">
            <button class="oe_stat_button" name="164" icon="fa-th-list" type="action" context="{'search_default_categ_id': active_id}">
                <div class="o_form_field o_stat_info">
                    <span class="o_stat_value"><field name="product_count"/></span>
                    <span class="o_stat_text"> Products</span>
                </div>
            </button>
        </div>
        <div class="oe_title">
            <label for="name" string="Category name" class="oe_edit_only"/>
            <h1><field name="name" placeholder="e.g. Lamps"/></h1>
        </div>
        <group name="first" col="4" string="Category Type">
            <field name="parent_id"/>
            <field name="type"/>
        </group>
    </sheet>
</form>



I would like to add another section:

"Category Test", a new section/title with same font and style as "Category Type", "Inventory Valuation", "Account Properties", etc. titles.

Under that section there will be a dummy checkbox (test checkbox) just to understand how to properly place new fields/sections.

I have created and installed the new module, now I have to understand which would be the right way to add this new section with the checkbox field.

Under views folder of the module I create the new .xml file:


<?xml version="1.0" encoding="UTF-8"?>
<odoo>
    <data>
        <!-- Add test field to existing view -->
        <record model="ir.ui.view" id="category_test_form_view">
            <field name="name">category.test</field>
            <field name="model">product.category</field>
            <field name="inherit_id" ref="product.product_category_form_view"/>
            <field name="arch" type="xml">
                <WHAT SHOULD I PUT HERE?>
            </field>
        </record>
    </data>
</odoo>


How would you specify to add both title and Test checkbox AFTER the Category Type section?

Odoo 10.

Avatar
Discard

What are the name(s) of the new fields you have created to go on the Category Test section?

ditto

Author

It was just test field. I was in doubt about the whole xpath and group syntax. Thanks for hte comments anyway.

Author Best Answer

I finally find it with some time. I was also having issues because I did not include "product" as module dependency in __manifest__.py.


The right xml is:

<?xml version="1.0" encoding="UTF-8"?>
<odoo>
    <data>
        <!-- Add test field to existing view -->
        <record model="ir.ui.view" id="category_test_form_view">
            <field name="name">Category Test</field>
            <field name="model">product.category</field>
            <field name="inherit_id" ref="product.product_category_form_view"/>
            <field name="arch" type="xml">
                <xpath expr="//group[@name='first']" position="after">
                        <group name="first" string="Category Test">
                                <field name="test"/>
                                <field name="image_medium" widget="image" class="oe_avatar" modifiers="{}"/>
                        </group>
                </xpath>
            </field>
        </record>
    </data>
</odoo>
Avatar
Discard