test data additions / holds
authorBill Erickson <berick@esilibrary.com>
Tue, 30 Oct 2012 15:29:12 +0000 (11:29 -0400)
committerBill Erickson <berick@esilibrary.com>
Tue, 30 Oct 2012 15:29:12 +0000 (11:29 -0400)
For the first 20 users in each patron group and the first 3 users in
each staff group:

 * create 3 regular and 3 overdue circs
 * create 3 title holds, one of which is frozen
 * if the user is in a Staff group, also create one copy hold.

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 519af0a..4016bd0 100644 (file)
@@ -41,11 +41,18 @@ CREATE FUNCTION evergreen.next_copy (copy_id BIGINT) RETURNS asset.copy AS $$
     ORDER BY id LIMIT 1;
 $$ LANGUAGE SQL;
 
+/** Returns the next (by ID) non-deleted biblio.record_entry */
+CREATE FUNCTION evergreen.next_bib (bib_id BIGINT) RETURNS biblio.record_entry AS $$
+    SELECT * FROM biblio.record_entry
+    WHERE id > $1 AND NOT deleted
+    ORDER BY id LIMIT 1;
+$$ LANGUAGE SQL;
+
 
 /** Create one circulation */
 CREATE FUNCTION evergreen.populate_circ (
-    patron_barcode TEXT, 
-    copy_barcode TEXT, 
+    patron_id INTEGER,
+    copy_id BIGINT,
     circ_lib INTEGER,
     duration_rule TEXT,
     recurring_fine_rule TEXT,
@@ -85,8 +92,8 @@ BEGIN
         recurring_fine_rule, max_fine_rule, due_date )
     VALUES (
         xact_start,
-        (SELECT usr FROM actor.card WHERE barcode = patron_barcode),
-        (SELECT id FROM asset.copy WHERE barcode = copy_barcode AND NOT deleted),
+        patron_id,
+        copy_id,
         circ_lib, 
         1, -- circ_staff
         duration.max_renewals,
@@ -108,22 +115,25 @@ $$ LANGUAGE PLPGSQL;
 CREATE FUNCTION evergreen.populate_hold (
     hold_type TEXT,
     target BIGINT,
-    patron_barcode TEXT, 
-    pickup_lib INTEGER
-    -- ...
-)
-RETURNS void AS $$
+    patron_id INTEGER,
+    pickup_lib INTEGER,
+    frozen BOOLEAN,
+    thawdate TIMESTAMP WITH TIME ZONE
+RETURNS void AS $$
 BEGIN
     INSERT INTO action.hold_request (
-        requestor, hold_type, target, usr, pickup_lib, request_lib, selection_ou)
+        requestor, hold_type, target, usr, pickup_lib, 
+            request_lib, selection_ou, frozen, thaw_date)
     VALUES (
         1, -- requestor 
         hold_type,
         target,
-        (SELECT usr FROM actor.card WHERE barcode = patron_barcode),
+        patron_id,
+        pickup_lib,
         pickup_lib,
         pickup_lib,
-        pickup_lib
+        frozen,
+        thawdate
     );
 END;
 $$ LANGUAGE PLPGSQL;
index ca64cd5..873dadf 100644 (file)
@@ -4,7 +4,9 @@ DROP TABLE marcxml_import;
 DROP FUNCTION evergreen.populate_call_number(INTEGER, TEXT, TEXT);
 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 
-    (TEXT, TEXT, INTEGER, TEXT, TEXT, TEXT, BOOLEAN);
-DROP FUNCTION evergreen.populate_hold (TEXT, BIGINT, TEXT, INTEGER);
+    (INTEGER, BIGINT, INTEGER, TEXT, TEXT, TEXT, BOOLEAN);
+DROP FUNCTION evergreen.populate_hold 
+    (TEXT, BIGINT, INTEGER, INTEGER, BOOLEAN, TIMESTAMP WITH TIME ZONE);
 
index da1aa99..e96fb3e 100644 (file)
 
-
-/* NOTE: fine generator should be run after loading to produce billings */
+/**
+ * For the first (by ID) 20 users in each Patron group and the first 3 in 
+ * each Staff group:
+ *
+ * 1. create 3 regular circs w/ varying (stock) rules and 3 overdue
+ * circs. 
+ *
+ * 2. create 2 regular title holds and one frozen title hold.  If the user
+ * is in a Staff group, also create one copy-level hold.
+ *
+ */
 
 /**
- * create 3 regular circs w/ varying (stock) rules and 3 overdue
- * circs for the fisrt 2 (by ID) users in each profile group.
- * target copies start at ID 1 and progress upward by ID from
- * there, skipping deleted copies.
- * TODO: vary the rules more
+ * NOTE: The fine generator and hold targeter should be run after this is
+ * loaded to creating overdue billings and target copies for holds.
  */
