Create new table acq.cancel_reason.
authorscottmk <scottmk@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Thu, 4 Mar 2010 21:31:55 +0000 (21:31 +0000)
committerscottmk <scottmk@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Thu, 4 Mar 2010 21:31:55 +0000 (21:31 +0000)
Create new columns pointing to it in acq.purchase_order and
acq.lineitem.

See KCLS ticket #3015.

M    Open-ILS/src/sql/Pg/200.schema.acq.sql
M    Open-ILS/src/sql/Pg/002.schema.config.sql
A    Open-ILS/src/sql/Pg/upgrade/0177.schema.cancel_reason.sql
M    Open-ILS/examples/fm_IDL.xml

git-svn-id: svn://svn.open-ils.org/ILS/trunk@15704 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/examples/fm_IDL.xml
Open-ILS/src/sql/Pg/002.schema.config.sql
Open-ILS/src/sql/Pg/200.schema.acq.sql
Open-ILS/src/sql/Pg/upgrade/0177.schema.cancel_reason.sql [new file with mode: 0644]

index 2dcc6ef..ceeeb91 100644 (file)
@@ -5087,6 +5087,20 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
                </links>
        </class>
 
+       <class id="acqcr" controller="open-ils.cstore open-ils.pcrud" oils_obj:fieldmapper="acq::cancel_reason" oils_persist:tablename="acq.cancel_reason" reporter:label="Cancel Reason">
+               <fields oils_persist:primary="id" oils_persist:sequence="acq.cancel_reason_id_seq">
+                       <field reporter:label="ID" name="id" reporter:datatype="id"/>
+                       <field reporter:label="Using Library" name="org_unit" reporter:datatype="org_unit"/>
+                       <field reporter:label="Label" name="label" reporter:datatype="text"/>
+                       <field reporter:label="Description" name="description" reporter:datatype="text"/>
+               </fields>
+               <links>
+                       <link field="org_unit" reltype="has_a" key="id" map="" class="aou"/>
+               </links>
+               <permacrud xmlns="http://open-ils.org/spec/opensrf/IDL/permacrud/v1">
+               </permacrud>
+       </class>
+
        <class id="acqpo" controller="open-ils.cstore open-ils.pcrud" oils_obj:fieldmapper="acq::purchase_order" oils_persist:tablename="acq.purchase_order" reporter:label="Purchase Order">
                <fields oils_persist:primary="id" oils_persist:sequence="acq.purchase_order_id_seq">
                        <field reporter:label="Purchase Order ID" name="id" reporter:datatype="id" />
@@ -5100,6 +5114,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
                        <field reporter:label="Editor" name="editor" reporter:datatype="link" />
                        <field reporter:label="Order Date" name="order_date" reporter:datatype="timestamp" />
                        <field reporter:label="Name" name="name" reporter:datatype="text" />
+                       <field reporter:label="Cancel Reason" name="cancel_reason" reporter:datatype="link" />
                        <field reporter:label="Line Items" name="lineitems" oils_persist:virtual="true" reporter:datatype="link" />
                        <field reporter:label="Notes" name="notes" oils_persist:virtual="true" reporter:datatype="link" />
                        <field reporter:label="Line Item Count" name="lineitem_count" oils_persist:virtual="true" reporter:datatype="link" />
@@ -5115,6 +5130,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
                        <link field="lineitems" reltype="has_many" key="purchase_order" map="" class="jub"/>
                        <link field="notes" reltype="has_many" key="purchase_order" map="" class="acqpon"/>
                        <link field="ordering_agency" reltype="has_a" key="id" map="" class="aou"/>
+                       <link field="cancel_reason" reltype="has_a" key="id" map="" class="acqcr"/>
                </links>
                <permacrud xmlns="http://open-ils.org/spec/opensrf/IDL/permacrud/v1">
                        <actions>
@@ -5190,6 +5206,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
                        <field reporter:label="Creator" name="creator" reporter:datatype="link" />
                        <field reporter:label="Editor" name="editor" reporter:datatype="link" />
                        <field reporter:label="Claim Interval" name="claim_interval" reporter:datatype="interval" />
+                       <field reporter:label="Cancel Reason" name="cancel_reason" reporter:datatype="link" />
                        <field reporter:label="Item Count" name="item_count" oils_persist:virtual="true" reporter:datatype="int" />
                        <field reporter:label="Descriptive Attributes" name="attributes" oils_persist:virtual="true" reporter:datatype="link" />
                        <field reporter:label="Line Item Details" name="lineitem_details" oils_persist:virtual="true" reporter:datatype="link" />
@@ -5206,6 +5223,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
                        <link field="attributes" reltype="has_many" key="lineitem" map="" class="acqlia"/>
                        <link field="lineitem_details" reltype="has_many" key="lineitem" map="" class="acqlid"/>
                        <link field="lineitem_notes" reltype="has_many" key="lineitem" map="" class="acqlin"/>
