Skip to Content
Menu
This question has been flagged
2 Replies
7900 Views

Hello my friends,

I have created 2 fields "State" and  "country" as follows :

 - state = fields.Many2one('res.country.state', string='La cité', required=True)

 - country = fields.Many2one('res.country', string='le Pays', required=True)

My question is : how to make the choose of the state according the city. Do you have solution for that ? thank you.


* I have tried this solution, but it dosen't working for me in Odoo 10 : 

state = fields.Many2one(related = 'country_id.state', string='La cité', store=True)


Avatar
Discard
Best Answer

Hi Zakaria,

You can filter the states according to the selected country like this.

country_id_new = fields.Many2one('res.country', string="country")
state_id_new = fields.Many2one('res.country.state', string="State", store=True)

@api.onchange('country_id_new')
def set_values_to(self):
if self.country_id_new:
ids = self.env['res.country.state'].search([('country_id', '=', self.country_id_new.id)])
return {
'domain': {'state_id_new': [('id', 'in', ids.ids)],}
}


Thanks

Avatar
Discard
Author Best Answer

Thank you so much Niyas ! 

Avatar
Discard
Author

Niyas, you don't need a domaine in the field declaration or in xml file ?