微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何隐藏/删除表单中的操作菜单?

如何解决如何隐藏/删除表单中的操作菜单?

我找不到隐藏或删除表单之外的操作菜单方法

action menu

我试过了:

  • <delete> 标签
  • 替换它
  • 使用 ir.values

它们都不起作用。

这是标准 xml 文件中操作按钮的代码

<record id="action_product_template_price_list_report" model="ir.actions.server">
    <field name="name">Generate Pricelist</field>
    <field name="groups_id" eval="[(4,ref('product.group_product_pricelist'))]"/>
    <field name="model_id" ref="product.model_product_template"/>
    <field name="binding_model_id" ref="product.model_product_template"/>
    <field name="state">code</field>
    <field name="code">
ctx = env.context
ctx.update({'default_pricelist': env['product.pricelist'].search([],limit=1).id})
action = {
    'name': 'Pricelist Report','type': 'ir.actions.client','tag': 'generate_pricelist','context': ctx,}
    </field>
</record>

解决方法

有两种简单的可能性:

  1. 只需在服务器操作的技术设置下进行更改

服务器操作表单视图上有一个按钮,用于创建或取消链接操作的菜单操作。可以找到这两个按钮的代码here

def create_action(self):
    """ Create a contextual action for each server action. """
    for action in self:
        action.write({'binding_model_id': action.model_id.id,'binding_type': 'action'})
    return True

def unlink_action(self):
    """ Remove the contextual actions created for the server actions. """
    self.check_access_rights('write',raise_exception=True)
    self.filtered('binding_model_id').write({'binding_model_id': False})
    return True

我不确定这是否适用于模块更新,但如果有人可以测试它并将其作为评论写在此答案下,我将不胜感激。

如您所见,第二种可能性源自第一种。

  1. 从服务器操作中删除 binding_model_id
<record id="product.action_product_template_price_list_report" model="ir.actions.server">
    <field name="binding_model_id" eval="False" />
</record>
,

Hide print action

希望这对你有用。

,

我不知道这段代码的某些部分做了什么,但我找到了它并对其进行了编辑以解决我的问题。该操作现在已隐藏。

from odoo import api,models,tools

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

    @api.model
    @tools.ormcache('frozenset(self.env.user.groups_id.ids)','model_name')
    def get_bindings(self,model_name):
        result = super(IrActionsInherit,self).get_bindings(model_name)
        actions = result.get('action')
        for action in actions:
            if action.get('name') == 'Generate Pricelist':
                actions.remove(action)
                result.update({'action': actions})
        return result

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。