Python 如何使用全局变量用Odoo 10更新选择字段?
嗨,是否可以有一个基于“onchange”更新的全局变量,并将其分配给选择字段Python 如何使用全局变量用Odoo 10更新选择字段?,python,python-2.7,global-variables,odoo,odoo-10,Python,Python 2.7,Global Variables,Odoo,Odoo 10,嗨,是否可以有一个基于“onchange”更新的全局变量,并将其分配给选择字段 variable = [] class a: @api.onchange('some_other_filed') def function1(self): global variable variable = #something based on some other filed test = fields.Selection(variable) 此更改
variable = []
class a:
@api.onchange('some_other_filed')
def function1(self):
global variable
variable = #something based on some other filed
test = fields.Selection(variable)
此更改将反映在选择字段中。我得到的只是选择字段中的空列表。不建议使用全局变量。如果您想使其在Odoo中的任何位置始终可用,可以在
ir.config_参数
表中使用持久字段。您可以在设置>技术>参数>系统参数上查看存储的配置参数
可以按如下方式设置参数的值:
self.env['ir.config_parameter'].set_param('use_journal_setting', True)
location = self.env['ir.config_parameter'].get_param(
'ir_attachment.location'
)
然后得到一些其他值,比如:
self.env['ir.config_parameter'].set_param('use_journal_setting', True)
location = self.env['ir.config_parameter'].get_param(
'ir_attachment.location'
)
您也可以使用某些值直接更新选择字段,也可以使用参数进行更新
@api.onchange('field_name')
def onchange_field_name(self):
self.test = self.env['ir.config_parameter'].get_param('parameter_name')
<强>注释:如果您需要许多全局变量,请考虑创建自己的参数表。
@ Navin还没有Bro。我创建了一个临时表,并使用了多个字段而不是选择字段。