+                       <link field="cancel_reason" reltype="has_a" key="id" map="" class="acqcr"/>
                </links>
        </class>
 
index c42e644..b752b15 100644 (file)
@@ -51,7 +51,7 @@ CREATE TABLE config.upgrade_log (
     install_date    TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW()
 );
 
-INSERT INTO config.upgrade_log (version) VALUES ('0176'); -- Scott McKellar
+INSERT INTO config.upgrade_log (version) VALUES ('0177'); -- Scott McKellar
 
 CREATE TABLE config.bib_source (
        id              SERIAL  PRIMARY KEY,
index 6fbcf59..44a3529 100644 (file)
@@ -322,6 +322,21 @@ CREATE INDEX acq_picklist_owner_idx   ON acq.picklist ( owner );
 CREATE INDEX acq_picklist_creator_idx ON acq.picklist ( creator );
 CREATE INDEX acq_picklist_editor_idx  ON acq.picklist ( editor );
 
+CREATE TABLE acq.cancel_reason (
+        id            SERIAL            PRIMARY KEY,
+        org_unit      INTEGER           NOT NULL REFERENCES actor.org_unit( id )
+                                        DEFERRABLE INITIALLY DEFERRED,
+        label         TEXT              NOT NULL,
+        description   TEXT              NOT NULL,
+        CONSTRAINT acq_cancel_reason_one_per_org_unit UNIQUE( org_unit, label )
+);
+
+-- Reserve ids 1-999 for stock reasons
+-- Reserve ids 1000-1999 for EDI reasons
+-- 2000+ are available for staff to create
+
+SELECT SETVAL('acq.cancel_reason_id_seq'::TEXT, 2000);
+
 CREATE TABLE acq.purchase_order (
        id              SERIAL                          PRIMARY KEY,
        owner           INT                             NOT NULL REFERENCES actor.usr (id) DEFERRABLE INITIALLY DEFERRED,
@@ -333,7 +348,9 @@ CREATE TABLE acq.purchase_order (
        provider        INT                             NOT NULL REFERENCES acq.provider (id) DEFERRABLE INITIALLY DEFERRED,
        state                   TEXT                                    NOT NULL DEFAULT 'new',
        order_date              TIMESTAMP WITH TIME ZONE,
-       name                    TEXT                                    NOT NULL
+       name                    TEXT                                    NOT NULL,
+       cancel_reason   INT                     REFERENCES acq.cancel_reason( id )
+                                            DEFERRABLE INITIALLY DEFERRED
 );
 CREATE INDEX po_owner_idx ON acq.purchase_order (owner);
 CREATE INDEX po_provider_idx ON acq.purchase_order (provider);
@@ -435,6 +452,8 @@ CREATE TABLE acq.lineitem (
        source_label        TEXT,
        state               TEXT                        NOT NULL DEFAULT 'new',
        claim_interval      INTERVAL,
+       cancel_reason       INT                         REFERENCES acq.cancel_reason( id )
+                                                    DEFERRABLE INITIALLY DEFERRED,
     CONSTRAINT picklist_or_po CHECK (picklist IS NOT NULL OR purchase_order IS NOT NULL)
 );
 CREATE INDEX li_po_idx ON acq.lineitem (purchase_order);
diff --git a/Open-ILS/src/sql/Pg/upgrade/0177.schema.cancel_reason.sql b/Open-ILS/src/sql/Pg/upgrade/0177.schema.cancel_reason.sql
new file mode 100644 (file)
index 0000000..2c21ae7
--- /dev/null
@@ -0,0 +1,28 @@
+BEGIN;
+
+INSERT INTO config.upgrade_log (version) VALUES ('0177'); -- Scott McKellar
+
+CREATE TABLE acq.cancel_reason (
+       id            SERIAL            PRIMARY KEY,
+       org_unit      INTEGER           NOT NULL REFERENCES actor.org_unit( id )
+                                       DEFERRABLE INITIALLY DEFERRED,
+       label         TEXT              NOT NULL,
+       description   TEXT              NOT NULL,
+       CONSTRAINT acq_cancel_reason_one_per_org_unit UNIQUE( org_unit, label )
+);
+
+-- Reserve ids 1-999 for stock reasons
+-- Reserve ids 1000-1999 for EDI reasons
+-- 2000+ are available for staff to create
+
+SELECT SETVAL('acq.cancel_reason_id_seq'::TEXT, 2000);
+
+ALTER TABLE acq.purchase_order
+       ADD COLUMN cancel_reason        INT REFERENCES acq.cancel_reason( id )
+                                           DEFERRABLE INITIALLY DEFERRED;
+
+ALTER TABLE acq.lineitem
+       ADD COLUMN cancel_reason        INT REFERENCES acq.cancel_reason( id )
+                                           DEFERRABLE INITIALLY DEFERRED;
+
+COMMIT;