动态隐藏树视图odoo 9中的字段和行 [英] dynamicly hide fields and rows in tree view odoo 9

查看:291
本文介绍了动态隐藏树视图odoo 9中的字段和行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个模型来存储运动员的训练结果,并以树状视图插入来自

I have model to store training results for athletes and tree view to insert results from

型号代码为:

class GeneralFitnessDetails(Model):

    _name = 'general_fitness_details'
    generalFitnessDetails = Many2one("general_fitness")
    player = Many2one('player')
    exercise = Many2one("exercise")
    exercise_state = Selection([('by_reps', 'By Reps'),
                                ('by_time', 'By Time'),
                                ('by_distance', 'By Distance'),
                                ('by_weight', 'By Weight')])
    reps = Integer(string='Reps')
    time_sec = Integer(string='Seconds')
    weight = Integer(string='Weight/KG')
    distance = Integer(string='Distance/Meters')

这是查看代码

<tree>
<field name="player"/>
<field name="exercise"/>
<field name="exercise_state"/>
<field name="reps" invisible="[('exercise_state', '=', 'by_reps')]"/>
<field name="time_sec" invisible="[('exercise_state', '=', 'by_time')]"/>
<field name="weight" invisible="[('exercise_state', '=', 'by_weight')]"/>
<field name="distance" invisible="[('exercise_state', '=', 'by_distance')]"/>
</tree>

我需要创建一个按钮,其功能是:onClick,它根据锻炼状态过滤树视图中显示的列的可见性;因此,如果运动状态的值为"by_distance",则它仅显示包含by distance值的列

what I need is to create a button where it's function is : onClick , it filters the visibility of the shown columns in the tree view according to the exercise state ; so that if the exercise state's value is "by_distance" then it shows only the column that holds the values of by distance

还必须自动更改可见性,以使如果锻炼状态变为"by_weight",它也会随之更改,依此类推.

Also the visibility have to be automatically changed so that if the exercise state becomes "by_weight" it changes to it and so on .

推荐答案

即使使用attrs或具有不可见属性的直接设置,也无法有条件地从树状视图中隐藏字段.

You can not hide fields from tree view conditionally, even with attrs or direct with invisible attribute.

原因是树视图包含多个记录,因此无法隐藏1条记录的字段,而对于其他记录则隐藏字段,因为标头对于所有记录都是通用的.这就是为什么不可见在树状视图中无法有条件工作的原因.

The reason is that tree view contains multiple records so it's not possible to hide field for 1 record and visible for others because headers are common for all the records. That's why invisible won't work conditionally in tree view.

是的,但是它将像这样静态地(而不是动态地)工作

Yes but it will work statically (not dynamically) as like,

invisible="1" or invisible="True"

如果树视图可编辑,则可以有条件地使用readonly属性.

You can use readonly attribute conditionally if tree view is editble.

这篇关于动态隐藏树视图odoo 9中的字段和行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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