如何按条件隐藏表单上的编辑/创建按钮?

问题描述 投票:3回答:2

我是一个新的Odoo开发人员,当我的表单进入自定义状态时我需要隐藏编辑按钮,因为安全问题我需要这个。

当我尝试为表单提供属性时,XML中的此代码不起作用。

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

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

openerp xml-rpc odoo-8
2个回答
1
投票

qWeb条件对FormView不起作用。

你可以在这里查看(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调用:

<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对象)

您可以在此处查找和编辑GUI中的规则:设置(顶层菜单) - >安全性(左侧菜单) - >访问规则(左侧菜单)。在调试模式下使用admin用户。

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

小心! Record rules do not apply to the Administrator user

在同一个你可以尝试扩展小部件FormView

希望这对你有所帮助。


0
投票

试试这个代码。

<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': [('state', 'in', ['baru'])]}">
    <!-- structure of form -->
</record>
© www.soinside.com 2019 - 2024. All rights reserved.