如何根据Odoo 12中formview中选择的值显示动态选择字段?
我正在使用Odoo 12,并试图在formView中显示到选择字段 第一个选择字段有2个值,但第二个选择字段有4个值,从第一个选择字段中选择的每个字段有2个值 我给出了伪代码,因为我不能显示生产代码如何根据Odoo 12中formview中选择的值显示动态选择字段?,odoo,odoo-11,odoo-12,Odoo,Odoo 11,Odoo 12,我正在使用Odoo 12,并试图在formView中显示到选择字段 第一个选择字段有2个值,但第二个选择字段有4个值,从第一个选择字段中选择的每个字段有2个值 我给出了伪代码,因为我不能显示生产代码 mainfile.py内容为 类MainClassFile(models.Model): 具有以下表单视图的同一py文件的xml文件: 我尝试了@api.onchange function\u name,但根据first\u field choosen,找不到选择特定第二个\u字段的逻辑。只需创
mainfile.py
内容为
类MainClassFile(models.Model):
我尝试了@api.onchange function\u name,但根据first\u field choosen,找不到选择特定第二个\u字段的逻辑。只需创建一个保存选择值的模型。并将你的领域转换为多个领域(是的,我只在研究这个领域。)你能展示一下吗?想象一下选择是记录,选择字段在选项固定且不大时使用,但如果选项较大且可以在此处更新,则选择字段不是答案,我们需要一个表来保存该选项,然后在两个表之间创建多个一的关系。
first_field = fields.Selection([ ('first':'Item-1'), ('second':'Item-2')],string="first-Selection")
second_field = fields.Selection([('1','one')
,('2','two')
,('3','three')
,('4','four')],
string='Only-two-fields')
@api.onchange('first_field')
def show_two_fields_only(self):
if self.first_field == 'first':
return {'domain':{second_field = fields.Selection([('1','one')
,('2','two')]
else
return {'domain':{second_field = fields.Selection([('3','three')
,('4','four')]
<group name="default" col="4" colspan="2">
<field name="first_field" required="1" default_focus="1" onchange="show_two_fields_only('first_type'/>
<field name="second_field" required="1"/>
</group>