mirror of
https://github.com/NaN-tic/trytond-patches.git
synced 2023-12-14 06:03:03 +01:00
80 lines
3.7 KiB
Diff
80 lines
3.7 KiB
Diff
diff -r 8684df73e037 shipment.py
|
|
--- a/trytond/trytond/modules/stock/shipment.py Fri Sep 04 16:29:38 2015 +0200
|
|
+++ b/trytond/trytond/modules/stock/shipment.py Fri Sep 04 16:30:32 2015 +0200
|
|
@@ -1111,6 +1111,14 @@
|
|
unit_price=move.unit_price,
|
|
)
|
|
|
|
+ @staticmethod
|
|
+ def _sync_inventory_to_outgoing_grouping_key(move, type):
|
|
+ '''
|
|
+ Returns the key used to sync inventory and outgoing moves for move
|
|
+ Type contains outgoing or incomming to indicate the kind of move
|
|
+ '''
|
|
+ return move.product.id
|
|
+
|
|
@classmethod
|
|
def _sync_inventory_to_outgoing(cls, shipments):
|
|
'Synchronise outgoing moves with inventory moves'
|
|
@@ -1125,8 +1133,10 @@
|
|
continue
|
|
quantity = Uom.compute_qty(move.uom, move.quantity,
|
|
move.product.default_uom, round=False)
|
|
- outgoing_qty.setdefault(move.product.id, 0.0)
|
|
- outgoing_qty[move.product.id] += quantity
|
|
+ key = cls._sync_inventory_to_outgoing_grouping_key(move,
|
|
+ 'outgoing')
|
|
+ outgoing_qty.setdefault(key, 0.0)
|
|
+ outgoing_qty[key] += quantity
|
|
|
|
to_create = []
|
|
for move in shipment.inventory_moves:
|
|
@@ -1134,19 +1144,20 @@
|
|
continue
|
|
qty_default_uom = Uom.compute_qty(move.uom, move.quantity,
|
|
move.product.default_uom, round=False)
|
|
+ key = cls._sync_inventory_to_outgoing_grouping_key(move,
|
|
+ 'inventory')
|
|
# Check if the outgoing move doesn't exist already
|
|
- if outgoing_qty.get(move.product.id):
|
|
+ if outgoing_qty.get(key):
|
|
# If it exist, decrease the sum
|
|
- if qty_default_uom <= outgoing_qty[move.product.id]:
|
|
- outgoing_qty[move.product.id] -= qty_default_uom
|
|
+ if qty_default_uom <= outgoing_qty[key]:
|
|
+ outgoing_qty[key] -= qty_default_uom
|
|
continue
|
|
# Else create the complement
|
|
else:
|
|
- out_quantity = (qty_default_uom
|
|
- - outgoing_qty[move.product.id])
|
|
+ out_quantity = (qty_default_uom - outgoing_qty[key])
|
|
out_quantity = Uom.compute_qty(
|
|
move.product.default_uom, out_quantity, move.uom)
|
|
- outgoing_qty[move.product.id] = 0.0
|
|
+ outgoing_qty[key] = 0.0
|
|
else:
|
|
out_quantity = move.quantity
|
|
|
|
@@ -1164,16 +1175,18 @@
|
|
for move in shipment.outgoing_moves:
|
|
if move.state == 'cancel':
|
|
continue
|
|
- if outgoing_qty.get(move.product.id, 0.0) > 0.0:
|
|
+ key = cls._sync_inventory_to_outgoing_grouping_key(move,
|
|
+ 'outgoing')
|
|
+ if outgoing_qty.get(key, 0.0) > 0.0:
|
|
exc_qty = Uom.compute_qty(move.product.default_uom,
|
|
- outgoing_qty[move.product.id], move.uom)
|
|
+ outgoing_qty[key], move.uom)
|
|
removed_qty = Uom.compute_qty(move.uom,
|
|
min(exc_qty, move.quantity), move.product.default_uom,
|
|
round=False)
|
|
Move.write([move], {
|
|
'quantity': max(0.0, move.quantity - exc_qty),
|
|
})
|
|
- outgoing_qty[move.product.id] -= removed_qty
|
|
+ outgoing_qty[key] -= removed_qty
|
|
|
|
@classmethod
|
|
@ModelView.button
|