diff --git a/rero_ils/modules/acquisition/acq_orders/api.py b/rero_ils/modules/acquisition/acq_orders/api.py index 629a70cc8d..ebc9017003 100644 --- a/rero_ils/modules/acquisition/acq_orders/api.py +++ b/rero_ils/modules/acquisition/acq_orders/api.py @@ -350,16 +350,22 @@ def get_order_lines(self, output=None, includes=None): :param includes: a list of statuses to include order lines. :return a generator of related order lines (or length). """ - query = AcqOrderLinesSearch().filter('term', acq_order__pid=self.pid) + query = AcqOrderLinesSearch()\ + .filter('term', acq_order__pid=self.pid) if includes: query = query.filter('terms', status=includes) if output == 'count': return query.count() elif output == 'query': - return query + return query \ + .params(preserve_order=True) \ + .sort({'pid': {"order": "asc"}}) else: - return get_objects(AcqOrderLine, query) + return get_objects(AcqOrderLine, query + .params(preserve_order=True) + .sort({'pid': {"order": "asc"}}) + ) def get_order_provisional_total_amount(self): """Get provisional total amount of this order."""