如何隐藏没有名称属性的odoo动作类型按钮?

how to hide odoo action type buttons that have no name attributes?

我正在尝试隐藏产品表单中的补货按钮并使其对特定组可见 这是按钮定义

<button string="Replenish" type="action"
                        name="%(action_product_replenish)d"
                        context="{'default_product_tmpl_id': id}"
                        groups="stock.group_stock_user"
                        attrs="{'invisible': [('type', '!=', 'product')]}"/>  

我使用 xbath 添加更改组属性如下

<xpath expr="//button[@name='%(action_product_replenish)d']" position="attributes">
                <attribute name="groups">stock.group_stock_manager</attribute>
</xpath>

但是我收到这个错误

引发 ValueError('External ID not found in the system: %s' % xmlid) 亲爱的,我该怎么做?

如果您想添加特定的 group,请在以下按钮上使用 attribute

<xpath expr="//button[@name='%(action_product_replenish)d']" position="attributes">
    <attribute name="groups">stock.group_stock_manager</attribute>
</xpath>

或者,如果您 replace 该按钮,那么您必须重新声明该按钮,直到您无法替换出现错误为止。 replace 的以下代码:

<xpath expr="//button[@name='%(action_product_replenish)d']" position="replace">
    <!-- This way you replace it's behavior  -->
    <button string="Replenish" type="action"
        name="%(action_product_replenish)d"
        context="{'default_product_tmpl_id': id}"
        groups="Your groups"
        attrs="{'invisible': [('type', '!=', 'product')]}"/>
</xpath>

我认为你几乎是正确的。尝试添加模块名称。例如在 expr 中,改用 //button[@name='%(<module_name>.action_product_replenish)d']

作为旁注,正如@Dipen Shah 所说,您可能希望使用 attributes 而不是 replace,因为后者将删除其他已经定义的属性。