显示共享按钮到Odoo 12中的特定组

问题描述

如果用户具有特定的组,我正在尝试显示“共享按钮”,该按钮似乎是启动 ir.actions.act_window

的操作

我尝试使用XPath使用该名称来定位它,但由于按钮的性质,该名称似乎随环境而变化(在其他环境中,名称可能会像123或124这样变化)

该按钮将启动一个具有以下操作外部ID portal.portal_share_action

的窗口操作

我试图在XML文件中使用组属性引用操作ID,该XML文件是我构建的自定义项目模块的一部分,代码如下:

<record model="ir.actions.act_window" id="portal.portal_share_action">
    <field name="groups" eval="[(6,[ref('rw_project.group_project_rw_base_user')])]"/>
</record>

即使用户没有分配组,该按钮仍会显示

编辑:

该按钮位于项目窗体中,并且xml如下:

<header>
    <button name="132" string="Share" type="action" class="oe_highlight oe_read_only"/>
</header>

share button on project module

解决方法

因为你说过:

名称可以不同,例如123或124,以此类推

我想您尝试覆盖客户发票中的按钮,例如Add credit note

<button name="%(action_account_invoice_refund)d" type='action' string='Add Credit Note' groups="account.group_account_invoice" attrs="{'invisible': ['|',('type','=','out_refund'),('state','not in',('open','in_payment','paid'))]}"/>

这是一个action类型的按钮,要覆盖它,您可以使用其名称,但可以使用外部ID(添加模块名称)。

示例:

<record id="invoice_form" model="ir.ui.view">
    <field name="name">account.invoice.form</field>
    <field name="model">account.invoice</field>
    <field name="inherit_id" ref="account.invoice_form"/>
    <field name="arch" type="xml">
        <button name='%(account.action_account_invoice_refund)d' position="attributes">
            <attribute name="groups"></attribute>
        </button>
    </field>
</record>  

如果尝试设置允许查看/使用共享文档操作的组,则需要使用groups_id字段。他们使用购买模块中的groups_id字段来限制对购买用户的访问,如下所示:

<field name="groups_id" eval="[(4,ref('purchase.group_purchase_user'))]"/>

如果您尝试覆盖的共享按钮是一个下拉按钮,例如销售订单,采购订单或发票,它们都是服务器操作,则没有可用的选项来限制对组的访问,但是您可以添加{ groups_id模型中的{1}}字段,然后使用它的XML定义。

要实现这一点,您可以检查我以前的答案,How to give user groups(XML) in the model ir.actions.server Odoo 12?

编辑:在项目表单标题中覆盖共享按钮操作

ir.actions.server