[FIX] stock: when transferring (action_done), do several links for the same operation and move at once

As the link between moves and operations is done for every quant,
we can do all links between a same operation and move at once.

Besides helping in performance, this fixes problems to handle all the lots
at once for one operation.

The views for pack operation lots are also refined.
This commit is contained in:
Josse Colpaert
2015-09-30 16:55:18 +02:00
parent 757ababa68
commit 98d18d767f
2 changed files with 40 additions and 13 deletions
+24 -9
View File
@@ -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):
+16 -4
View File
@@ -761,10 +761,10 @@
<field name="lot_id" invisible="context.get('only_create', False)"
domain="[('product_id','=', parent.product_id)]"
context="{'product_id': parent.product_id}"/>
<field name="qty_todo" invisible="not context.get('show_reserved') or context.get('serial')" readonly="1"/>
<field name="qty_todo" invisible="not context.get('show_reserved') or context.get('serial') or context.get('state_done')" readonly="1"/>
<field name="qty" invisible="context.get('serial')"/>
<button name="do_minus" type="object" icon="fa-minus-square" attrs="{'invisible': [('qty', '&lt;=', 0.99)]}" invisible="not context.get('show_reserved')"/>
<button name="do_plus" type="object" icon="fa-plus-square" attrs="{'invisible': [('plus_visible', '=', False)]}" invisible="not context.get('show_reserved')"/>
<button name="do_minus" type="object" icon="fa-minus-square" attrs="{'invisible': [('qty', '&lt;=', 0.99)]}" invisible="not context.get('show_reserved') or context.get('state_done')"/>
<button name="do_plus" type="object" icon="fa-plus-square" attrs="{'invisible': [('plus_visible', '=', False)]}" invisible="not context.get('show_reserved') or context.get('state_done')"/>
<field name="plus_visible" invisible="1"/>
</tree>
</field>
@@ -777,7 +777,19 @@
</field>
</record>
<record id="view_pack_operation_lot_lot_form" model="ir.ui.view">
<field name="name">stock.pack.operation.lots.form</field>
<field name="model">stock.pack.operation.lot</field>
<field eval="20" name="priority"/>
<field name="arch" type="xml">
<form>
<group>
<field name="lot_id"/>
<field name="qty"/>
</group>
</form>
</field>
</record>
<record id="view_picking_form" model="ir.ui.view">
<field name="name">stock.picking.form</field>