我正在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
,因此当我点击我的按钮时,会创建挑选,但它不会带走产品,因此,如何从我的函数中添加这种关系?
答案 0 :(得分: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