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

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

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.

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

How to use selection field (dropdown) instead of checkboxes in Odoo groups (roles) selection?

I am creating a custom module in Odoo for a faculty and y need to create 3 roles (groups): students, professors and admins. An user cannot have 2 roles at the same time, so it could only be either a teacher, a professor or an admin. I have defined the permisions in the following code. But for selecting those permissions, Odoo creates a view with checkboxes, where you can chose 2 or more roles at the same time, instead of a selection field (dropdown), I dont want that. How can I force Odoo to create a dropdown for the selection of those roles
]
<record model="ir.module.category" id="module_category_faculty">
<field name="name">Faculty</field>
<field name="description">Faculty Roles</field>
<field name="sequence">45</field>
</record>
<record id="group_faculty_student" model="res.groups">
<field name="name">Student</field>
<field name="category_id" ref="module_category_faculty"/>
</record>
<record id="group_faculty_professor" model="res.groups">
<field name="name">Professor</field>
<field name="category_id" ref="module_category_faculty"/>
</record>
<record id="group_faculty_admin" model="res.groups">
<field name="name">Admin</field>
<field name="category_id" ref="module_category_faculty"/>
</record>
<record id="group_faculty_student" model="res.groups">
<field name="name">Student</field>
<field name="category_id" ref="module_category_faculty"/>
<field name="implied_ids" eval="[(4, ref('base.group_user'))]"/>
</record>
<record id="group_faculty_professor" model="res.groups">
<field name="name">Professor</field>
<field name="category_id" ref="module_category_faculty"/>
<field name="implied_ids" eval="[(4, ref('group_faculty_student'))]"/>
</record>
<record id="group_faculty_admin" model="res.groups">
<field name="name">Administrator</field>
<field name="category_id" ref="module_category_faculty"/>
<field name="implied_ids" eval="[(4, ref('group_faculty_professor'))]"/>
<field name="users" eval="[(4, ref('base.user_root')), (4, ref('base.user_admin'))]"/>
</record>
But in that case all Professors also have Stundent group.

How to change autofill groups name in res.users odoo

I made new security in the custom module, like this
<record model="ir.module.category" id="module_create">
<field name="name">Module Role</field>
<field name="description">User access level for this module</field>
<field name="sequence">5</field>
</record>
<record id="group_merc" model="res.groups">
<field name="name">Merc Access</field>
<field name="category_id" ref="mymodule.module_create"/>
<field name="implied_ids" eval="[(4, ref('base.group_user'))]"/>
</record>
and i make another form views using class res.users like this
<page name="access_rights" string="Access Rights">
<field name="groups_id" widget="many2many_tags" options='{"no_create": True, "no_open": True}'/>
</page>
the field displays like this
can i remove the fields views and change of the form in groups_id by displaying the group names that I have created automatically without having to do a search first?
You can use many2many_checkboxes which will list all the groups and you can select without any searching required.
<field name="groups_id" widget="many2many_checkboxes" />

hide button Edit , Create on odoo xml

I want to hide the edit and create button on the form view for a specific user I use this code but the button not showing at all
i just want to hide buttons just for only group
<record model="ir.ui.view" id="edit_button_message_">
<field name="name">edit.button.message.1</field>
<field name="model">person.message</field>
<field name="inherit_id" ref="view_parent_message_form"/>
<field name="groups_id" eval="[(6,0,[ref('person_access')])]"/>
<field name="arch" type="xml">
<xpath expr="/form[#string='form_view_string']" position="attributes">
<attribute name="create">false</attribute>
<attribute name="edit">false</attribute>
</xpath>
</field>
</record>
and i use this
<form string="form_view_string" edit="false" create="false" >
nothing happened , I use odoo v8
You better create a security access for that group to allow just read to that model, preventing the create, write and unlink actions and those buttons should disappear.
You could create it in xml as it will be only one, like:
<record id="person_message_access" model="ir.model.access">
<field name="name">edit.button.message.access</field>
<field name="model_id" ref="person.message"/>
<field name="group_id" ref="person_access"/>
<field name="perm_read" eval="1"/>
<field name="perm_create" eval="0"/>
<field name="perm_write" eval="0"/>
<field name="perm_unlink" eval="0"/>
</record>
or you could set it into a field ir.model.access.csv with content like:
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
person_message_access,edit.button.message.access,model_person_message,person_access,1,0,0,0

OpenERP specify multiple view references on "view_id"

