Allow partial assignation on Supplier Shipment Return
issue3492 review1681002
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user