[open-ils-commits] r15498 - in trunk/Open-ILS: examples src/perlmods/OpenILS/Application/Acq src/sql/Pg src/sql/Pg/upgrade (miker)

svn at svn.open-ils.org svn at svn.open-ils.org
Wed Feb 10 16:46:04 EST 2010


Author: miker
Date: 2010-02-10 16:45:59 -0500 (Wed, 10 Feb 2010)
New Revision: 15498

Added:
   trunk/Open-ILS/src/sql/Pg/upgrade/0159.schema.acq.patron_requests.sql
Modified:
   trunk/Open-ILS/examples/fm_IDL.xml
   trunk/Open-ILS/src/perlmods/OpenILS/Application/Acq/Order.pm
   trunk/Open-ILS/src/sql/Pg/002.schema.config.sql
   trunk/Open-ILS/src/sql/Pg/200.schema.acq.sql
Log:
backend to support collection of patron purchase request data; create holds, when requested, from purchase requests at acqli->bre vivication time

Modified: trunk/Open-ILS/examples/fm_IDL.xml
===================================================================
--- trunk/Open-ILS/examples/fm_IDL.xml	2010-02-10 21:38:43 UTC (rev 15497)
+++ trunk/Open-ILS/examples/fm_IDL.xml	2010-02-10 21:45:59 UTC (rev 15498)
@@ -4309,6 +4309,75 @@
             </actions>
         </permacrud>
 	</class>
+
+	<class id="aurt" controller="open-ils.cstore open-ils.reporter-store open-ils.pcrud" oils_obj:fieldmapper="acq::user_request_type" oils_persist:tablename="acq.user_request_type" reporter:label="User Purchase Request Type">
+		<fields oils_persist:primary="id">
+			<field reporter:label="ID" name="id" reporter:datatype="id" reporter:selector='label'/>
+			<field reporter:label="Type Label" name="label" reporter:datatype="text" oils_persist:i18n="true" />
+		</fields>
+		<links/>
+        <permacrud xmlns="http://open-ils.org/spec/opensrf/IDL/permacrud/v1">
+            <actions>
+                <create permission="ADMIN_USER_REQUEST_TYPE" global_required="true"/>
+                <retrieve/>
+                <update permission="ADMIN_USER_REQUEST_TYPE" global_required="true"/>
+                <delete permission="ADMIN_USER_REQUEST_TYPE" global_required="true"/>
+            </actions>
+        </permacrud>
+	</class>
+
+	<class id="aur" controller="open-ils.cstore open-ils.reporter-store open-ils.pcrud" oils_obj:fieldmapper="acq::user_request" oils_persist:tablename="acq.user_request" reporter:label="User Purchase Request">
+		<fields oils_persist:primary="id">
+			<field reporter:label="ID" name="id" reporter:datatype="id" reporter:selector='label'/>
+			<field reporter:label="User" name="usr" reporter:datatype="link" />
+			<field reporter:label="Request Type" name="request_type" reporter:datatype="link" />
+			<field reporter:label="Place Hold" name="hold" reporter:datatype="bool" />
+			<field reporter:label="Pickup Library" name="pickup_lib" reporter:datatype="link" />
+			<field reporter:label="Holdable Formats" name="holdable_formats" reporter:datatype="text" />
+			<field reporter:label="Phone Notify" name="phone_notify" reporter:datatype="text" />
+			<field reporter:label="Email Notify" name="email_notify" reporter:datatype="bool" />
+			<field reporter:label="PO Line Item" name="lineitem" reporter:datatype="link" />
+			<field reporter:label="Bib Record" name="eg_bib" reporter:datatype="link" />
+			<field reporter:label="Request Date/Time" name="request_date" reporter:datatype="timestamp" />
+			<field reporter:label="Need Before Date/Time" name="request_date" reporter:datatype="timestamp" />
+			<field reporter:label="Max Acceptable Fee" name="max_fee" reporter:datatype="text" />
+			<field reporter:label="ISxN" name="isxn" reporter:datatype="text" />
+			<field reporter:label="Title" name="title" reporter:datatype="text" />
+			<field reporter:label="Volume" name="volume" reporter:datatype="text" />
+			<field reporter:label="Author" name="author" reporter:datatype="text" />
+			<field reporter:label="Article Title" name="article_title" reporter:datatype="text" />
+			<field reporter:label="Article Pages" name="article_pages" reporter:datatype="text" />
+			<field reporter:label="Publisher" name="publisher" reporter:datatype="text" />
+			<field reporter:label="Publication Location" name="location" reporter:datatype="text" />
+			<field reporter:label="Publication Date" name="pubdate" reporter:datatype="text" />
+			<field reporter:label="Mentioned In" name="mentioned" reporter:datatype="text" />
+			<field reporter:label="Other Info" name="other_info" reporter:datatype="text" />
+		</fields>
+		<links>
+			<link field="usr" reltype="has_a" key="id" map="" class="au"/>
+			<link field="pickup_lib" reltype="has_a" key="id" map="" class="aou"/>
+			<link field="lineitem" reltype="has_a" key="id" map="" class="acqli"/>
+			<link field="eg_bib" reltype="has_a" key="id" map="" class="bre"/>
+			<link field="request_type" reltype="has_a" key="id" map="" class="aurt"/>
+		</links>
+        <permacrud xmlns="http://open-ils.org/spec/opensrf/IDL/permacrud/v1">
+            <actions>
+                <create permission="user_request.create">
+                    <context link="usr" field="home_ou"/>
+				</create>
+                <retrieve permission="user_request.view">
+                    <context link="usr" field="home_ou"/>
+				</retrieve>
+                <update permission="user_request.update">
+                    <context link="usr" field="home_ou"/>
+				</update>
+                <delete permission="user_request.delete">
+                    <context link="usr" field="home_ou"/>
+				</delete>
+            </actions>
+        </permacrud>
+	</class>
+
 	<class id="acqct" controller="open-ils.cstore open-ils.reporter-store open-ils.pcrud" oils_obj:fieldmapper="acq::currency_type" oils_persist:tablename="acq.currency_type" reporter:label="Currency Type">
 		<fields oils_persist:primary="code">
 			<field reporter:label="Currency Code" name="code" reporter:datatype="text" reporter:selector='label'/>

