Skip to content

Commit

Permalink
acquisitions: sort lines in order
Browse files Browse the repository at this point in the history
Line sorting is now done on the PID to keep the same order as the command.

* Closes #2653.

Co-Authored-by: Bertrand Zuchuat <[email protected]>
  • Loading branch information
Garfield-fr committed Oct 2, 2023
1 parent 601a15e commit 8187995
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions rero_ils/modules/acquisition/acq_orders/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,16 +350,26 @@ 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).
"""

def preserve_order(query):
"""Keep results in order.
:param: query: the es query.
:return the es query.
"""
return query.params(preserve_order=True) \
.sort({'pid': {"order": "asc"}})

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 preserve_order(query)
else:
return get_objects(AcqOrderLine, query)
return get_objects(AcqOrderLine, preserve_order(query))

def get_order_provisional_total_amount(self):
"""Get provisional total amount of this order."""
Expand Down

0 comments on commit 8187995

Please sign in to comment.