I used this xml code to add a button inside the 'Action',But i need to restrict the button to some user groups,
<record id="specialist_no_show_action" model="ir.actions.server">
<field name="name">No Show </field>
<field name="type">ir.actions.server</field>
<field name="binding_model_id" ref="second_opinion.model_consultation"/>
<field name="model_id" ref="second_opinion.model_consultation"/>
<field name="state">code</field>
<field name="code">
action = model.update_no_show()
</field>
</record>
The ir.actions.actions
get_bindings method will try to retrieve the list of actions bound to the given model and discard unauthorized actions then read action definitions.
The method will use groups_id field to check if the user may not perform an action.
groups_id
Many2many field to the groups allowed to view/use the current report
So a groups_id field is added to ir.actions.report
to allow groups to view/use the current report
Unfortunately, the groups_id
field is not implemented in ir.actions.server
Fortunately, the get_bindings
method is implemented in the ir.actions.actions
model which is the base model for both models ir.actions.report
and ir.actions.server
, so to use the same logic in server actions just add a groups_id
field in ir.action.server
and use it from the XML definition to restrict access to some groups.
Use the groups_id
field for server action:
Inherit server action model and add the groups_id
field:
class IrActionsServer(models.Model):
_inherit = 'ir.actions.server'
groups_id = fields.Many2many('res.groups', 'res_groups_server_rel', 'uid', 'gid', string='Groups')
Then set the groups_id
field value from XML, the following example will use the special commands format to add the Administration/Access Rights
group to the groups_id
field:
<field name='groups_id' eval="[(4, ref('base.group_erp_manager'))]"/>