Improve move sorting on Picking List report
This commit is contained in:
1 parent
d2717a7b7f
commit
587f28621f
2 files changed
+38
-9
No files matched your search
+38
-9
@@ -1545,22 +1545,51 @@ class DeliveryNote(CompanyReport):
|
||||
DeliveryNote()
|
||||
|
||||
|
||||
|
||||
class PickingList(CompanyReport):
|
||||
_name = 'stock.packing.out.picking_list'
|
||||
|
||||
def parse(self, cursor, user, report, objects, datas, context):
|
||||
if context is None:
|
||||
context = {}
|
||||
context = context.copy()
|
||||
move_obj = self.pool.get('stock.move')
|
||||
packing_out_obj = self.pool.get('stock.packing.out')
|
||||
|
||||
context['sort'] = lambda moves : sorted(
|
||||
moves,
|
||||
lambda x,y: cmp((x.from_location.rec_name, x.to_location.rec_name),
|
||||
(y.from_location.rec_name, y.to_location.rec_name))
|
||||
)
|
||||
compare_context = self.get_compare_context(
|
||||
cursor, user, report, objects, datas, context)
|
||||
|
||||
sorted_moves = {}
|
||||
for packing in objects:
|
||||
sorted_moves[packing.id] = sorted(
|
||||
packing.inventory_moves,
|
||||
lambda x,y: cmp(self.get_compare_key(x, compare_context),
|
||||
self.get_compare_key(y, compare_context))
|
||||
)
|
||||
|
||||
context['moves'] = sorted_moves
|
||||
|
||||
return super(PickingList, self).parse(cursor, user, report,
|
||||
objects, datas, context)
|
||||
|
||||
def get_compare_context(self, cursor, user, report, objects, datas, context):
|
||||
location_obj = self.pool.get('stock.location')
|
||||
from_location_ids = set()
|
||||
to_location_ids = set()
|
||||
for obj in objects:
|
||||
for move in obj.inventory_moves:
|
||||
from_location_ids.add(move.from_location.id)
|
||||
to_location_ids.add(move.to_location.id)
|
||||
|
||||
from_location_ids = location_obj.search(
|
||||
cursor, user, list(from_location_ids), context=context)
|
||||
to_location_ids = location_obj.search(
|
||||
cursor, user, list(to_location_ids), context=context)
|
||||
|
||||
return {'from_location_ids' : from_location_ids,
|
||||
'to_location_ids' : to_location_ids}
|
||||
|
||||
|
||||
def get_compare_key(self, move, compare_context):
|
||||
from_location_ids = compare_context['from_location_ids']
|
||||
to_location_ids = compare_context['to_location_ids']
|
||||
return [from_location_ids.index(move.from_location.id),
|
||||
to_location_ids.index(move.to_location.id)]
|
||||
|
||||
PickingList()
|
||||
Binary file not shown.
Reference in new issue
Block a user