2017-04-17 67 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」

嘗試採取「相關」字段。