This question has been flagged
1 Reply
11999 Views

I need to create division field(many2one) and need to group them by their parent department wise. good example I got from hr_view.xml.they categorize by 'manager', 'coach', 'department', etc.. How to add this feature to my own many2one field.?

Please advice..

<record id="view_employee_filter" model="ir.ui.view">
    <field name="name">Employees</field>
    <field name="model">hr.employee</field>
    <field name="arch" type="xml">
        <search string="Employees">
            <field name="name" string="Employees"/>
            <field name="department_id" />
            <field name="category_ids" groups="base.group_hr_user"/>
            <group expand="0" string="Group By...">
                <filter string="Manager" icon="terp-personal" domain="[]" context="{'group_by':'parent_id'}"/>
                <filter string="Coach" icon="terp-personal" domain="[]" context="{'group_by':'coach_id'}"/>
                <filter string="Department" icon="terp-personal+" domain="[]" context="{'group_by':'department_id'}"/>
                <filter string="Job" icon="terp-gtk-select-all" domain="[]" context="{'group_by':'job_id'}"/>
                <filter string="Company" icon="terp-go-home" domain="[]" context="{'group_by':'company_id'}" groups="base.group_multi_company"/>
            </group>
        </search>
     </field>
 </record>
Avatar
Discard
Best Answer

Create many2one field: 'division_id': fields.many2one('model name', 'Division'),

Create search field with group_by: <record id="view_name_filter" model="ir.ui.view"> <field name="name">xxx</field> <field name="model">model name</field> <field name="arch" type="xml"> <search string="xxx"> <field name="name" string="xxx"/> <field name="department_id"/> <group expand="0" string="Group By..."> <filter string="Division" icon="terp-personal" domain="[]" context="{'group_by':'division_id'}"/> /group> </search> </field> </record>

Avatar
Discard

Where do you put this code? Is it in a View that inherits another view? Or in some other place? Does it need to inherit something or any other details?