2017-10-12 113 views
2

對odoo我是嘗試onchange。條件是,在我插入數據如「SO00012」後,我的代碼將嘗試通過插入代碼瀏覽數據。這裏是我的代碼:odoo onchange沒有得到數據

def onchange_data(self, cr, uid, vals, ids, context=None): 

    stocks_picking_onchange = self.browse(cr, uid) 
    products = [] 

    stiks = self.browse(cr, uid, ids) 
    objk = self.pool.get('purchase.order') 
    objeck = self.pool.get('data.stock.picking') 
    objecks = objk.search(cr, uid,[('name','=',stiks.origin)]) 
    datas = objk.browse(cr, uid, objecks) 

    if datas: 
     for data in datas: 
      for line in data.order_line: 
       products.append((0, 0, { 
        'data1': line.id, 
        'data2' : line.product_qty, 
        'data3' : line.bonus, 
       })) 

,但我從來沒有得到過的數據,我的朋友sugges我來添加方法來創建這樣的:

def onchange_data(self, cr, uid, vals, ids, context=None): 
    res = super(stock_picking, self).create(cr, uid, vals, context=context) 
    stocks_picking_onchange = self.browse(cr, uid) 
    products = [] 

但是,它還是老樣子不工作

+0

我沒有看到* onchange()*方法中的return語句。 –

回答

1

這是真的,您創建了記錄列表,但並未影響到您的型號的任何字段:

if datas: 
     products.append((5,0,false)) # if you want to remove all old records 
     # i think without this line you will add the new record to the old list 
     for data in datas: 
      for line in data.order_line: 
       products.append((0, 0, { 
        'data1': line.id, 
        'data2' : line.product_qty, 
        'data3' : line.bonus, 
       })) 
# return your value 
return {'values' : {'your_field_name_here': products}} 

有一件事情y你應該知道onchange data1,data2和data3必須出現在你的領域的樹中,否則Web客戶端將不知道在哪裏存儲它們,它們將會丟失。