provide option to leave lineitem_details when purging PO if the li points to a picklist
authorerickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Wed, 15 Apr 2009 16:09:30 +0000 (16:09 +0000)
committererickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Wed, 15 Apr 2009 16:09:30 +0000 (16:09 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/trunk@12882 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/src/support-scripts/test-scripts/purge_po.sql

index 8dced97..0aeb0aa 100644 (file)
@@ -2,7 +2,7 @@
 -- Removes all traces of a purchase order, including the PO, lineitems, 
 -- lineitem_details, bibs, copies, callnumbers, and debits
 
-CREATE OR REPLACE FUNCTION acq.purge_po (po_id INT) RETURNS VOID AS $$
+CREATE OR REPLACE FUNCTION acq.purge_po (po_id INT, purge_items BOOLEAN) RETURNS VOID AS $$
 DECLARE
     li RECORD;
 BEGIN
@@ -15,11 +15,17 @@ BEGIN
 
         DELETE FROM acq.fund_debit WHERE id in (
             SELECT fund_debit FROM acq.lineitem_detail WHERE lineitem = li.id);
-        DELETE FROM acq.lineitem_detail WHERE lineitem = li.id;
+
         IF li.picklist IS NULL THEN
+            IF purge_items THEN
+                DELETE FROM acq.lineitem_detail WHERE lineitem = li.id;
+            ELSE
+                UPDATE acq.lineitem_detail SET eg_copy_id = NULL WHERE lineitem = li.id;
+            END IF;
             DELETE FROM acq.lineitem_attr WHERE lineitem = li.id;
             DELETE from acq.lineitem WHERE id = li.id;
         ELSE
+            DELETE FROM acq.lineitem_detail WHERE lineitem = li.id;
             UPDATE acq.lineitem SET purchase_order = NULL, eg_bib_id = NULL, state = 'new' WHERE id = li.id;
         END IF;
     END LOOP;