Modified: trunk/Open-ILS/src/perlmods/OpenILS/Application/Acq/Order.pm
===================================================================
--- trunk/Open-ILS/src/perlmods/OpenILS/Application/Acq/Order.pm	2010-02-10 21:38:43 UTC (rev 15497)
+++ trunk/Open-ILS/src/perlmods/OpenILS/Application/Acq/Order.pm	2010-02-10 21:45:59 UTC (rev 15498)
@@ -197,7 +197,56 @@
     $li->edit_time('now');
     $li->editor($mgr->editor->requestor->id);
     $mgr->add_li;
-    return $li if $mgr->editor->update_acq_lineitem($li);
+    my $success = $mgr->editor->update_acq_lineitem($li);
+
+    if ($success) { # check for requests, create holds
+        my $requests = $mgr->editor->search_acq_user_request(
+            { lineitem => $li->id,
+              '-or' =>
+                [ { need_before => {'>' => 'now'} },
+                  { need_before => undef }
+                ]
+            }
+        );
+
+        for my $request ( @$requests ) {
+
+            $request->eg_bib( $li->eg_bib_id );
+            $mgr->editor->update_acq_user_request( $request );
+
+            next unless ($U->is_true( $request->hold ));
+
+            my $hold = Fieldmapper::action::hold_request->new;
+            $hold->usr( $request->usr );
+            $hold->requestor( $request->usr );
+            $hold->request_time( $request->request_date );
+            $hold->pickup_lib( $request->pickup_lib );
+            $hold->request_lib( $request->pickup_lib );
+            $hold->selection_ou( $request->pickup_lib );
+            $hold->phone_notify( $request->phone_notify );
+            $hold->email_notify( $request->email_notify );
+            $hold->expire_time( $request->need_before );
+
+            if ($request->holdable_formats) {
+                my $mrm = $mgr->editor->search_metabib_metarecord_source_map( { source => $li->eg_bib_id } )->[0];
+                if ($mrm) {
+                    $hold->hold_type( 'M' );
+                    $hold->holdable_formats( $request->holdable_formats );
+                    $hold->target( $mrm->metarecord );
+                }
+            }
+
+            if (!$hold->target) {
+                $hold->hold_type( 'T' );
+                $hold->target( $li->eg_bib_id );
+            }
+
+            $mgr->editor->create_actor_hold_request( $hold );
+        }
+
+        return $li;
+    }
+
     return undef;
 }
 

