Skip to content

Commit

Permalink
libraries: allow multiple pickup locations
Browse files Browse the repository at this point in the history
* Closes rero#1341

Co-Authored-by: Aly Badr <aly.badr@rero.ch>
  • Loading branch information
Aly Badr committed Feb 1, 2021
1 parent 45722af commit 082e90a
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 27 deletions.
16 changes: 9 additions & 7 deletions rero_ils/modules/documents/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,20 +303,22 @@ def item_library_pickup_locations(item):
if 'restrict_pickup_to' in location:
# Get all pickup locations as Location objects and append it to the
# location item (removing possible None values)
pickup_locations = list(filter(None, [
pickup_locations = [
Location.get_record_by_pid(loc_pid)
for loc_pid in location.restrict_pickup_to
]))
]
else:
org = Organisation.get_record_by_pid(location.organisation_pid)
# Get the pickup location from each library of the item organisation
# (removing possible None value)
pickup_locations = list(filter(None, [
Location.get_record_by_pid(library.get_pickup_location_pid())
for library in org.get_libraries()
]))
pickup_locations = []
for library in org.get_libraries():
for location_pid in list(library.get_pickup_locations_pids()):
pickup_locations.append(
Location.get_record_by_pid(location_pid))

return sorted(
pickup_locations,
list(filter(None, pickup_locations)),
key=lambda location: location.get('pickup_name', location.get('code'))
)

Expand Down
16 changes: 12 additions & 4 deletions rero_ils/modules/libraries/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,21 @@ def get_organisation(self):
from ..organisations.api import Organisation
return Organisation.get_record_by_pid(self.organisation_pid)

def get_pickup_location_pid(self):
"""Returns libraries first pickup location."""
results = LocationsSearch().filter(
def pickup_location_query(self):
"""Search the location index for pickup locations."""
return LocationsSearch().filter(
'term', library__pid=self.pid).filter(
'term', is_pickup=True).source(['pid']).scan()

def get_pickup_locations_pids(self):
"""Returns libraries all pickup locations pids."""
for location in self.pickup_location_query():
yield location.pid

def get_pickup_location_pid(self):
"""Returns libraries first pickup location pid."""
try:
return next(results).pid
return next(self.pickup_location_query()).pid
except StopIteration:
return None

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,22 +63,7 @@
"title": "Is pickup location",
"type": "boolean",
"default": false,
"description": "Qualify this location as a pickup location.",
"form": {
"validation": {
"validators": {
"valueAlreadyExists": {
"limitToValues": [
true
],
"filter": "'library.pid:' + model.library.pid"
}
},
"messages": {
"alreadyTakenMessage": "There is already one pickup location in this library."
}
}
}
"description": "Qualify this location as a pickup location."
},
"is_online": {
"title": "Is online location",
Expand Down

0 comments on commit 082e90a

Please sign in to comment.