[open-ils-commits] r974 - in grpl: . hold_go_home (dkyle)
svn at svn.open-ils.org
svn at svn.open-ils.org
Thu Sep 2 12:06:16 EDT 2010
Author: dkyle
Date: 2010-09-02 12:06:13 -0400 (Thu, 02 Sep 2010)
New Revision: 974
Added:
grpl/hold_go_home/
grpl/hold_go_home/Holds.pm.diff
grpl/hold_go_home/hold_go_home.sql
Log:
Prevent copies from getting stuck circulating away from home library
Added: grpl/hold_go_home/Holds.pm.diff
===================================================================
--- grpl/hold_go_home/Holds.pm.diff (rev 0)
+++ grpl/hold_go_home/Holds.pm.diff 2010-09-02 16:06:13 UTC (rev 974)
@@ -0,0 +1,28 @@
+Index: Open-ILS/src/perlmods/OpenILS/Application/Circ/Holds.pm
+===================================================================
+--- Open-ILS/src/perlmods/OpenILS/Application/Circ/Holds.pm (revision 17427)
++++ Open-ILS/src/perlmods/OpenILS/Application/Circ/Holds.pm (working copy)
+@@ -1576,10 +1576,22 @@
+
+ my $fifo = $U->ou_ancestor_setting_value($user->ws_ou, 'circ.holds_fifo');
+
++ ## check interval value named circ.hold_go_home in actor.org_unit_setting and if holds are waiting
++ ## at copy's home library and if the interval has been exceeded
++ my $hold_go_home = $editor->json_query({from => ['grpl.hold_go_home',
++ $copy->id, $copy->circ_lib->id, $user->ws_ou]})->[0]->{'grpl.hold_go_home'};
++
+ # search for what should be the best holds for this copy to fulfill
+- my $best_holds = $U->storagereq(
++ my $best_holds;
++ if ($hold_go_home) { ## fill hold at home library
++ $best_holds = $U->storagereq(
++ "open-ils.storage.action.hold_request.nearest_hold.atomic",
++ $copy->circ_lib->id, $copy->id, 10, $hold_stall_interval );
++ } else {
++ $best_holds = $U->storagereq(
+ "open-ils.storage.action.hold_request.nearest_hold.atomic",
+ $user->ws_ou, $copy->id, 10, $hold_stall_interval, $fifo );
++ }
+
+ unless(@$best_holds) {
+
Added: grpl/hold_go_home/hold_go_home.sql
===================================================================
--- grpl/hold_go_home/hold_go_home.sql (rev 0)
+++ grpl/hold_go_home/hold_go_home.sql 2010-09-02 16:06:13 UTC (rev 974)
@@ -0,0 +1,41 @@
+CREATE OR REPLACE FUNCTION grpl.hold_go_home( cpid INT, home_lib INT, current_lib INT ) RETURNS INT AS $func$
+DECLARE
+ hgh_interval TEXT;
+ exceeded BOOLEAN := FALSE;
+BEGIN
+
+ -- is copy already home?
+ IF current_lib = home_lib THEN
+ RETURN 0;
+ END IF;
+
+ -- is there a go home interval for the home lib?
+ SELECT INTO hgh_interval value from actor.org_unit_ancestor_setting('circ.hold_go_home',home_lib);
+ IF FOUND THEN
+
+ -- are there holds waiting at the home lib?
+ PERFORM h.id FROM action.hold_request h JOIN action.hold_copy_map hm ON (hm.hold = h.id)
+ WHERE hm.target_copy = cpid
+ AND h.pickup_lib = home_lib
+ AND h.capture_time IS NULL
+ AND h.cancel_time IS NULL
+ AND (h.expire_time IS NULL OR h.expire_time > NOW())
+ AND h.frozen IS FALSE
+ LIMIT 1;
+ IF FOUND THEN
+
+ -- has the go home interval been exceeded for this copy?
+ SELECT INTO exceeded MAX(checkin_time) < NOW() - (hgh_interval)::INTERVAL
+ FROM action.circulation
+ WHERE target_copy = cpid AND circ_lib = home_lib
+ HAVING max(checkin_time) IS NOT NULL;
+ RETURN (exceeded)::INT;
+ END IF;
+
+ END IF;
+
+ RETURN 0;
+
+END;
+$func$ LANGUAGE plpgsql;
+
More information about the open-ils-commits
mailing list