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

2024-10-02 18:24:59 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图在产品表单中隐藏“补充”按钮,并使其对特定组可见 这是按钮的定义

<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>

但是我得到了这个错误

raisevalueerror('在系统中找不到外部ID:%s'%xmlid) 亲爱的,我该怎么做


Tags: nameid表单产品typestockgroupattribute
2条回答

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

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

如果要添加特定的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>

相关问题 更多 >