当其他选择字段发生变化时,我正在尝试更新选择字段,我试过这个:
class Billard(models.Model):
_name = 'billard'
name = fields.Char()
value3 = fields.Selection(string="Selection",selection=[('pair','Pair'),('impair','Impair')],default = 'impair')
value4 = fields.Selection(string="Selection dependante",selection = [('1','1'),('3','3'),('5','5')])
description = fields.Text()
@api.onchange('value3')
def get_selection(self) :
if self.value3 :
if self.value3 == "impair" :
self.value4 = [('1','1'),('3','3'),('5','5')]
else :
self.value4 = [('2','2'),('4','4'),('6','6')]
else :
self.value4 = [('error','error')]
但是我收到了一个错误:ValueError: Wrong value for billard.value4: [('1', '1'), ('3', '3'), ('5', '5')]
似乎我不能影响选择字段的列表,我将不胜感激任何帮助:)
答案 0 :(得分:0)
您正在应用错误的逻辑
将选择字段更改为计算字段,并使用依赖(例如@api.depends('value3')
现在将您的逻辑放在装饰方法中,它将根据条件返回选择列表
我希望它对您的情况有所帮助。