How to add rule in openerp7 - security

I have code that shows I have multiple stations each station have a different worker.. I use rule to show each station to it's worker only .. I have supervisor who must see all stations .. how can I do rule for the supervisor to see all stations
This is rule for worker
<record model="ir.rule" id="station_worker_rule">
<field name="name">station worker Rule</field>
<field name="model_id" ref="model_mrp_production_workcenter_line"/>
<field name="domain_force">[('user_id','=',user.id)]</field>
<field name="groups" eval="[(4, ref('group_worker'))]"/>
<field name="perm_read" eval="True"/>
<field name="perm_write" eval="True"/>
<field name="perm_unlink" eval="True"/>
<field name="perm_create" eval="True"/>
</record>

For the supervisor you have to change a domain and groups.
You have to put a domain
<field name="domain_force">[(1 ,'=', 1)] </field>
<field name="groups" eval="[(4, ref('group_supervisor'))]"/>

Related

issue to Add a custom list view in odoo

when i add my list view code in the my .xml file
this code:
<odoo>
<data>
<record id="test_list_view" model="ir.ui.view">
<field name="arch" type="xml">
<tree string="Tests">
<field name="name"/>
<field name="last_seen"/>
</tree>
</field>
</record>
</data>
</odoo>
to this file :(estate_list_views.xml)
i can not up great my module because of this error
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/home/hadi/Public/st/odoo/odoo/http.py", line 640, in _handle_exception
return super(JsonRequest, self)._handle_exception(exception)
File "/home/hadi/Public/st/odoo/odoo/http.py", line 316, in _handle_exception
raise exception.with_traceback(None) from new_cause
odoo.tools.convert.ParseError: while parsing /home/hadi/Public/st/odoo/oca/estate/views/estate_list_views.xml:3, near
<record id="test_list_view" model="ir.ui.view">
<field name="arch" type="xml">
<tree string="Tests">
<field name="name"/>
<field name="last_seen"/>
</tree>
</field>
</record>
i follow this tutorial but that not have any description please unless introduce to me a free video tutorial for odoo
I think you missed the model name
Try this:
<record id="test_list_view" model="ir.ui.view">
<field name="name">model.tree.view</field>
<field name="model">your.model.name</field>
<field name= "arch" type = "xml">
<tree string="Tests">
<field name="name"/>
<field name="last_seen"/>
</tree>
</field>
</record>
See this for reference.

Odoo hide some view type on specific model

I need the following view types on CRM hide calendar,pivot,graph,cohort,dashboard using a custom module
I tried with this without success
<record id="crm_action" model="ir.actions.act_window">
<field name="name">CRM views</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">crm.lead</field>
<field name="view_type">crm.lead.kanban</field>
<field name="view_mode">tree,form,calendar,graph</field>
</record>
thanks
UPDATE
Your module should depend on crm. Then, the code must be this:
<record model="ir.actions.act_window" id="crm.crm_lead_action_pipeline">
<field name="view_mode">kanban,tree,form</field>
</record>

How to set a filter as default filter in odoo

i'm using odoo 11 and i want to set a default filter which group by employee. i made a modification on the module but it doesn't shows the right result(i want to remove the administrator filter) .I don't know what's the problem .Any idea for help please ?
.
<record id="action_bt_overtime_management" model="ir.actions.act_window">
<field name="name">Overtime</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">bt.hr.overtime</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
<field name="context">{'search_default_employee_id':1}</field>
<field name="search_view_id" ref="bt_overtime_management_search"/>
<field name="help" type="html">
<p class="oe_view_nocontent_create">
Create Overtime Request
</p>
</field>
</record>
Try to give like this
<record id="action_bt_overtime_management" model="ir.actions.act_window">
<field name="name">Overtime</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">bt.hr.overtime</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
<field name="context">{'group_by':'employee_id'}</field>
<field name="search_view_id" ref="bt_overtime_management_search"/>
<field name="help" type="html">
<p class="oe_view_nocontent_create">
Create Overtime Request
</p>
</field>
</record>

How to make website menu item invisible in specific group?

I'm working on a private sale website. If the user is a manager, the menu2 will look, else user is a salesman, the menu3 will look. How can I do that?
What is the best solution?
Here is my code:
<record id="menu_shop_sales" model="website.menu">
<field name="name">menu2</field>
<field name="url">/shop_sales</field>
<field name="parent_id" ref="website.main_menu"/>
<field name="sequence" type="int">21</field>
</record>
<record id="menu_shop_dealer" model="website.menu">
<field name="name">menu3</field>
<field name="url">/shop_dealer</field>
<field name="parent_id" ref="website.main_menu"/>
<field name="sequence" type="int">22</field>
</record>
Add groups like this.
<field name="groups" eval="[(6, 0, [ref('base.group_user')])]"/>
Or write access rule in csv.
Add groups attribute.
groups="base.group_user"
example:
<record id="menu_shop_dealer" model="website.menu">
<field name="name">menu3</field>
<field name="url">/shop_dealer</field>
<field name="parent_id" ref="website.main_menu"/>
<field name="sequence" type="int">22</field>
<field name="groups">base.group_user</field>
</record>

How to give access rights to users with certain conditions?

If there are four records created by four users. The Manager can be able to see all the records of all users. But a user should not be able view another user's record.
user – Can create/view/edit only his/her own record.
This is my need.
Thank You in advance.
you need to create ir.rules. For example in your case it would be something like this:
For administrators:
<record id="manager_rule" model="ir.rule">
<field name="name">My first rule</field>
<field name="model_id" ref="model_your_model"/>
<field name="domain_force">[(1,'=',1)]</field>
<field name="groups" eval="[(4,ref('your_manager_group'))]"/>
</record>
For other users:
<record id="others_rule" model="ir.rule">
<field name="name">My second rule</field>
<field name="model_id" ref="model_your_model"/>
<field name="domain_force">[('user_id','=',user.id)]</field>
<field name="groups" eval="[(4,ref('base.group_user'))]"/>
</record>
For more information about access rules you could visit odoo_security, access_rules.
I hope this help you!
Your problem solved using domain like
Eg.
domain = [('user_id','=',user.id)]
i hope it helps you

Resources