0

我需要帮助来完成我想在 Odoo 8 中实现的目标。我有 2 个选择。A 和 B。根据选择 A 中选择的值,我需要在选择 B 中显示特定值。一段代码更清楚:

selection_A = fields.Selection([('fruit', 'Fruit'),
                                 ('branch', 'Branch'),
                                 ('root','Root')],
                                'Tree', required=True)

selection_B = fields.Selection([('deep', 'Deep'),
                                 ('large', 'Large'),
                                 ('orange','Orange')],
                                'Feature', required=True)

因此,当在 selection_A 中选择水果时,我需要在 selection_B 'Orange' 中显示结果。有什么建议吗?

4

1 回答 1

1

您可以使用@api.onchange('selection_A') 创建一个函数。当您更改 selection_A 的值时,它将被调用。然后您可以将所需的值写入 selection_B。

@api.onchange('selection_A')
def compute_selection_B(self):
    if self.selection_A == 'fruit':
        self.selection_B = 'orange'
于 2018-09-04T16:09:47.010 回答