如果状态被“确认”,如何在表单中只读取所有字段?(How to make all fields readonly in a form when the state is 'confirmed

系统教程 行业动态 更新时间:2024-06-14 16:55:58
如果状态被“确认”,如何在表单中只读取所有字段?(How to make all fields readonly in a form when the state is 'confirmed'?)

当对象的状态变为“ confirmed ”时,我需要表单中的所有字段都是只读的。 到目前为止,我把attrs = "{'readonly': [('state', '=', 'confirmed')]}"放在每个字段中,但我想知道是否有任何方法可以使其更优化。

When the state of an object changes to 'confirmed', I need all fields in the form to be readonly. So far I put attrs = "{'readonly': [('state', '=', 'confirmed')]}" in each field, but I would like to know if there is any way to make it more optimal.

最满意答案

如果要将该条件应用于模型的每个视图(在Odoo的不同部分中显示有多个表单视图的模型),最好在Python中指定它。 在每个字段的定义中,您应该添加states参数:

your_field = fields.Whatever( ... readonly=False, states={ 'confirmed': [('readonly', True)], } )

这样,如果用户通过与您修改的视图不同的视图打开模型,如果状态得到确认,则字段将是只读的,您没有修改打开的视图也没关系。

另一方面,如果您只想在特定的表单视图中应用您的目的,您可以比将attrs添加到每个字段更快地执行操作,并且它会将其添加到包含多个字段的标记,例如group ,例如。 这也有效,对您来说更快:

<group attrs="{'readonly': [('state', '=', 'confirmed')]}"> <field name="your field_1"/> <field name="your field_2"/> ... </group>

If you want to apply that condition to every view of the model (there are models with more than one form view displayed in different parts of Odoo), it would be better to specify it in Python. In the definition of each field, you should add states argument:

your_field = fields.Whatever( ... readonly=False, states={ 'confirmed': [('readonly', True)], } )

This way, if the model is opened by the user through a view different from the one you have modified, the fields would be readonly if the state is confirmed, it doesn't matter that you haven't modified the opened view.

On the other hand, if you want to apply your purpose only in a specific form view, you could do something quicker than adding the attrs to each field, and it would be adding it to tags which contain several fields, like group, for example. This also works and is faster for you:

<group attrs="{'readonly': [('state', '=', 'confirmed')]}"> <field name="your field_1"/> <field name="your field_2"/> ... </group>

更多推荐

'confirmed',字段,attrs,电脑培训,计算机培训,IT培训"/> <meta name=&quo

本文发布于:2023-04-10 11:30:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/dzcp/d01d4e1db14719a260c7a4fb867a5722.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:字段   表单   状态   如何在   fields

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!