105 lines
5.7 KiB
Diff
105 lines
5.7 KiB
Diff
diff --git a/trytond/trytond/modules/stock_lot/stock.py b/trytond/trytond/modules/stock_lot/stock.py
|
|
index f851071..d13b03d 100644
|
|
--- a/trytond/trytond/modules/stock_lot/stock.py
|
|
+++ b/trytond/trytond/modules/stock_lot/stock.py
|
|
@@ -170,33 +170,73 @@ class ShipmentOut(metaclass=PoolMeta):
|
|
shipments, create=create, write=write)
|
|
to_write = []
|
|
for shipment in shipments:
|
|
- outgoing_by_product = defaultdict(list)
|
|
- for move in shipment.outgoing_moves:
|
|
- outgoing_by_product[move.product.id].append(move)
|
|
- for move in shipment.inventory_moves:
|
|
- if not move.lot:
|
|
- continue
|
|
- quantity = Uom.compute_qty(move.uom, move.quantity,
|
|
- move.product.default_uom, round=False)
|
|
- outgoing_moves = outgoing_by_product[move.product.id]
|
|
- while outgoing_moves and quantity > 0:
|
|
- out_move = outgoing_moves.pop()
|
|
- out_quantity = Uom.compute_qty(out_move.uom,
|
|
- out_move.quantity, out_move.product.default_uom,
|
|
- round=False)
|
|
- values = {}
|
|
- if quantity < out_quantity:
|
|
- with Transaction().set_context(_stock_move_split=True):
|
|
- outgoing_moves.extend(
|
|
- Move.copy([out_move], default={
|
|
- 'quantity': out_move.uom.round(
|
|
- out_quantity - quantity),
|
|
- }))
|
|
- values['quantity'] = out_move.uom.round(quantity)
|
|
- values['lot'] = move.lot.id
|
|
- to_write.extend(([out_move], values))
|
|
- quantity -= out_quantity
|
|
- assert move.uom.round(quantity) <= 0
|
|
+ if 'stock.move' in Move._get_origin():
|
|
+ # patch keep origin sync inventory to outgoing
|
|
+ outgoing_by_product = defaultdict(list)
|
|
+ for move in shipment.outgoing_moves:
|
|
+ key = (move.product.id, move)
|
|
+ outgoing_by_product[key].append((move, Uom.compute_qty(move.uom,
|
|
+ move.quantity, move.product.default_uom,
|
|
+ round=False)))
|
|
+
|
|
+ for move in shipment.inventory_moves:
|
|
+ if not move.lot:
|
|
+ continue
|
|
+ quantity = Uom.compute_qty(move.uom, move.quantity,
|
|
+ move.product.default_uom, round=False)
|
|
+ key = (move.product.id, move.origin)
|
|
+ outgoing_moves = outgoing_by_product[key]
|
|
+ while outgoing_moves and quantity > 0:
|
|
+ out_move, out_quantity = outgoing_moves.pop()
|
|
+ values = {}
|
|
+ pending_qty = out_quantity
|
|
+ if quantity < out_quantity:
|
|
+ with Transaction().set_context(_stock_move_split=True):
|
|
+ new_move, = Move.copy([out_move], default={
|
|
+ 'quantity': quantity,
|
|
+ 'lot': move.lot.id
|
|
+ })
|
|
+ to_write.extend(([move], {'origin': str(new_move)}))
|
|
+ pending_qty = out_move.uom.round(out_quantity - quantity)
|
|
+ quantity = move.quantity - quantity
|
|
+ else:
|
|
+ quantity = 0
|
|
+ to_write.extend( ([out_move], {'lot': move.lot}) )
|
|
+ outgoing_by_product[key].append((out_move, pending_qty))
|
|
+ for values in outgoing_by_product.values():
|
|
+ for move, qty in values:
|
|
+ if qty > 0:
|
|
+ to_write.extend(([move], {'quantity': qty}))
|
|
+ else:
|
|
+ # core sync inventory to outgoing
|
|
+ outgoing_by_product = defaultdict(list)
|
|
+ for move in shipment.outgoing_moves:
|
|
+ outgoing_by_product[move.product.id].append(move)
|
|
+ for move in shipment.inventory_moves:
|
|
+ if not move.lot:
|
|
+ continue
|
|
+ quantity = Uom.compute_qty(move.uom, move.quantity,
|
|
+ move.product.default_uom, round=False)
|
|
+ outgoing_moves = outgoing_by_product[move.product.id]
|
|
+ while outgoing_moves and quantity > 0:
|
|
+ out_move = outgoing_moves.pop()
|
|
+ out_quantity = Uom.compute_qty(out_move.uom,
|
|
+ out_move.quantity, out_move.product.default_uom,
|
|
+ round=False)
|
|
+ values = {}
|
|
+ if quantity < out_quantity:
|
|
+ with Transaction().set_context(_stock_move_split=True):
|
|
+ outgoing_moves.extend(
|
|
+ Move.copy([out_move], default={
|
|
+ 'quantity': out_move.uom.round(
|
|
+ out_quantity - quantity),
|
|
+ }))
|
|
+ values['quantity'] = out_move.uom.round(quantity)
|
|
+ values['lot'] = move.lot.id
|
|
+ to_write.extend(([out_move], values))
|
|
+ quantity -= out_quantity
|
|
+ assert move.uom.round(quantity) <= 0
|
|
+
|
|
if to_write:
|
|
Move.write(*to_write)
|