Bug 27863: Use the /libraries route when AllowHoldsPolicyOverride is set

This patch makes the dropdown for changing the pickup location for
existing holds use the GET /libraries route instead of GET
/holds/:hold_id/pikcup_locations if the configuration allows the
override.

Terminology:
- Pickup location, means a library that is marked as valid pickup
  location on its configuration.

To test:
1. Have the circ rules set so 'Hold pickup library match' is set to
   'Item's home library' or 'Any'. The goal is to be able to
   differentiate when all libraries are returned, from the case only
   'valid pickup locations' are returned. The easiest one is 'Item's
   home library'.
2. Set AllowHoldsPolicyOverride
3. Pick a patron from a library that is not a valid pickup location and
   an item that belongs to a library that doesn't match any of the valid
   ones.
=> SUCCESS: Notice Koha allows you to choose any library (because of the
        syspref)
4. Place the hold.
5. Now check on the holds list for the bib, if you can use the dropdown
   to change the pickup location for the hold
=> SUCCESS: You can, sort of
=> FAIL: It doesn't show/search all pickup locations. It only shows the
        valid ones, even though we should be able to override it.
6. Apply this patch
7. Restart all just in case, and reload the holds page for the bib
8. Repeat 5
=> SUCCESS: You are presented all pickup locations!
9. Sign off :-D

Signed-off-by: Andrew Fuerste-Henry <andrew@bywatersolutions.com>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
This commit is contained in:
Tomás Cohen Arazi 2021-03-05 15:17:56 -03:00 committed by Jonathan Druart
parent f17d3dd62c
commit fce91d2bb0

View file

@ -1164,13 +1164,17 @@
this_dropdown.select2({ this_dropdown.select2({
allowClear: false, allowClear: false,
ajax: { ajax: {
[%- IF Koha.Preference('AllowHoldPolicyOverride') -%]
url: '/api/v1/libraries',
[%- ELSE -%]
url: '/api/v1/holds/' + encodeURIComponent(hold_id) + '/pickup_locations', url: '/api/v1/holds/' + encodeURIComponent(hold_id) + '/pickup_locations',
[%- END -%]
delay: 300, // wait 300 milliseconds before triggering the request delay: 300, // wait 300 milliseconds before triggering the request
dataType: 'json', dataType: 'json',
data: function (params) { data: function (params) {
var search_term = (params.term === undefined) ? '' : params.term; var search_term = (params.term === undefined) ? '' : params.term;
var query = { var query = {
"q": JSON.stringify({"name":{"-like":search_term+'%'}}), "q": JSON.stringify({"name":{"-like":search_term+'%'},"pickup_location":1}),
"_order_by": "name" "_order_by": "name"
}; };
return query; return query;