如何在ODOO v8中列出一个国家的州

如何在ODOO v8中列出一个国家的州,odoo,odoo-8,Odoo,Odoo 8,我试图列出一个国家的所有州。 在OpenERP v7中,我认为这是可行的: \u列={ 'country_id':fields.manyOne('res.country','country'), “state\u id”:字段.related('country\u id','state\u id',type=“manyOne”,relation=“res.country.state”,string=“state”), } 在Odoo-v8中如何实现这一点? 我试过: country\u id=f

我试图列出一个国家的所有州。 在OpenERP v7中,我认为这是可行的:

\u列={
'country_id':fields.manyOne('res.country','country'),
“state\u id”:字段.related('country\u id','state\u id',type=“manyOne”,relation=“res.country.state”,string=“state”),
}

在Odoo-v8中如何实现这一点? 我试过:

country\u id=fields.manyOne('res.country','country')
state\u id=fields.related('country\u id','state\u id',type=“manyOne”,relation=“res.country.state”,string=“state”)

但我发现,
在'module'中没有定义为'related'

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

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

@api.onchange('country\u id'))
def:_onchange_country(self):
#我不知道如何在此方法中列出状态


您有什么解决方案吗?

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

就这样

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

我希望这会对您有所帮助:)

谢谢你的回答!它如预期的那样工作……如果a想将表格关联起来:res_country What my_声明了我该怎么做?在我的状态下,我有一个与国家相关的id家长。我无法理解你的问题,请在depth中澄清我。我构建了一个名为“我的状态”的新类。他的属性是
country\u id
name
,所以当我试图列出他的记录时,我遇到了一个错误,我想我的类出了问题,因为它不是
base
模块的一部分……我现在不知道我现在做什么:(如果你不在乎,我想给你的收件箱写更多细节!