2017-03-03 95 views
0

我從fleet.vehicle.log.services創建stock.picking這樣的:選股創建失敗產品 - Odoo V9社會

@api.multi 
def create_picking(self): 
    self.ensure_one() 
    vals = { 
     'location_id': self.location_id.id, 
     'location_dest_id': self.location_dest_id.id, 
     'product_id': self.product_id.id, # shouldn't be set on stock.picking, products are handled on it's positions (stock.move) 
     'product_uom_qty': self.product_uom_qty, # the same as for product_id 
     'picking_type_id': self.picking_type_id.id 
    } 
    picking = self.env['stock.picking'].create(vals) 
    return picking 

創建採摘,這種方法被稱爲與視圖按鈕,如下所示:

<button name="create_picking" string="Crear Picking" type="object" class="oe_highlight"/> 

我的問題是,product_idproduct_uom_qty不進stock.picking,但他們被稱爲具有One2many場,上stock.picking模型是這樣的:

'move_lines': fields.one2many('stock.move', 'picking_id', string="Stock Moves", copy=True), 

所以,product_idproduct_uom_qtystock.move,所以當我點擊我的按鈕,創建了採摘,但它沒有考慮產品,因此,如何從我的函數中添加這種關係?

+1

轉到更新move_lines爲*數據庫結構*,並找出* stock.picking *對象。打開該記錄並查看必填字段以創建記錄集。根據你的創建* vals *更新。 –

+0

嗨,不,產品不在那裏,我怎麼能說這個? – NeoVe

回答

1

創建採摘stock.move
的線,然後在stock.picking

@api.multi 
def create_picking(self): 
    self.ensure_one() 
    #creating move_lines 
    move_vals = { 
     'product_id':your_product, 
     'product_uom':your_uom, 
     'product_uom_qty':product_uom_qty, 
     'picking_type_id': self.picking_type_id.id, 
     } 
    move_ids = self.env['stock.move'].create(move_vals) 
    vals = { 
     'location_id': self.location_id.id, 
     'location_dest_id': self.location_dest_id.id, 
     'product_id': self.product_id.id, # shouldn't be set on stock.picking, products are handled on it's positions (stock.move) 
     'product_uom_qty': self.product_uom_qty, # the same as for product_id 
     'picking_type_id': self.picking_type_id.id 
     #the move_lines here 
     'move_lines':[(6,0,move_ids.ids)] 
    } 
    picking = self.env['stock.picking'].create(vals) 
    return picking 
+0

嗨,非常感謝,但是,可以舉個例子嗎?我問過這裏:http://stackoverflow.com/questions/42614194/expected-singleton-stock-move-odoo-v9-community,但我想盡可能保持代碼清潔,我不認爲我在這個問題上的做法是最簡單的方式。謝謝。 – NeoVe

+1

太棒了!非常感謝! – NeoVe

相關問題