1
我一直在嘗試在我的openerp模塊中使用下拉菜單列表。我有一個many2one字段包含類別。該字段與一個onchange函數關聯。這個onchange函數返回第二個字段的新值。現在一切正常,但我想在第二個字段中使用下拉菜單,以便我可以從中選擇值。我的Python代碼如下:如何在OpenERP中使用下拉字段?
class deg_form(osv.osv):
_name = "deg.form"
_columns = {
'categ1':fields.many2one('product.category','Parent Category',required=True),
'my_products':fields.char('Product',size=64)
}
def Product_Category_OnChange(self,cr,uid,ids,categ1):
pro_id=[]
cr.execute('select id,name from product_template where categ_id in (select id from product_category where parent_id in (select id from product_category where parent_id='+str(categ1)+')) union select id,name from product_template where categ_id in (select id from product_category where parent_id='+str(categ1)+') union select id,name from product_template where categ_id='+str(categ1))
res = cr.fetchall()
for pid,name in res:
pro_id.append((pid,name))
return {'value':{'my_products':pro_id}}
這裏是我的xml:過濾
<field name="categ1" on_change="Product_Category_OnChange(categ1)" />
我的價值觀,但都顯示在用逗號分隔的領域。我希望他們被列爲下拉列表。我用many2one,但這些值似乎沒有被過濾。因此,我在實現我的值作爲下拉列表視圖時遇到問題。請幫幫我。 Regards
我必須使用查詢,因爲我有要求加入其他表的數據的要求。無論如何,我可以使用查詢來做到這一點。謝謝 –
ofcourse:使用您的查詢並創建一個所有(結果)ID列表並使用該域的新列表。像[('id','in',your_id_list]] – CZoellner