设置默认国家/地区

2024-05-17 06:24:45 发布

您现在位置:Python中文网/ 问答频道 /正文

我想为SturnID字段设置默认国家“香港”。我在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')

Tags: 函数代码pyodoo10selfapiiddefault
2条回答

返回值始终与字段数据类型匹配。在您的例子中,存储“char”值并返回“Boolean”(true/false)。这没道理。在

如果您想要下拉列表,那么将“country_info”数据类型从“Char”更改为“manyOne”,并且您的默认函数应该根据您的逻辑返回“integer”值。在

Python Lambda函数主要与filter()、map()和reduce()函数结合使用。在

奥多10

Python代码:

country_id = fields.Many2one('res.country', string='Country', default=lambda self: self.env['res.country'].browse([(95)]))

XML代码:

^{pr2}$

相关问题 更多 >