How to make dropdown for groups instead of checkboxes in Odoo?

Viewed 2036

I have made some groups A,B,C,D through GUI in Odoo v10. These groups are shown as check-boxes on the user page.

I want that instead of these check-boxes a dropdown must be shown so that user can be assigned to only a single group i.e. a user can only be in one of the A,B,C,D groups.

How can i do this??

3 Answers

I've found something that will clear how drop-downs are made and how check boxes are made. This is through code not from GUI as i am still finding a solution for it.

So, drop-downs are made when each group in a category inherits some other group in same category in hierarchical manner.

So, when i wrote the following code, check-boxes were made.

<record id='group_category' model='ir.module.category'>
   <field name='name'>Category name</field>
</record>

<record id="group_a" model="res.groups">
    <field name="name">A</field>
    <field name="category_id" ref="group_category"/>
</record>

<record id="group_b" model="res.groups">
    <field name="name">B</field>
    <field name="category_id" ref="group_category"/>
</record>

<record id="group_c" model="res.groups">
    <field name="name">C</field>
    <field name="category_id" ref="group_category"/>
</record>

But when i wrote the following code in which one group inherits the other in a hierarchical way, drop-down was made

<record id='group_category' model='ir.module.category'>
   <field name='name'>Category name</field>
</record>

<record id="group_a" model="res.groups">
    <field name="name">A</field>
    <field name="category_id" ref="group_category"/>
</record>

<record id="group_b" model="res.groups">
    <field name="name">B</field>
    <field name="category_id" ref="group_category"/>
    <field name="implied_ids" eval="[(4, ref('module_name.group_a'))]"/>
</record>

<record id="group_c" model="res.groups">
    <field name="name">C</field>
    <field name="category_id" ref="group_category"/>
    <field name="implied_ids" eval="[(4, ref('module_name.group_b'))]"/>
</record>

so, this was the case when i did it. Still finding a way to do it through GUI.

First Create this below record through xml.

<record model="ir.module.category" id="abcd_category">
    <field name="name">ABCD</field>
</record>

Then Create your groups with category_id.

<record id="group_a" model="res.groups">
    <field name="name">A</field>
    <field name="category_id" ref="abcd_category"/>
</record>

<record id="group_b" model="res.groups">
    <field name="name">B</field>
    <field name="category_id" ref="abcd_category"/>
</record>
......
......

Thats it.

Updates :

Add category in manifest.py

....
....
'category':'ABCD',
....
....

and select it from view into the Application in group formview. enter image description here

You can override the view and specify a widget. You could try:

<field name="field_name" widget="selection"/>

or

<field name="field_name" widget="many2one"/>

I hope this help you!

Related