如何在模型 ir.actions.server odoo 12 中给用户组(XML)? [英] How to give user groups(XML) in the model ir.actions.server odoo 12?

查看:168
本文介绍了如何在模型 ir.actions.server odoo 12 中给用户组(XML)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用这个xml代码在'Action'里面添加了一个按钮,但是我需要将按钮限制在一些用户组中,

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>

推荐答案

ir.actions.actions get_bindings 方法将尝试检索绑定到给定模型的动作列表并丢弃未经授权的动作,然后读取动作定义.

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.

该方法将使用 groups_id 字段来检查用户是否可以不执行操作.

The method will use groups_id field to check if the user may not perform an action.

groups_id
允许查看/使用当前报告的组的 Many2many 字段

groups_id
Many2many field to the groups allowed to view/use the current report

所以一个 groups_id 字段添加到 ir.actions.report 以允许 查看/使用当前报告

So a groups_id field is added to ir.actions.report to allow groups to view/use the current report

遗憾的是,ir.actions.server

幸运的是,get_bindings 方法是在 ir.actions.actions 模型中实现的,该模型是两个模型 ir.actions.reportir.actions.server,因此要在服务器操作中使用相同的逻辑,只需在 ir.action.server 中添加一个 groups_id 字段并在 XML 定义中使用它来限制对某些组的访问.

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.

使用 groups_id 字段进行服务器操作:

Use the groups_id field for server action:

  • 继承服务器操作模型并添加groups_id字段:

class IrActionsServer(models.Model):
    _inherit = 'ir.actions.server'

    groups_id = fields.Many2many('res.groups', 'res_groups_server_rel', 'uid', 'gid', string='Groups')

  • 然后从 XML 设置 groups_id 字段值,以下示例将使用 特殊命令格式,将Administration/Access Rights 组添加到groups_id 字段:>

  • 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'))]"/>
    

  • 这篇关于如何在模型 ir.actions.server odoo 12 中给用户组(XML)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