我有模型来存储运动员的训练结果和树视图来插入结果
型号代码是:
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 值的列
此外,可见性必须自动更改,以便如果锻炼状态变为“by_weight”,它会更改为它,依此类推。