3

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??

Sankalp Kataria
  • 479
  • 7
  • 24

3 Answers3

5

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.

Sankalp Kataria
  • 479
  • 7
  • 24
3

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

Chavada Viki
  • 1,514
  • 1
  • 12
  • 22
  • I know that this will create drop-down but I've not created groups from code, I've created them through GUI and they are shown as check-boxes. I've made large amount of rules and access rights for those groups and i don't want to start over. Please suggest a way i which i can show my existing groups in drop-down. – Sankalp Kataria Oct 04 '17 at 13:56
  • i updated my answer. and if you want to add your groups in existing dropdown then you can select that application in group. – Chavada Viki Oct 04 '17 at 17:07
  • So, when i have to show that drop-down on user page, i can write it like this--> (gid is id of group) ??? – Sankalp Kataria Oct 05 '17 at 05:44
  • 1
    No it will automatically appears on the users page. no need to do any thing. – Chavada Viki Oct 05 '17 at 09:29
  • NO, not working. i've added it to an Application "Administration" but when i open user page it says sel_groups_3_5 does not exist. – Sankalp Kataria Oct 05 '17 at 12:19
  • Okay then try to create new application from that dropdown. and set it in it. – Chavada Viki Oct 06 '17 at 04:11
  • Tried it. Not working. I think i have to start over again. – Sankalp Kataria Oct 06 '17 at 05:54
0

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!

Dayana
  • 1,500
  • 1
  • 16
  • 29