Odoo13_联动下拉框
class ZeroneBook(models.Model): _name = "zerone.book" _description = "Zerone Books" business_tag1 = fields.Many2one('bus.type_1', string='业务类型1') business_tag2 = fields.Many2one('bus.type_2', string='业务类型2') # 设置联动规则 @api.onchange('business_tag1') def _onchange_tag1_id(self): self.business_tag2 = False if self.business_tag1: # 如果第一个框有值,则设置第二个框的取值范围 return {'domain': {'business_tag2': [('tag1_id', '=', self.business_tag1.id)]}} else: # 如果第一个框没有值,则第二个框滞空 return {'domain': {'business_tag2': []}} class bus_type_1(models.Model): _name = 'bus.type_1' _description = '业务类型1' # 下拉框中必须设置name字段为显示字段 name = fields.Char('业务类型1', required=True) # 必填 ext = fields.Char(string='扩展id', default='0') class bus_type_2(models.Model): _name = 'bus.type_2' _description = '业务类型2' tag1_id = fields.Many2one('bus.type_1', string='业务类型1的id') # 下拉框中必须设置name字段为显示字段 name = fields.Char('业务类型2', required=True) # 必填 ext = fields.Char(string='扩展id', default='0')