Skip to content

Instantly share code, notes, and snippets.

@josemoralesp
Created July 2, 2018 22:42
Show Gist options
  • Save josemoralesp/0a00fba86a8bcb297fbfca008588121e to your computer and use it in GitHub Desktop.
Save josemoralesp/0a00fba86a8bcb297fbfca008588121e to your computer and use it in GitHub Desktop.
qty_available = env['stock.quant']._get_available_quantity(record.product_id, record.location_id)
if qty_available:
qty_needed = record.product_uom._compute_quantity(record.product_uom_qty, record.product_id.uom_id)
real_qty = record.product_id.uom_id._compute_quantity(qty_available, record.product_uom)
if qty_needed > qty_available:
new_move = record.copy({'ordered_qty': real_qty, 'product_uom_qty': real_qty, 'state': 'confirmed', 'procure_method': 'make_to_stock', 'created_purchase_line_id': False, 'picking_id': record.picking_id.id})
#raise Warning('%s' % record.picking_id.name)
remaining = record.product_uom_qty - real_qty
record.write({'ordered_qty': remaining, 'product_uom_qty': remaining})
new_move._action_assign()
line = record.created_purchase_line_id
line.write({'product_qty': line.product_qty - real_qty})
else:
line = record.created_purchase_line_id
line.write({'product_qty': line.product_qty - record.product_uom_qty})
record.write({'state': 'confirmed', 'created_purchase_line_id': False, 'procure_method': 'make_to_stock'})
record._action_assign()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment