Advertisement
Guest User

init_stock_move

a guest
Sep 12th, 2019
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.73 KB | None | 0 0
  1. def _init_stock_move(self):
  2.         stock_location = self.env.ref('stock.stock_location_stock')
  3.        
  4.         for prod in self.produce_ids:
  5.             move = self.env['stock.move'].create({
  6.                 'name': 'IN-'+str(prod.item_id.name),
  7.                 'location_id': stock_location.id,
  8.                 'location_dest_id': stock_location.id,
  9.                 'product_id': prod.item_id.id,
  10.                 'product_uom': prod.item_id.uom_id.id,
  11.                 'product_uom_qty': prod.produced_qty,
  12.                 'picking_type_id': 1,  # assign picking type to id of 'iRebero: Receipts'
  13.                 'reserved_availability': prod.produced_qty,
  14.                 'availability': prod.produced_qty,
  15.                 'ordered_qty': prod.produced_qty
  16.             })
  17.            
  18.             # This creates a stock.move.line record.
  19.             # You could also do it manually using self.env['stock.move.line'].create({...})
  20.             # move.move_line_ids.write({'qty_done': prod.produced_qty})
  21.             move.reserved_quant_ids.write({'qty': prod.produced_qty})
  22.             move.quant_ids.write({'qty': prod.produced_qty, 'product_qty': prod.produced_qty})
  23.            
  24.             picking = self.env['stock.picking'].create({
  25.                     'state': 'draft',
  26.                     'location_id': stock_location.id,
  27.                     'location_dest_id': stock_location.id,
  28.                     'origin': self.name,
  29.                     # 'move_lines': move,
  30.                     'picking_type_id': 1,
  31.                     'picking_type_code': 'incoming',
  32.                     'quant_reserved_exist':False,
  33.                     'min_date': datetime.today()
  34.             })
  35.             picking.move_lines = move
  36.         return {}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement