diff --git a/packing.py b/packing.py index 178f968bad..1852828732 100644 --- a/packing.py +++ b/packing.py @@ -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() diff --git a/picking_list.odt b/picking_list.odt index f081d8941e..58d8ca582e 100644 Binary files a/picking_list.odt and b/picking_list.odt differ