使用外部模型的域 - Odoo 9
Domain using external models - Odoo 9
我正在尝试在 xml 视图文件的模型之间进行过滤。但我不能使用外部模型的值。
实际上我正在尝试根据之前的选择过滤字段 (M2O) 的选项。
Myview.xml trys to render this
Attributes:[Select an attribute from the list]
Version :[Select version here (from the available versions for the previously selected attribute)]
有我的模型
alternative_model
code = fields.Char('code', required=True, size=6)
description = fields.Char('description', required=True)
attribute_type_id = fields.Many2one('attribute', required=True)
attribute_version_id = fields.Many2one('version', required=True)
alternative_model
code = fields.Char('code', required=True, size=2)
description = fields.Char('description', required=True)
alternative_ids = fields.One2many('alternative','attribute_version_id')
alternative_model
code = fields.Char('code',required=True,size=6)
attribute_id = fields.Many2one('attribute',required=True)
description = fields.Char('description',required=True)
tag_ids = fields.One2many('tag','attribute_version_id')
我正在使用以下域:
<field string="version" name="attribute_version_id" domain="[([attribute_type_id.code], '=',[attribute_version_id.attribute_id.code])]"/>
你的xml好像有误。
1./ 您正在尝试使用同一字段尝试在屏幕上显示的域,这是错误的。
2./ 这个域将不起作用,因为它不允许访问运算符右侧的其他模型属性,在您的情况下是 '='。
尝试使用'name_search'方法'attribute_version_id',可以使用[=传递需要的值18=]context 并基于此,您可以筛选出 'attribute_version_id'.
的记录
尝试使用 "related" 字段。
在这种情况下,您需要使用 onchange 方法来更新域
你的 many2one 字段:
@api.onchange('attribute_type_id')
def onchage_attribute(self):
if self.attribute_type_id:# check if the user has selected an attribute
# cancel the selected version
#but you can check if it much the domain before seting to False
self.attribute_version_id = False
# return the new domain
return {'domain':{'attribute_version_id':[('attribute_id', '=', self.attribute_type_id.id)]}
else: # remove the domain
return {'domain':{'attribute_version_id':[]}
我正在尝试在 xml 视图文件的模型之间进行过滤。但我不能使用外部模型的值。
实际上我正在尝试根据之前的选择过滤字段 (M2O) 的选项。
Myview.xml trys to render this
Attributes:[Select an attribute from the list]
Version :[Select version here (from the available versions for the previously selected attribute)]
有我的模型
alternative_model
code = fields.Char('code', required=True, size=6)
description = fields.Char('description', required=True)
attribute_type_id = fields.Many2one('attribute', required=True)
attribute_version_id = fields.Many2one('version', required=True)
alternative_model
code = fields.Char('code', required=True, size=2)
description = fields.Char('description', required=True)
alternative_ids = fields.One2many('alternative','attribute_version_id')
alternative_model
code = fields.Char('code',required=True,size=6)
attribute_id = fields.Many2one('attribute',required=True)
description = fields.Char('description',required=True)
tag_ids = fields.One2many('tag','attribute_version_id')
我正在使用以下域:
<field string="version" name="attribute_version_id" domain="[([attribute_type_id.code], '=',[attribute_version_id.attribute_id.code])]"/>
你的xml好像有误。
1./ 您正在尝试使用同一字段尝试在屏幕上显示的域,这是错误的。
2./ 这个域将不起作用,因为它不允许访问运算符右侧的其他模型属性,在您的情况下是 '='。
尝试使用'name_search'方法'attribute_version_id',可以使用[=传递需要的值18=]context 并基于此,您可以筛选出 'attribute_version_id'.
的记录尝试使用 "related" 字段。
在这种情况下,您需要使用 onchange 方法来更新域 你的 many2one 字段:
@api.onchange('attribute_type_id')
def onchage_attribute(self):
if self.attribute_type_id:# check if the user has selected an attribute
# cancel the selected version
#but you can check if it much the domain before seting to False
self.attribute_version_id = False
# return the new domain
return {'domain':{'attribute_version_id':[('attribute_id', '=', self.attribute_type_id.id)]}
else: # remove the domain
return {'domain':{'attribute_version_id':[]}