2017-04-17 65 views
0

我试图在我的xml视图文件上的模型之间做一个过滤器。但我不能使用外部模型的值。使用外部模型的域 - Odoo 9

其实我试着根据以前的选择过滤字段(M2O)的选项。

Myview.xml改掉呈现此

属性:从列表中选择一个属性]

版本:[在此选择的版本(从可用版本之前选择的属性)]

有我的模型

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])]"/>

回答

1

我这种情况下,你需要使用的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':[]} 
+0

的伟大工程。我仍然必须练习更多的功能和api装饰器 – NMenam

+0

是的onchange现在更强大,然后用新的api – Cherif

0

您的xml似乎是错误的。

1. /您正在尝试使用相同的字段,您试图显示在屏幕上,这是错误的域。

2.此域名不可用,因为它不允许访问运营商右侧的其他模型属性,您的情况为'='

尝试使用“name_search”方法“attribute_version_id”,您可以通过使用背景,并基于该所要求的数值,就可以过滤掉的记录“attribute_version_id”

尝试采取“相关”字段。