diff --git a/addons/stock/stock.py b/addons/stock/stock.py
index ed7a963db5f..b0e706e6c87 100644
--- a/addons/stock/stock.py
+++ b/addons/stock/stock.py
@@ -2594,11 +2594,20 @@ class stock_move(osv.osv):
tot_qty += pack_lot.qty
if ops.pack_lot_ids and ops.product_id and float_compare(tot_qty, ops.product_qty, precision_rounding=ops.product_uom_id.rounding) != 0.0:
raise UserError(_('You have a difference between the quantity on the operation and the quantities specified for the lots. '))
+
quants_taken = []
false_quants = []
lot_move_qty = {}
+ #Group links by move first
+ move_qty_ops = {}
for record in ops.linked_move_operation_ids:
move = record.move_id
+ if not move_qty_ops.get(move):
+ move_qty_ops[move] = record.qty
+ else:
+ move_qty_ops[move] += record.qty
+ #Process every move only once for every pack operation
+ for move in move_qty_ops:
self.check_tracking(cr, uid, move, ops, context=context)
preferred_domain = [('reservation_id', '=', move.id)]
fallback_domain = [('reservation_id', '=', False)]
@@ -2606,7 +2615,7 @@ class stock_move(osv.osv):
dom = main_domain
if not ops.pack_lot_ids:
preferred_domain_list = [preferred_domain] + [fallback_domain] + [fallback_domain2]
- quants = quant_obj.quants_get_preferred_domain(cr, uid, record.qty, move, ops=ops, domain=dom,
+ quants = quant_obj.quants_get_preferred_domain(cr, uid, move_qty_ops[move], move, ops=ops, domain=dom,
preferred_domain_list=preferred_domain_list, context=context)
quant_obj.quants_move(cr, uid, quants, move, ops.location_dest_id, location_from=ops.location_id,
@@ -2614,7 +2623,7 @@ class stock_move(osv.osv):
dest_package_id=quant_dest_package_id, entire_pack=entire_pack, context=context)
else:
# Check what you can do with reserved quants already
- qty_on_link = record.qty
+ qty_on_link = move_qty_ops[move]
rounding = ops.product_id.uom_id.rounding
for reserved_quant in move.reserved_quant_ids:
if not reserved_quant.lot_id:
@@ -2632,7 +2641,7 @@ class stock_move(osv.osv):
if not move_qty.get(move.id):
raise UserError(_("The roundings of your Unit of Measures %s on the move vs. %s on the product don't allow to do these operations or you are not transferring the picking at once. ") % (move.product_uom.name, move.product_id.uom_id.name))
- move_qty[move.id] -= record.qty
+ move_qty[move.id] -= move_qty_ops[move]
#Handle lots separately
if ops.pack_lot_ids:
@@ -4456,6 +4465,8 @@ class stock_pack_operation(osv.osv):
show_reserved = any([x for x in pack.pack_lot_ids if x.qty_todo > 0.0])
ctx.update({'serial': serial,
'only_create': only_create,
+ 'create_lots': picking_type.use_create_lots,
+ 'state_done': pack.picking_id.state == 'done',
'show_reserved': show_reserved})
return {
'name': _('Lot Details'),
@@ -4534,18 +4545,22 @@ class stock_pack_operation_lot(osv.osv):
('uniq_lot_name', 'unique(operation_id, lot_name)', 'You have already mentioned this lot name in another line')]
def do_plus(self, cr, uid, ids, context=None):
+ pack_obj = self.pool['stock.pack.operation']
for packlot in self.browse(cr, uid, ids, context=context):
self.write(cr, uid, [packlot.id], {'qty': packlot.qty + 1}, context=context)
- self.pool['stock.pack.operation'].write(cr, uid, [packlot.operation_id.id], {'qty_done': packlot.operation_id.qty_done + 1}, context=context)
- pack = self.browse(cr, uid, ids[0], context=context).operation_id.id
- return self.pool['stock.pack.operation'].split_lot(cr, uid, [pack], context=context)
+ pack = self.browse(cr, uid, ids[0], context=context).operation_id
+ qty_done = sum([x.qty for x in pack.pack_lot_ids])
+ pack_obj.write(cr, uid, [pack.id], {'qty_done': qty_done}, context=context)
+ return pack_obj.split_lot(cr, uid, [pack.id], context=context)
def do_minus(self, cr, uid, ids, context=None):
+ pack_obj = self.pool['stock.pack.operation']
for packlot in self.browse(cr, uid, ids, context=context):
self.write(cr, uid, [packlot.id], {'qty': packlot.qty - 1}, context=context)
- self.pool['stock.pack.operation'].write(cr, uid, [packlot.operation_id.id], {'qty_done': packlot.operation_id.qty_done - 1}, context=context)
- pack = self.browse(cr, uid, ids[0], context=context).operation_id.id
- return self.pool['stock.pack.operation'].split_lot(cr, uid, [pack], context=context)
+ pack = self.browse(cr, uid, ids[0], context=context).operation_id
+ qty_done = sum([x.qty for x in pack.pack_lot_ids])
+ pack_obj.write(cr, uid, [pack.id], {'qty_done': qty_done}, context=context)
+ return pack_obj.split_lot(cr, uid, [pack.id], context=context)
class stock_move_operation_link(osv.osv):
diff --git a/addons/stock/stock_view.xml b/addons/stock/stock_view.xml
index bdb3e216915..9c0a90304f5 100644
--- a/addons/stock/stock_view.xml
+++ b/addons/stock/stock_view.xml
@@ -761,10 +761,10 @@
-
+
-
-
+
+
@@ -777,7 +777,19 @@
-
+
+ stock.pack.operation.lots.form
+ stock.pack.operation.lot
+
+
+
+
+
stock.picking.form