From 35a8bc11415ff9b642b52b63d3533edd403d6d8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Mon, 25 Nov 2013 12:27:06 +0100 Subject: [PATCH] Allow partial assignation on Supplier Shipment Return issue3492 review1681002 --- CHANGELOG | 2 ++ move.py | 21 ++++++++++++++------- shipment.py | 36 ++++++------------------------------ 3 files changed, 22 insertions(+), 37 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 9e73b97ff3..bbd8ecc561 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,5 @@ +* Allow partial assignation on Supplier Shipment Return + Version 3.0.0 - 2013-10-21 * Bug fixes (see mercurial logs for details) * Add Mixin class with helper to setup stock quantity fields diff --git a/move.py b/move.py index 2d4749c4f4..d2438f78bd 100644 --- a/move.py +++ b/move.py @@ -706,7 +706,7 @@ class Move(Workflow, ModelSQL, ModelView): return to_pick @classmethod - def assign_try(cls, moves, grouping=('product',)): + def assign_try(cls, moves, with_childs=True, grouping=('product',)): ''' Try to assign moves. It will split the moves to assign as much possible. @@ -720,9 +720,13 @@ class Move(Workflow, ModelSQL, ModelView): Transaction().cursor.lock(cls._table) - locations = Location.search([ - ('parent', 'child_of', [x.from_location.id for x in moves]), - ]) + if with_childs: + locations = Location.search([ + ('parent', 'child_of', + [x.from_location.id for x in moves]), + ]) + else: + locations = list(set((m.from_location for m in moves))) with Transaction().set_context( stock_date_end=Date.today(), stock_assign=True): @@ -746,9 +750,12 @@ class Move(Workflow, ModelSQL, ModelView): continue to_location = move.to_location location_qties = {} - childs = Location.search([ - ('parent', 'child_of', [move.from_location.id]), - ]) + if with_childs: + childs = Location.search([ + ('parent', 'child_of', [move.from_location.id]), + ]) + else: + childs = [move.from_location] for location in childs: key = get_key(location) if key in pbl: diff --git a/shipment.py b/shipment.py index 9c50a08100..d0a09c2c7d 100644 --- a/shipment.py +++ b/shipment.py @@ -738,37 +738,13 @@ class ShipmentInReturn(Workflow, ModelSQL, ModelView): @ModelView.button def assign_try(cls, shipments): pool = Pool() - Product = pool.get('product.product') - Uom = pool.get('product.uom') - Date = pool.get('ir.date') Move = pool.get('stock.move') - - Transaction().cursor.lock(Move._table) - - moves = [m for s in shipments for m in s.moves] - location_ids = [m.from_location.id for m in moves] - with Transaction().set_context( - stock_date_end=Date.today(), - stock_assign=True): - pbl = Product.products_by_location(location_ids=location_ids, - product_ids=[m.product.id for m in moves]) - - for move in moves: - if move.state != 'draft': - continue - if (move.from_location.id, move.product.id) in pbl: - qty_default_uom = pbl[(move.from_location.id, move.product.id)] - qty = Uom.compute_qty(move.product.default_uom, - qty_default_uom, move.uom, round=False) - if qty < move.quantity: - return False - pbl[(move.from_location.id, move.product.id)] = ( - pbl[(move.from_location.id, move.product.id)] - - qty_default_uom) - else: - return False - cls.assign(shipments) - return True + if Move.assign_try([m for s in shipments for m in s.moves], + with_childs=False): + cls.assign(shipments) + return True + else: + return False @classmethod @ModelView.button