+
 DO $$                                                                           
     DECLARE grp INTEGER;                                                      
     DECLARE recipient INTEGER;
     DECLARE copy asset.copy%ROWTYPE;
+    DECLARE bre biblio.record_entry%ROWTYPE;
+    DECLARE user_count 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
+
+        IF 2 IN (SELECT id FROM permission.grp_ancestors(grp)) THEN
+            -- patron group
+            user_count := 20;
+        ELSE
+            user_count := 3;
+        END IF;
 
-    FOR grp IN SELECT id FROM permission.grp_tree LOOP
         FOR recipient IN SELECT id FROM actor.usr 
-            WHERE profile = grp ORDER BY id LIMIT 2 LOOP
+            WHERE NOT deleted AND profile = grp 
+                ORDER BY id LIMIT user_count LOOP
+
+            -- regular circs --------------------------------
 
             copy := evergreen.next_copy(copy.id);
             PERFORM evergreen.populate_circ(
-                (SELECT barcode FROM actor.card WHERE usr = recipient),
-                copy.barcode, copy.circ_lib,
+                recipient,
+                copy.id, copy.circ_lib,
                 'default', 'default', 'default', FALSE
             );
 
             copy := evergreen.next_copy(copy.id);
             PERFORM evergreen.populate_circ(
-                (SELECT barcode FROM actor.card WHERE usr = recipient),
-                copy.barcode, copy.circ_lib,
+                recipient,
+                copy.id, copy.circ_lib,
                 '1_hour_2_renew', 'default', 'overdue_min', FALSE
             );
 
             copy := evergreen.next_copy(copy.id);
             PERFORM evergreen.populate_circ(
-                (SELECT barcode FROM actor.card WHERE usr = recipient),
-                copy.barcode, copy.circ_lib,
+                recipient,
+                copy.id, copy.circ_lib,
                 '7_days_0_renew', 'default', 'overdue_max', FALSE
             );
 
-            -- overdues...
+            -- overdue circs ----------------------------------
 
             copy := evergreen.next_copy(copy.id);
             PERFORM evergreen.populate_circ(
-                (SELECT barcode FROM actor.card WHERE usr = recipient),
-                copy.barcode, copy.circ_lib,
+                recipient,
+                copy.id, copy.circ_lib,
                 'default', 'default', 'default', TRUE
             );
 
             copy := evergreen.next_copy(copy.id);
             PERFORM evergreen.populate_circ(
-                (SELECT barcode FROM actor.card WHERE usr = recipient),
-                copy.barcode, copy.circ_lib,
+                recipient,
+                copy.id, copy.circ_lib,
                 '1_hour_2_renew', 'default', 'overdue_min', TRUE
             );
 
             copy := evergreen.next_copy(copy.id);
             PERFORM evergreen.populate_circ(
-                (SELECT barcode FROM actor.card WHERE usr = recipient),
-                copy.barcode, copy.circ_lib,
+                recipient,
+                copy.id, copy.circ_lib,
                 '7_days_0_renew', 'default', 'overdue_max', TRUE
             );
 
+            -- holds ------------------------------------------
+
+            -- title hold
+            bre := evergreen.next_bib(bre.id);
+            PERFORM evergreen.populate_hold(
+                'T', bre.id, recipient,
+                (SELECT home_ou FROM actor.usr WHERE id = recipient),
+                FALSE, NULL
+            );
+
+            -- title hold
+            bre := evergreen.next_bib(bre.id);
+            PERFORM evergreen.populate_hold(
+                'T', bre.id, recipient,
+                (SELECT home_ou FROM actor.usr WHERE id = recipient),
+                FALSE, NULL
+            );
+
+            -- frozen title hold
+            bre := evergreen.next_bib(bre.id);
+            PERFORM evergreen.populate_hold(
+                'T', bre.id, recipient,
+                (SELECT home_ou FROM actor.usr WHERE id = recipient),
+                TRUE, NOW() + '3 months'::INTERVAL
+            );
+
+            -- is this a Staff account?
+            IF 3 IN (SELECT id FROM permission.grp_ancestors(grp)) THEN
+                copy := evergreen.next_copy(copy.id);
+                PERFORM evergreen.populate_hold(
+                    'C', copy.id, recipient,
+                    (SELECT home_ou FROM actor.usr WHERE id = recipient),
+                    FALSE, NULL
+                );
+            END IF;
+
         END LOOP;                                                                   
     END LOOP;                                                                   
 END $$;