Modified: trunk/Open-ILS/src/sql/Pg/002.schema.config.sql
===================================================================
--- trunk/Open-ILS/src/sql/Pg/002.schema.config.sql	2010-02-10 21:38:43 UTC (rev 15497)
+++ trunk/Open-ILS/src/sql/Pg/002.schema.config.sql	2010-02-10 21:45:59 UTC (rev 15498)
@@ -51,7 +51,7 @@
     install_date    TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW()
 );
 
-INSERT INTO config.upgrade_log (version) VALUES ('0158'); -- atz
+INSERT INTO config.upgrade_log (version) VALUES ('0159'); -- miker
 
 CREATE TABLE config.bib_source (
 	id		SERIAL	PRIMARY KEY,

Modified: trunk/Open-ILS/src/sql/Pg/200.schema.acq.sql
===================================================================
--- trunk/Open-ILS/src/sql/Pg/200.schema.acq.sql	2010-02-10 21:38:43 UTC (rev 15497)
+++ trunk/Open-ILS/src/sql/Pg/200.schema.acq.sql	2010-02-10 21:45:59 UTC (rev 15498)
@@ -688,6 +688,51 @@
 CREATE INDEX acq_attribution_credit_idx
     ON acq.debit_attribution( funding_source_credit );
 
+
+-- Patron requests
+CREATE TABLE acq.user_request_type (
+    id      SERIAL  PRIMARY KEY,
+    label   TEXT    NOT NULL UNIQUE -- i18n-ize
+);
+
+INSERT INTO acq.user_request_type (id,label) VALUES (1, oils_i18n_gettext('1', 'Books', 'aurt', 'label'));
+INSERT INTO acq.user_request_type (id,label) VALUES (2, oils_i18n_gettext('2', 'Journal/Magazine & Newspaper Articles', 'aurt', 'label'));
+INSERT INTO acq.user_request_type (id,label) VALUES (3, oils_i18n_gettext('3', 'Audiobooks', 'aurt', 'label'));
+INSERT INTO acq.user_request_type (id,label) VALUES (4, oils_i18n_gettext('4', 'Music', 'aurt', 'label'));
+INSERT INTO acq.user_request_type (id,label) VALUES (5, oils_i18n_gettext('5', 'DVDs', 'aurt', 'label'));
+
+SELECT SETVAL('acq.user_request_type_id_seq'::TEXT, 6);
+
+CREATE TABLE acq.user_request (
+    id                  SERIAL  PRIMARY KEY,
+    usr                 INT     NOT NULL REFERENCES actor.usr (id), -- requesting user
+    hold                BOOL    NOT NULL DEFAULT TRUE,
+
+    pickup_lib          INT     NOT NULL REFERENCES actor.org_unit (id), -- pickup lib
+    holdable_formats    TEXT,           -- nullable, for use in hold creation
+    phone_notify        TEXT,
+    email_notify        BOOL    NOT NULL DEFAULT TRUE,
+    lineitem            INT     REFERENCES acq.lineitem (id) ON DELETE CASCADE,
+    eg_bib              BIGINT  REFERENCES biblio.record_entry (id) ON DELETE CASCADE,
+    request_date        TIMESTAMPTZ NOT NULL DEFAULT NOW(), -- when they requested it
+    need_before         TIMESTAMPTZ,    -- don't create holds after this
+    max_fee             TEXT,
+  
+    request_type        INT     NOT NULL REFERENCES acq.user_request_type (id),
+    isxn                TEXT,
+    title               TEXT,
+    volume              TEXT,
+    author              TEXT,
+    article_title       TEXT,
+    article_pages       TEXT,
+    publisher           TEXT,
+    location            TEXT,
+    pubdate             TEXT,
+    mentioned           TEXT,
+    other_info          TEXT
+);
+
+
 -- Functions
 
 CREATE TYPE acq.flat_lineitem_holding_subfield AS (lineitem int, holding int, subfield text, data text);

Added: trunk/Open-ILS/src/sql/Pg/upgrade/0159.schema.acq.patron_requests.sql
===================================================================
--- trunk/Open-ILS/src/sql/Pg/upgrade/0159.schema.acq.patron_requests.sql	                        (rev 0)
+++ trunk/Open-ILS/src/sql/Pg/upgrade/0159.schema.acq.patron_requests.sql	2010-02-10 21:45:59 UTC (rev 15498)
@@ -0,0 +1,49 @@
+BEGIN;
+
+INSERT INTO config.upgrade_log (version) VALUES ('0159');  -- miker
+
+CREATE TABLE acq.user_request_type (
+    id      SERIAL  PRIMARY KEY,
+    label   TEXT    NOT NULL UNIQUE -- i18n-ize
+);
+
+INSERT INTO acq.user_request_type (id,label) VALUES (1, oils_i18n_gettext('1', 'Books', 'aurt', 'label'));
+INSERT INTO acq.user_request_type (id,label) VALUES (2, oils_i18n_gettext('2', 'Journal/Magazine & Newspaper Articles', 'aurt', 'label'));
+INSERT INTO acq.user_request_type (id,label) VALUES (3, oils_i18n_gettext('3', 'Audiobooks', 'aurt', 'label'));
+INSERT INTO acq.user_request_type (id,label) VALUES (4, oils_i18n_gettext('4', 'Music', 'aurt', 'label'));
+INSERT INTO acq.user_request_type (id,label) VALUES (5, oils_i18n_gettext('5', 'DVDs', 'aurt', 'label'));
+
+SELECT SETVAL('acq.user_request_type_id_seq'::TEXT, 6);
+
+CREATE TABLE acq.user_request (
+    id                  SERIAL  PRIMARY KEY,
+    usr                 INT     NOT NULL REFERENCES actor.usr (id), -- requesting user
+    hold                BOOL    NOT NULL DEFAULT TRUE,
+
+    pickup_lib          INT     NOT NULL REFERENCES actor.org_unit (id), -- pickup lib
+    holdable_formats    TEXT,           -- nullable, for use in hold creation
+    phone_notify        TEXT,
+    email_notify        BOOL    NOT NULL DEFAULT TRUE,
+    lineitem            INT     REFERENCES acq.lineitem (id) ON DELETE CASCADE,
+    eg_bib              BIGINT  REFERENCES biblio.record_entry (id) ON DELETE CASCADE,
+    request_date        TIMESTAMPTZ NOT NULL DEFAULT NOW(), -- when they requested it
+    need_before         TIMESTAMPTZ,    -- don't create holds after this
+    max_fee             TEXT,
+
+    request_type        INT     NOT NULL REFERENCES acq.user_request_type (id), 
+    isxn                TEXT,
+    title               TEXT,
+    volume              TEXT,
+    author              TEXT,
+    article_title       TEXT,
+    article_pages       TEXT,
+    publisher           TEXT,
+    location            TEXT,
+    pubdate             TEXT,
+    mentioned           TEXT,
+    other_info          TEXT
+);
+
+
+COMMIT;
+



More information about the open-ils-commits mailing list