2017-09-04 68 views
1

我想为country_id字段设置默认国家“香港”。那么我为odoo10写的是什么函数。现在我的Python代码如下:设置默认国家

PY代码:

@api.depends('country_id') 
def _get_default_country(self, context=None): 
    if self.country_id: 
     return {'domain': [('country_id', '=', self.country_id.id)]} 
    print "yes:", 235 
    return True 

_defaults = { 
    'country_id': _get_default_country 
} 
country_info = fields.Char(compute='_get_default_country', 
          string='Default Country') 

回答

1

返回值始终匹配字段的数据类型。在你的情况下,你正在存储“char”值并返回“Boolean”(true/false)。这是没有道理的。

如果您想要下拉列表,然后将“country_info”数据类型从“Char”更改为“Many2one”,并且您的默认功能应根据您的逻辑返回“integer”值。

+0

是的,你是对的Odedra。我已经通过添加以下代码来完成此操作:country_id = fields.Many2one('res.country',“Country”,change_default = True,default = _get_default_country)@ api.model 012_bdef _get_default_country(self): print“yes: “,95 返回95 –