基于其他选择框的选择框填充

Population of a selection box base on the Other Selection Box

美好的一天!我有一个问题,我正在尝试根据另一个选择框上的所选数据填充一个选择框,这是我的代码

.py

licensetype = fields.Many2one('hr.licensetype','License Type')
license = fields.Many2one('hr.license','License')

@api.one
@api.onchange('licensetype')
def getlicense(self):
    if len(self.licensetype) > 0:
        mdlLicense= self.env['hr.license'].search([('license_name', '=', int(self.licensetype[0]))])
        #raise Warning(mdlLicense.ids)
        self.license = mdlLicense.ids

但它仍然会填充所有许可证我想根据所选的许可证类型填充许可证。这是在 Odoo8

域是一个条件列表,每个条件都是(field_name、运算符、值)的三元组(列表或元组)。

这里,

  • field_name : 它是字符串类型,必须来自当前模型或使用成员资格 (.) 点运算符通过 Many2one/One2many 字段的任何关系遍历字段。

    - operator :用于比较字段的值和传递的值。 有效运算符列表 (>, >=, <, <=, =, !=, =?, ilike, like =like, =ilike, not like, not ilike, childs_of, in,不在)

  • value : 用于与字段的值进行比较。

可以使用三个逻辑运算符连接多个条件。 逻辑与、逻辑或、逻辑非。

阅读更多关于 domain

您可以通过为该字段定义域轻松实现此目的,无需编写任何额外代码。

只需将域名放入您的 xml 代码中。

<field name="licensetype" />
<field name="license" domain="[('licensetype','=',licensetype)]" />

:

记住hr.licensehr.licensetype之间一定有关系。许可证类型必须是 hr.license.

中的 Many2one

效果如你所愿