I extended "hr.employee" class. (Inherited and gave the same name to the new one).
I defined two views (tree and form) and a menu:
<record model="ir.ui.view" id="my_employee_tree">
<field name="name">hr.employee.tree</field>
<field name="model">hr.employee</field>
<field name="arch" type="xml">
...
</field>
</record>
<record id="view_my_hr_employee_form" model="ir.ui.view">
<field name="name">hr.employee.form</field>
<field name="model">hr.employee</field>
<field name="arch" type="xml">
...
</field>
</record>
<record model="ir.actions.act_window" id="action_my_hr_employee_seq">
<field name="name">Angajati</field>
<field name="res_model">hr.employee</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
<field name="view_id" ref="view_my_hr_employee_form"/>
</record>
<menuitem id="menu_project_hr_base" parent="menu_project_utcn_project_base_main" name="HR"/>
<menuitem action="action_my_hr_employee_seq" id="menu_action_employee_form" name ="Angajati" parent="menu_project_hr_base"/>
What I want to do is to get the original views from hr.employee view when i use the original module, and to get my defined views when i use my module.
As you can see, I have specified "view_id" reference to my form view, but how can i define a reference also to my tree view? And I want the tree view to be shown first, and form view as alternative. How can i specify this?
<field name="view_mode">tree,form</field>
seems not to work if i add reference to form view
You have to map your action with particular tree,form view.
Try this:
<record model="ir.actions.act_window" id="action_my_hr_employee_seq">
<field name="name">Angajati</field>
<field name="res_model">hr.employee</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
</record>
<record model="ir.actions.act_window.view" id="act_hr_employee_tree_view">
<field eval="1" name="sequence"/>
<field name="view_mode">tree</field>
<field name="view_id" ref="your_tree_view_id"/>
<field name="act_window_id" ref="action_my_hr_employee_seq"/>
</record>
<record model="ir.actions.act_window.view" id="act_hr_employee_form_view">
<field eval="2" name="sequence"/>
<field name="view_mode">form</field>
<field name="view_id" ref="your_form_view_id"/>
<field name="act_window_id" ref="action_my_hr_employee_seq"/>
</record>

Record Rule for user groups in openerp

I have created a new module in openerp which contain consumption details related to each project.
I have created two user groups for my module (user,manager).User can create consumption details of project and he can see only consumption details which he has created.
I give the permission like this
<record id="property_rule_mat_mgmt_user" model="ir.rule">
<field name="name">Material Manage Rule</field>
<field model="ir.model" name="model_id" ref="model_mat_mgmt"/>
<field name="domain_force">[('create_uid','=',user.id)]</field>
</record>
It is working fine
Similarly if I assign a user as manager of my module he can see all consumption details of projects,in which he is member or manager.How to write the rule, I tried different ways but can't find a proper rule.
This is one of the rule I have tried
<record id="property_rule_mat_mgmt_manager" model="ir.rule">
<field name="name">Material Manage manager Rule</field>
<field model="ir.model" name="model_id" ref="project.model_project_project"/>
<field name="domain_force">['|',('user_id','=',False),('user_id','=',user.id)]</field>
</record>
For the record, it would have been be easier to answer if you could give the details of your model, specifically the mat.mgmt one. Perhaps that's why there was no answer yet.
Let's say you have a many2one relationship between mat.mgmt and project.project named project_id, you could then use something like this:
<record id="property_rule_mat_mgmt_manager" model="ir.rule">
<field name="name">Material Manage manager Rule</field>
<field model="ir.model" name="model_id" ref="model_mat_mgmt"/>
<field name="domain_force">['|',('project_id.user_id','=',False),('project_id.user_id','=',user.id)]</field>
</record>
Notice that the model is still model_mat_mgmt as this is the model on which the filtering is applied. You didn't want to filter projects but mat.mgmt if I understand correctly your question.
<record id="user_record_rule_id" model="ir.rule">
<field name="name">Record Rule Name</field>
<field model="ir.model" name="model_id" ref="model_my_model_name"/>
<field name="domain_force">[('create_uid', '=', user.id)]</field>
<field name="perm_read" eval="True"/>
<field name="perm_write" eval="True"/>
<field name="perm_create" eval="True"/>
<field name="perm_unlink" eval="True"/>
<field name="groups" eval="[(4,ref('group_user'))]"/>
</record>
<record id="manager_record_rule_id" model="ir.rule">
<field name="name">Record Rule Name</field>
<field model="ir.model" name="model_id" ref="model_my_model_name"/>
<field name="domain_force">[]</field>
<field name="perm_read" eval="True"/>
<field name="perm_write" eval="True"/>
<field name="perm_create" eval="True"/>
<field name="perm_unlink" eval="True"/>
<field name="groups" eval="[(4,ref('group_manager'))]"/>
</record>
Try above code:
manager group should be inherited from user group
example:
<record id="group_user" model="res.groups">
<field name="name">User</field>
<field name="category_id" ref="module_category_name"/>
</record>
<record id="group_manager" model="res.groups">
<field name="name">Manager</field>
<field name="implied_ids" eval="[(4, ref('group_user'))]"/>
<field name="category_id" ref="module_exit_category"/>
<field name="users" eval="[(4, ref('base.user_root'))]"/>
</record>
Explanation:
User can create the record(s) as well as can view his record(s) only
but manager can see all the user's record(s) as well as he can create & view his own record(s)