当对象的状态变为“ 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
发布评论