我從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_id
和product_uom_qty
不進stock.picking
,但他們被稱爲具有One2many場,上stock.picking
模型是這樣的:
'move_lines': fields.one2many('stock.move', 'picking_id', string="Stock Moves", copy=True),
所以,product_id
和product_uom_qty
上stock.move
,所以當我點擊我的按鈕,創建了採摘,但它沒有考慮產品,因此,如何從我的函數中添加這種關係?
轉到更新move_lines爲*數據庫結構*,並找出* stock.picking *對象。打開該記錄並查看必填字段以創建記錄集。根據你的創建* vals *更新。 –
嗨,不,產品不在那裏,我怎麼能說這個? – NeoVe