Skip to content

Commit

Permalink
libraries: allow multiple pickup locations
Browse files Browse the repository at this point in the history
Co-Authored-by: Aly Badr <aly.badr@rero.ch>
  • Loading branch information
Aly Badr committed Jan 6, 2021
1 parent c6342df commit 95dd017
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 24 deletions.
11 changes: 7 additions & 4 deletions rero_ils/modules/documents/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,10 +303,13 @@ def item_library_pickup_locations(item):
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()):
location = Location.get_record_by_pid(location_pid)
pickup_locations.append(location)
pickup_locations = list(filter(None, pickup_locations))

return sorted(
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 95dd017

Please sign in to comment.