Odoo级联查询,三级联动:
demo1:
state_id = fields.Many2one(“res.country.state”, string=‘State’, ondelete=‘restrict’)
country_id = fields.Many2one(‘res.country’, string=‘Country’, ondelete=‘restrict’)
@api.onchange(‘country_id’)
def _onchange_country_id(self):
if self.country_id:
return {‘domain’: {‘state_id’: [(‘country_id’, ‘=’, self.country_id.id)]}}
else:
return {‘domain’: {‘state_id’: []}}
demo2:
product_type = fields.Many2one(‘material.group’, string=“Product Type*”, domain=[(‘material_group’, ‘ilike’, ‘R-’)])
product_class = fields.Many2one(‘plm.subclass’, string=‘Sub Class’)
@api.onchange(‘product_type’)
def _onchange_product_type(self):
if self.product_type:
return {‘domain’: {‘product_class’: [(‘material_group’, ‘=’, self.product_type.material_group)]}}
else:
return {‘domain’: {‘product_class’: []}}