Python 设置默认国家/地区
我想为国家/地区id字段设置默认国家/地区“香港”。那么我在odoo10中为它写了什么函数。现在,我的python代码如下: py代码:Python 设置默认国家/地区,python,python-2.7,openerp,odoo-10,Python,Python 2.7,Openerp,Odoo 10,我想为国家/地区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:
@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')
返回值始终与字段数据类型匹配。在本例中,您存储“char”值并返回“Boolean”(真/假)。那是没有道理的
如果要下拉列表,请将“国家/地区信息”数据类型从“Char”更改为“manyOne”,默认函数应根据逻辑返回“integer”值。返回值始终与字段数据类型匹配。在本例中,您存储“char”值并返回“Boolean”(真/假)。那是没有道理的
如果要下拉列表,请将“country_info”数据类型从“Char”更改为“manyOne”,默认函数应根据逻辑返回“integer”值。Python Lambda函数主要与函数filter()、map()和reduce()结合使用 ODOO 10 Python代码:
country_id = fields.Many2one('res.country', string='Country', default=lambda self: self.env['res.country'].browse([(95)]))
XML代码:
<field name="country_id" readonly="1"/>
Python Lambda函数主要与函数filter()、map()和reduce()结合使用 ODOO 10 Python代码:
country_id = fields.Many2one('res.country', string='Country', default=lambda self: self.env['res.country'].browse([(95)]))
XML代码:
<field name="country_id" readonly="1"/>
是的,你说得对,奥德拉。为此,我添加了以下代码:country\u id=fields.manyOne('res.country',“country”,change\u default=True,default=\u get\u default\u country)@api.model def\u get\u default\u country(self):打印“yes:”,95返回95Yes,你说得对,奥德拉。为此,我添加了以下代码:country\u id=fields.manyOne('res.country',“country”,change\u default=True,default=\u get\u default\u country)@api.model def\u get\u default\u country(self):打印“yes:”,95返回95