我正在从stock.picking创建一个fleet.vehicle.log.services,如下所示:
@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,而是在stock.picking模型中使用One2many字段调用它们:
'move_lines': fields.one2many('stock.move', 'picking_id', string="Stock Moves", copy=True),所以,product_id和product_uom_qty都在stock.move上,所以当我点击按钮时,就会创建拣选,但是它不会占用产品,那么,我如何从函数中添加这种关系呢?
发布于 2017-03-05 20:36:09
创建挑选stock.move的行
然后更新move_lines中的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 pickinghttps://stackoverflow.com/questions/42587675
复制相似问题