LP#1895052: Allow pickup lib to control stalling
authorMike Rylander <mrylander@gmail.com>
Wed, 23 Jun 2021 16:28:39 +0000 (12:28 -0400)
committerGalen Charlton <gmc@equinoxOLI.org>
Fri, 13 Aug 2021 22:02:21 +0000 (18:02 -0400)
This commit provides a new YAOUS that, when set, takes precedence over
the current "soft stalling interval" YAOUS.  Instead of limiting capture
to items owned by the pickup library (or the directly targeted item)
based on the context of scanned item's circulating library, it instead
restricts op capture to holds that have a pickup library of the scanning
location when the hold is younger that the interval, base on the context
of the pickup location of each hold.

tl;dr: It allows the pickup library to control op capture stalling
rather than the circulating library of an arbitrary scanned item.

Signed-off-by: Mike Rylander <mrylander@gmail.com>
Signed-off-by: Jason Stephenson <jason@sigio.com>
Signed-off-by: John Amundson <jamundson@cwmars.org>
Signed-off-by: Galen Charlton <gmc@equinoxOLI.org>
Open-ILS/src/perlmods/lib/OpenILS/Application/Storage/Publisher/action.pm
Open-ILS/src/sql/Pg/950.data.seed-values.sql
Open-ILS/src/sql/Pg/upgrade/XXXX.data.stalling-YAOUS.sql [new file with mode: 0644]

index 94ea9cd..b921e6c 100644 (file)
@@ -577,11 +577,34 @@ sub nearest_hold {
                 ON ( au.id = ausp.usr AND ( ausp.stop_date IS NULL OR ausp.stop_date > NOW() ) )
             LEFT JOIN config.standing_penalty csp
                 ON ( csp.id = ausp.standing_penalty AND csp.block_list LIKE '%CAPTURE%' )
+            LEFT JOIN LATERAL (
+                SELECT OILS_JSON_TO_TEXT(value) AS age
+                  FROM actor.org_unit_ancestor_setting('circ.pickup_hold_stalling.soft', h.pickup_lib)
+            ) AS pickup_stall ON TRUE
             $addl_join
           WHERE hm.target_copy = ?
-            /* not protected, or protection is expired or we're in range */
+
+                /* not protected, or protection is expired or we're in range */
             AND (cahp.id IS NULL OR (AGE(NOW(),acp.active_date) >= cahp.age OR cahp.prox >= hm.proximity))
-            AND (AGE(NOW(),h.request_time) >= CAST(? AS INTERVAL) OR hm.proximity = 0 OR p.prox = 0)
+
+                /* the complicated hold stalling logic */
+            AND CASE WHEN pickup_stall.age IS NOT NULL AND h.request_time + pickup_stall.age::INTERVAL > NOW()
+                        THEN -- pickup lib oriented stalling is configured for this hold's pickup lib, and it's "too young"
+                            CASE WHEN p.prox = 0
+                                THEN TRUE -- Cheap test: allow it when scanning at pickup lib
+                                ELSE action.hold_copy_calculated_proximity( -- have to call this because we don't know if pprox will be included
+                                        h.id,
+                                        acp.id,
+                                        p.from_org -- equals scan lib, see first JOIN above
+                                     ) <= 0 -- else more expensive test for scan-lib calc prox
+                            END
+                    ELSE ( h.request_time + CAST(? AS INTERVAL) < NOW()
+                           OR hm.proximity <= 0
+                           OR p.prox = 0
+                         ) -- not "too young" OR copy-owner/pickup prox OR scan-lib/pickup prox
+                END
+
+                /* simple, quick tests */
             AND h.capture_time IS NULL
             AND h.cancel_time IS NULL
             AND (h.expire_time IS NULL OR h.expire_time > NOW())
index f3eba61..397cfa3 100644 (file)
@@ -3598,7 +3598,16 @@ INSERT into config.org_unit_setting_type
         'Soft stalling interval',
         'coust', 'label'),
     oils_i18n_gettext('circ.hold_stalling.soft',
-        'How long to wait before allowing remote items to be opportunistically captured for a hold.  Example "5 days"',
+        $$How long to wait before allowing opportunistic capture of holds with a pickup library other than the context item's circulating library$$, -- ' vim
+        'coust', 'description'),
+    'interval', null)
+
+,( 'circ.pickup_hold_stalling.soft', 'holds',
+    oils_i18n_gettext('circ.pickup_hold_stalling.soft',
+        'Pickup Library Soft stalling interval',
+        'coust', 'label'),
+    oils_i18n_gettext('circ.pickup_hold_stalling.soft',
+        'When set for the pickup library, this specifies that only items scanned at the pickup library can be opportunistically captured for this time period.  Example "5 days".  This setting takes precedence over "Soft stalling interval" (circ.hold_stalling.soft).',
         'coust', 'description'),
     'interval', null)
 
diff --git a/Open-ILS/src/sql/Pg/upgrade/XXXX.data.stalling-YAOUS.sql b/Open-ILS/src/sql/Pg/upgrade/XXXX.data.stalling-YAOUS.sql
new file mode 100644 (file)
index 0000000..4ddcafc
--- /dev/null
@@ -0,0 +1,20 @@
+BEGIN;
+
+SELECT evergreen.upgrade_deps_block_check('XXXX', :eg_version);
+
+UPDATE config.org_unit_setting_type
+  SET description = $$How long to wait before allowing opportunistic capture of holds with a pickup library other than the context item's circulating library$$ -- ' vim
+  WHERE name = 'circ.hold_stalling.soft';
+
+INSERT into config.org_unit_setting_type
+( name, grp, label, description, datatype, fm_class ) VALUES
+( 'circ.pickup_hold_stalling.soft',
+  'holds',
+  'Pickup Library Soft stalling interval',
+  'When set for the pickup library, this specifies that only items scanned at the pickup library can be opportunistically captured for this time period.  Example "5 days".  This setting takes precedence over "Soft stalling interval" (circ.hold_stalling.soft).',
+  'interval',
+  null
+);
+
+COMMIT;
+