From fc960413799e5da9ecc8af14bfe3560eeff362d5 Mon Sep 17 00:00:00 2001 From: Bertrand Zuchuat Date: Wed, 20 Sep 2023 14:08:49 +0200 Subject: [PATCH] acquisitions: sort lines in order Line sorting is now done on the PID to keep the same order as the command. * Closes #2653. Co-Authored-by: Bertrand Zuchuat --- rero_ils/modules/acquisition/acq_orders/api.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) 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."""