[FIX] stock: copy over pack_lot_ids when clicking on 'split'
Analogous to 6fde72abeacdac6e36a0c623c024252839f993ae but now instead for the 'split' button. Additionally this uses float_compare with the rounding set on the uom of the operation to determine if there are any units left, which is more correct. opw-685908
This commit is contained in:
+13
-8
@@ -1732,7 +1732,6 @@ class stock_picking(models.Model):
|
||||
def put_in_pack(self, cr, uid, ids, context=None):
|
||||
stock_move_obj = self.pool["stock.move"]
|
||||
stock_operation_obj = self.pool["stock.pack.operation"]
|
||||
stock_operation_lot_obj = self.pool["stock.pack.operation.lot"]
|
||||
package_obj = self.pool["stock.quant.package"]
|
||||
package_id = False
|
||||
for pick in self.browse(cr, uid, ids, context=context):
|
||||
@@ -1751,13 +1750,7 @@ class stock_picking(models.Model):
|
||||
|
||||
# the stock.pack.operation.lot records now belong to the new, packaged stock.pack.operation
|
||||
# we have to create new ones with new quantities for our original, unfinished stock.pack.operation
|
||||
for pack_lot_id in stock_operation_obj.browse(cr, uid, new_operation, context=context).pack_lot_ids:
|
||||
new_qty_todo = pack_lot_id.qty_todo - pack_lot_id.qty
|
||||
|
||||
if new_qty_todo > 0:
|
||||
stock_operation_lot_obj.copy(cr, uid, pack_lot_id.id, {'operation_id': operation.id,
|
||||
'qty_todo': new_qty_todo,
|
||||
'qty': 0}, context=context)
|
||||
stock_operation_obj._copy_remaining_pack_lot_ids(cr, uid, new_operation, operation.id, context=context)
|
||||
|
||||
op = stock_operation_obj.browse(cr, uid, new_operation, context=context)
|
||||
pack_operation_ids.append(op.id)
|
||||
@@ -4523,6 +4516,7 @@ class stock_pack_operation(osv.osv):
|
||||
if pack.product_qty - pack.qty_done > 0.0 and pack.qty_done < pack.product_qty:
|
||||
pack2 = self.copy(cr, uid, pack.id, default={'qty_done': 0.0, 'product_qty': pack.product_qty - pack.qty_done}, context=context)
|
||||
self.write(cr, uid, [pack.id], {'product_qty': pack.qty_done}, context=context)
|
||||
self._copy_remaining_pack_lot_ids(cr, uid, pack.id, pack2, context=context)
|
||||
else:
|
||||
raise UserError(_('The quantity to split should be smaller than the quantity To Do. '))
|
||||
return True
|
||||
@@ -4607,6 +4601,17 @@ class stock_pack_operation(osv.osv):
|
||||
'context': context,
|
||||
}
|
||||
|
||||
def _copy_remaining_pack_lot_ids(self, cr, uid, id, new_operation_id, context=None):
|
||||
stock_pack_operation_lot_obj = self.pool["stock.pack.operation.lot"]
|
||||
old_operation = self.browse(cr, uid, id, context=context)
|
||||
|
||||
for pack_lot_id in old_operation.pack_lot_ids:
|
||||
new_qty_todo = pack_lot_id.qty_todo - pack_lot_id.qty
|
||||
|
||||
if float_compare(new_qty_todo, 0, precision_rounding=old_operation.product_uom_id.rounding) > 0:
|
||||
stock_pack_operation_lot_obj.copy(cr, uid, pack_lot_id.id, {'operation_id': new_operation_id,
|
||||
'qty_todo': new_qty_todo,
|
||||
'qty': 0}, context=context)
|
||||
|
||||
class stock_pack_operation_lot(osv.osv):
|
||||
_name = "stock.pack.operation.lot"
|
||||
|
||||
Reference in New Issue
Block a user