采购创建失败了产品--Odoo v9社区

时间:2017-03-03 20:14:39

标签: python openerp odoo-9

我正在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_idproduct_uom_qty不会进入stock.picking,但会在stock.picking模型上使用One2many字段调用它们,如下所示:

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

因此,product_idproduct_uom_qty位于stock.move,因此当我点击我的按钮时,会创建挑选,但它不会带走产品,因此,如何从我的函数中添加这种关系?

1 个答案:

答案 0 :(得分:1)

创建挑选行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