如何按条件隐藏表单上的“编辑/创建"按钮? [英] How to hide edit/create button on form by conditions?

查看:119
本文介绍了如何按条件隐藏表单上的“编辑/创建"按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Odoo的新开发人员,当我的表单进入自定义状态时,我需要隐藏编辑按钮,由于安全问题,我需要此按钮.

I'm a new Odoo developer and I need to hide the edit button when my form is entering a custom state, I need this because of a security problem.

当我尝试为表单赋予属性时,此XML代码无法正常工作.

This code in XML does not work when I try to give an attribute to the form.

<record model="ir.ui.view" id="pesan_form_view">
    <field name="name">pesan_service_form</field>
    <field name="model">pesan.service</field>
    <field name="arch" type="xml">
    <form string="Booking Service" attrs="{edit:'false':[('state','in','baru')]}">
    <!-- structure of form -->
</record>

我不知道为什么它不起作用.

I don't know why it doesn't work.

推荐答案

qWeb条件不适用于FormView.

qWeb conditions doesn't work for FormView.

您可以在此处进行检查( path_to_odoo/addons/web/static/src/js/framework/view.js ):

You can check it here(path_to_odoo/addons/web/static/src/js/framework/view.js):

 /**
  * Return whether the user can perform the action ('create', 'edit', 'delete') in this view.
  * An action is disabled by setting the corresponding attribute in the view's main element,
  * like: <form string="" create="false" edit="false" delete="false">
  */
  is_action_enabled: function(action) {
      var attrs = this.fields_view.arch.attrs;
      return (action in attrs) ? JSON.parse(attrs[action]) : true;
  },

此方法从 path_to_odoo/addons/web/static/src/xml/base.xml 中的模板FormView.buttons调用:

This method calls from template FormView.buttons in path_to_odoo/addons/web/static/src/xml/base.xml:

<button t-if="widget.is_action_enabled('edit')"
    type="button"
    class="oe_form_button_edit btn btn-default btn-sm" accesskey="E">
    Edit
</button>

这些问题在Odoo中借助规则(Odoo的ir.rule对象)解决了

These problems are solved in Odoo with the help of rules(ir.rule object of Odoo)

您可以在GUI中找到和编辑规则:设置(顶部菜单)->安全性(左侧菜单)->访问规则(左侧菜单).为此,请在调试模式下使用 admin用户.

You can find and edit rules in GUI here: Settings(top menu) -> Security(left menu) -> Access Rules(left menu). Use admin user in debug mode for this.

同时,您可以向模块的data.xml添加一些规则以进行导入.它们将在您安装或更新模块时添加.

At the same you can add some rules to data.xml of your module for import. They will be added when you install or update module.

小心! 记录规则不适用于管理员用户.

同时,您可以尝试扩展小部件FormView.

At the same you can try to expand widget FormView.

希望这对您有所帮助.

这篇关于如何按条件隐藏表单上的“编辑/创建"按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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