test data addtions / requestors and circulators
authorBill Erickson <berick@esilibrary.com>
Tue, 30 Oct 2012 18:33:54 +0000 (14:33 -0400)
committerBill Erickson <berick@esilibrary.com>
Tue, 30 Oct 2012 18:33:54 +0000 (14:33 -0400)
* Make most hold requests self-placed instead of admin-placed
* 1 hold for each user is placed by a Circulator
* All circulations use a Circulator as the circ_staff

Signed-off-by: Bill Erickson <berick@esilibrary.com>
Open-ILS/tests/datasets/sql/env_create.sql
Open-ILS/tests/datasets/sql/env_destroy.sql
Open-ILS/tests/datasets/sql/transactions.sql

index 4016bd0..d27d698 100644 (file)
@@ -52,6 +52,7 @@ $$ LANGUAGE SQL;
 /** Create one circulation */
 CREATE FUNCTION evergreen.populate_circ (
     patron_id INTEGER,
+    staff_id INTEGER,
     copy_id BIGINT,
     circ_lib INTEGER,
     duration_rule TEXT,
@@ -95,7 +96,7 @@ BEGIN
         patron_id,
         copy_id,
         circ_lib, 
-        1, -- circ_staff
+        staff_id,
         duration.max_renewals,
         recurring.grace_period,
         duration.normal,
@@ -116,6 +117,7 @@ CREATE FUNCTION evergreen.populate_hold (
     hold_type TEXT,
     target BIGINT,
     patron_id INTEGER,
+    requestor INTEGER,
     pickup_lib INTEGER,
     frozen BOOLEAN,
     thawdate TIMESTAMP WITH TIME ZONE
@@ -125,7 +127,7 @@ BEGIN
         requestor, hold_type, target, usr, pickup_lib, 
             request_lib, selection_ou, frozen, thaw_date)
     VALUES (
-        1, -- requestor 
+        requestor,
         hold_type,
         target,
         patron_id,
index 873dadf..bb8fc9d 100644 (file)
@@ -6,7 +6,7 @@ DROP FUNCTION evergreen.populate_copy(INTEGER, INTEGER, TEXT, TEXT);
 DROP FUNCTION evergreen.next_copy (BIGINT);
 DROP FUNCTION evergreen.next_bib (BIGINT);
 DROP FUNCTION evergreen.populate_circ 
-    (INTEGER, BIGINT, INTEGER, TEXT, TEXT, TEXT, BOOLEAN);
+    (INTEGER, INTEGER, BIGINT, INTEGER, TEXT, TEXT, TEXT, BOOLEAN);
 DROP FUNCTION evergreen.populate_hold 
-    (TEXT, BIGINT, INTEGER, INTEGER, BOOLEAN, TIMESTAMP WITH TIME ZONE);
+    (TEXT, BIGINT, INTEGER, INTEGER, INTEGER, BOOLEAN, TIMESTAMP WITH TIME ZONE);
 
index e96fb3e..ed27bbb 100644 (file)
 
 DO $$                                                                           
     DECLARE grp INTEGER;                                                      
-    DECLARE recipient INTEGER;
+    DECLARE recipient actor.usr%ROWTYPE;
     DECLARE copy asset.copy%ROWTYPE;
     DECLARE bre biblio.record_entry%ROWTYPE;
     DECLARE user_count INTEGER;
+    DECLARE requestor INTEGER;
 BEGIN                                                                           
 
     copy := evergreen.next_copy(0);
     bre := evergreen.next_bib(0);
 
-    FOR grp IN SELECT id FROM permission.grp_tree ORDER BY id LOOP
+    FOR grp IN SELECT id FROM permission.grp_tree WHERE id > 1 ORDER BY id LOOP
 
         IF 2 IN (SELECT id FROM permission.grp_ancestors(grp)) THEN
             -- patron group
-            user_count := 20;
+            user_count := 50;
         ELSE
             user_count := 3;
         END IF;
 
-        FOR recipient IN SELECT id FROM actor.usr 
+        FOR recipient IN SELECT * FROM actor.usr 
             WHERE NOT deleted AND profile = grp 
                 ORDER BY id LIMIT user_count LOOP
 
+            -- find a suitable circulator/requestor for these transactions
+            SELECT INTO requestor id 
+                FROM actor.usr 
+                WHERE home_ou = recipient.home_ou AND
+                      profile = 5 AND -- Circulators
+                      NOT deleted
+                ORDER BY id LIMIT 1;
+
             -- regular circs --------------------------------
 
             copy := evergreen.next_copy(copy.id);
+            EXIT WHEN copy IS NULL;
             PERFORM evergreen.populate_circ(
-                recipient,
-                copy.id, copy.circ_lib,
+                recipient.id, requestor, copy.id, copy.circ_lib,
                 'default', 'default', 'default', FALSE
             );
 
             copy := evergreen.next_copy(copy.id);
+            EXIT WHEN copy IS NULL;
             PERFORM evergreen.populate_circ(
-                recipient,
-                copy.id, copy.circ_lib,
+                recipient.id, requestor, copy.id, copy.circ_lib,
                 '1_hour_2_renew', 'default', 'overdue_min', FALSE
             );
 
             copy := evergreen.next_copy(copy.id);
+            EXIT WHEN copy IS NULL;
             PERFORM evergreen.populate_circ(
-                recipient,
-                copy.id, copy.circ_lib,
+                recipient.id, requestor, copy.id, copy.circ_lib,
                 '7_days_0_renew', 'default', 'overdue_max', FALSE
             );
 
             -- overdue circs ----------------------------------
 
             copy := evergreen.next_copy(copy.id);
+            EXIT WHEN copy IS NULL;
             PERFORM evergreen.populate_circ(
-                recipient,
-                copy.id, copy.circ_lib,
+                recipient.id, requestor, copy.id, copy.circ_lib,
                 'default', 'default', 'default', TRUE
             );
 
             copy := evergreen.next_copy(copy.id);
+            EXIT WHEN copy IS NULL;
             PERFORM evergreen.populate_circ(
-                recipient,
-                copy.id, copy.circ_lib,
+                recipient.id, requestor, copy.id, copy.circ_lib,
                 '1_hour_2_renew', 'default', 'overdue_min', TRUE
             );
 
             copy := evergreen.next_copy(copy.id);
+            EXIT WHEN copy IS NULL;
             PERFORM evergreen.populate_circ(
-                recipient,
-                copy.id, copy.circ_lib,
+                recipient.id, requestor, copy.id, copy.circ_lib,
                 '7_days_0_renew', 'default', 'overdue_max', TRUE
             );
 
@@ -90,35 +99,36 @@ BEGIN
 
             -- title hold
             bre := evergreen.next_bib(bre.id);
+            EXIT WHEN bre IS NULL;
             PERFORM evergreen.populate_hold(
-                'T', bre.id, recipient,
-                (SELECT home_ou FROM actor.usr WHERE id = recipient),
-                FALSE, NULL
+                'T', bre.id, recipient.id, recipient.id,
+                recipient.home_ou, FALSE, NULL
             );
 
-            -- title hold
+            -- title hold, circulator-placed 
             bre := evergreen.next_bib(bre.id);
+            EXIT WHEN bre IS NULL;
             PERFORM evergreen.populate_hold(
-                'T', bre.id, recipient,
-                (SELECT home_ou FROM actor.usr WHERE id = recipient),
-                FALSE, NULL
+                'T', bre.id, recipient.id, requestor,
+                recipient.home_ou, FALSE, NULL
             );
 
             -- frozen title hold
             bre := evergreen.next_bib(bre.id);
+            EXIT WHEN bre IS NULL;
             PERFORM evergreen.populate_hold(
-                'T', bre.id, recipient,
-                (SELECT home_ou FROM actor.usr WHERE id = recipient),
+                'T', bre.id, recipient.id, recipient.id,
+                recipient.home_ou,
                 TRUE, NOW() + '3 months'::INTERVAL
             );
 
-            -- is this a Staff account?
+            -- Staff accounts get a copy-level hold
             IF 3 IN (SELECT id FROM permission.grp_ancestors(grp)) THEN
                 copy := evergreen.next_copy(copy.id);
+                EXIT WHEN copy IS NULL;
                 PERFORM evergreen.populate_hold(
-                    'C', copy.id, recipient,
-                    (SELECT home_ou FROM actor.usr WHERE id = recipient),
-                    FALSE, NULL
+                    'C', copy.id, recipient.id, recipient.id,
+                    recipient.home_ou, FALSE, NULL
                 );
             END IF;