будет создано фиктивное поле
Код: Выделить всё
domain_district = fields.Char(compute='_compute_domain_district')
Код: Выделить всё
@api.depends('state_id')
def _compute_domain_district(self):
for rec in self:
if rec.state_id:
districts = self.env['res.country.district'].sudo().search([('state_id', '=', rec.state_id.id)])
domain = [('id', 'in', districts.ids)] if districts else []
else:
domain = []
rec.domain_district = json.dumps(domain)
Код: Выделить всё
Код: Выделить всё
@api.onchange('state_id', 'district_id')
def _onchange_state_id(self):
result = {}
if self.state_id:
result['domain'] = {'district_id': [('state_id', '=', self.state_id.id)]}
else:
result['domain'] = {'district_id': [('id', 'in', [])]}
return result
Подробнее здесь: https://stackoverflow.com/questions/788 ... in-odoo-17