Allow partial assignation on Supplier Shipment Return

issue3492
review1681002
This commit is contained in:
Cédric Krier
2013-11-25 12:27:06 +01:00
parent c6673c5345
commit 35a8bc1141
3 changed files with 22 additions and 37 deletions
+2
View File
@@ -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
+14 -7
View File
@@ -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:
+6 -30
View File
@@ -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