gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 03:18:23 25 4
gpt4 key购买 nike

我是一名新的 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>

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

最佳答案

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 中查找和编辑规则:设置(顶部菜单)-> 安全(左侧菜单)-> 访问规则(左侧菜单)。为此,请使用处于 Debug模式的管理员用户

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

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

同时你可以尝试展开小部件FormView

希望对你有帮助。

关于openerp - 如何按条件隐藏表单上的编辑/创建按钮?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35196277/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com