NeoVe
NeoVe

Reputation: 3897

Stock picking creation fails with product - Odoo v9 community

I'm creating a stock.picking from fleet.vehicle.log.services like this:

@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

The picking is created, this method is called with a button on view, like this:

<button name="create_picking" string="Crear Picking" type="object" class="oe_highlight"/>

My problem is, that product_id and product_uom_qty are not into stock.picking but they are called with a One2many field, on stock.picking model like this:

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

So, product_id and product_uom_qty are on stock.move, so when I click on my button, the picking is created, but it doesn't take the products, so, how can I add this relationship from my function?

Upvotes: 0

Views: 475

Answers (1)

m3asmi
m3asmi

Reputation: 1262

Create the lines of picking stock.move
And then update the move_lines in 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

Upvotes: 1

Related Questions