2017-09-04 83 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 –