[IMP] When reserved quants are ok, no need to rereserve quants
bzr revid: jco@openerp.com-20140227131237-du11dk5fu71nfnex
This commit is contained in:
parent
634d0f3ff8
commit
0f52affe0b
|
@ -1041,10 +1041,12 @@ class stock_picking(osv.osv):
|
|||
|
||||
def do_recompute_remaining_quantities(self, cr, uid, picking_ids, context=None):
|
||||
pack_op_obj = self.pool.get('stock.pack.operation')
|
||||
quants_res = True
|
||||
for picking in self.browse(cr, uid, picking_ids, context=context):
|
||||
op_ids = [op.id for op in picking.pack_operation_ids]
|
||||
if op_ids:
|
||||
pack_op_obj.recompute_rem_qty_from_operation(cr, uid, op_ids, context=context)
|
||||
quants_res = quants_res and pack_op_obj.recompute_rem_qty_from_operation(cr, uid, op_ids, context=context)
|
||||
return quants_res
|
||||
|
||||
def _create_extra_moves(self, cr, uid, picking, context=None):
|
||||
'''This function creates move lines on a picking, at the time of do_transfer, based on
|
||||
|
@ -1092,13 +1094,15 @@ class stock_picking(osv.osv):
|
|||
self.action_done(cr, uid, [picking.id], context=context)
|
||||
continue
|
||||
else:
|
||||
self.do_recompute_remaining_quantities(cr, uid, [picking.id], context=context)
|
||||
quants_ok = self.do_recompute_remaining_quantities(cr, uid, [picking.id], context=context)
|
||||
#create extra moves in the picking (unexpected product moves coming from pack operations)
|
||||
self._create_extra_moves(cr, uid, picking, context=context)
|
||||
if not quants_ok:
|
||||
self._create_extra_moves(cr, uid, picking, context=context)
|
||||
picking.refresh()
|
||||
#split move lines eventually
|
||||
todo_move_ids = []
|
||||
toassign_move_ids = []
|
||||
no_rereserve = True
|
||||
for move in picking.move_lines:
|
||||
remaining_qty = move.remaining_qty
|
||||
if move.state in ('done', 'cancel'):
|
||||
|
@ -1106,15 +1110,18 @@ class stock_picking(osv.osv):
|
|||
continue
|
||||
elif move.state == 'draft':
|
||||
toassign_move_ids.append(move.id)
|
||||
no_rereserve = False
|
||||
if remaining_qty == 0:
|
||||
if move.state in ('draft', 'assigned', 'confirmed'):
|
||||
todo_move_ids.append(move.id)
|
||||
elif remaining_qty > 0 and remaining_qty < move.product_qty:
|
||||
no_rereserve = False
|
||||
new_move = stock_move_obj.split(cr, uid, move, remaining_qty, context=context)
|
||||
todo_move_ids.append(move.id)
|
||||
#Assign move as it was assigned before
|
||||
toassign_move_ids.append(new_move)
|
||||
self.rereserve_quants(cr, uid, picking, move_ids=todo_move_ids, context=context)
|
||||
if not quants_ok or not no_rereserve:
|
||||
self.rereserve_quants(cr, uid, picking, move_ids=todo_move_ids, context=context)
|
||||
if todo_move_ids and not context.get('do_only_split'):
|
||||
self.pool.get('stock.move').action_done(cr, uid, todo_move_ids, context=context)
|
||||
elif context.get('do_only_split'):
|
||||
|
@ -3553,7 +3560,6 @@ class stock_pack_operation(osv.osv):
|
|||
quants_done[quant.id] = 0
|
||||
before = time.time()
|
||||
link_obj.create(cr, uid, {'move_id': quant.reservation_id.id, 'operation_id': ops.id, 'qty': quant.qty}, context=context)
|
||||
print "Link create", time.time() - before
|
||||
else:
|
||||
qty = uom_obj._compute_qty(cr, uid, ops.product_uom_id.id, ops.product_qty, ops.product_id.uom_id.id)
|
||||
#Check moves with same product
|
||||
|
@ -3602,19 +3608,22 @@ class stock_pack_operation(osv.osv):
|
|||
link_obj.unlink(cr, uid, to_unlink_ids, context=context)
|
||||
_check_quants_reserved(op)
|
||||
|
||||
quants_reserve_ok = True
|
||||
for op in operations:
|
||||
op.refresh()
|
||||
if op.product_id:
|
||||
#TODO: Remaining qty: UoM conversions are done twice
|
||||
normalized_qty = uom_obj._compute_qty(cr, uid, op.product_uom_id.id, op.remaining_qty, op.product_id.uom_id.id)
|
||||
|
||||
if normalized_qty > 0:
|
||||
quants_reserve_ok = False
|
||||
_create_link_for_product(op.product_id.id, normalized_qty)
|
||||
elif op.package_id:
|
||||
prod_quants = self._get_remaining_prod_quantities(cr, uid, op, context=context)
|
||||
for product_id, qty in prod_quants.items():
|
||||
if qty > 0:
|
||||
quants_reserve_ok = False
|
||||
_create_link_for_product(product_id, qty)
|
||||
return quants_reserve_ok
|
||||
|
||||
def process_packaging(self, cr, uid, operation, quants, context=None):
|
||||
''' Process the packaging of a given operation, after the quants have been moved. If there was not enough quants found
|
||||
|
|
|
@ -1,3 +1,8 @@
|
|||
-
|
||||
Do it with the rights of Mr. Demo
|
||||
-
|
||||
!context
|
||||
uid: 'base.user_demo'
|
||||
-
|
||||
I first create a warehouse with pick-pack-ship and reception in 2 steps
|
||||
-
|
||||
|
@ -198,6 +203,6 @@
|
|||
related_dest_pickings = [x.picking_id for x in move_dest_ids if x.picking_id]
|
||||
picks = list(set(related_dest_pickings))
|
||||
for pick in picks:
|
||||
#pick_obj.do_prepare_partial(cr, uid, [pick.id])
|
||||
pick_obj.do_prepare_partial(cr, uid, [pick.id])
|
||||
pick_obj.do_transfer(cr, uid, [pick.id])
|
||||
print "after second transfer", time.time()
|
Loading…
Reference in New Issue