如何在 ODOO v8 中列出一个国家/地区的状态

How list States of a Country in ODOO v8

我正在尝试列出一个国家/地区的所有州。 在 OpenERP v7 中,我想这可能是可行的:

_columns = { 'country_id': fields.many2one('res.country', 'Country'), 'state_id': fields.related('country_id', 'state_id', type="many2one", relation="res.country.state", string="State"), }

我如何在 Odoo-v8 中做到这一点? 我试过了:

country_id = fields.many2one('res.country', 'Country') state_id = fields.related('country_id', 'state_id', type="many2one", relation="res.country.state", string="State")

但是我得到了,in 'module' is not defined 'related'

关于关系字段的官方文档不是很清楚。

我想也许我需要一个 onchange 方法:

@api.onchange('country_id') def: _onchange_country(self): #I don’t how list the states, inside this method

你有什么解决办法吗?

在 Odoo 8.0 中,新 API 字段本身在任何字段中使用 相关属性 。 听说没有任何工具可以添加相关的单独字段

就这样..

country_id = fields.many2one('res.country', 'Country') 
state_id=fields.many2one(related='country_id.state_id.id', store=True)

希望这对您有所帮助..:)