产品选股创建失败 - Odoo v9 社区
Stock picking creation fails with product - Odoo v9 community
我正在从 fleet.vehicle.log.services
创建一个 stock.picking
,如下所示:
@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
上,所以当我点击我的按钮时,会创建拣货,但它不会拿走产品,所以,我如何从我的函数中添加这种关系?
创建领料线stock.move
然后在 stock.picking
中更新 move_lines
@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
我正在从 fleet.vehicle.log.services
创建一个 stock.picking
,如下所示:
@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
上,所以当我点击我的按钮时,会创建拣货,但它不会拿走产品,所以,我如何从我的函数中添加这种关系?
创建领料线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