[open-ils-commits] r12869 - trunk/Open-ILS/src/support-scripts/test-scripts (erickson)

svn at svn.open-ils.org svn at svn.open-ils.org
Tue Apr 14 12:35:37 EDT 2009


Author: erickson
Date: 2009-04-14 12:35:35 -0400 (Tue, 14 Apr 2009)
New Revision: 12869

Added:
   trunk/Open-ILS/src/support-scripts/test-scripts/purge_po.sql
Log:
sql function to remove all traces of a PO.  This is for testing/development purposes only

Added: trunk/Open-ILS/src/support-scripts/test-scripts/purge_po.sql
===================================================================
--- trunk/Open-ILS/src/support-scripts/test-scripts/purge_po.sql	                        (rev 0)
+++ trunk/Open-ILS/src/support-scripts/test-scripts/purge_po.sql	2009-04-14 16:35:35 UTC (rev 12869)
@@ -0,0 +1,25 @@
+-- Testing purposes only
+-- 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 $$
+DECLARE
+    li RECORD;
+BEGIN
+    FOR li IN SELECT * FROM acq.lineitem WHERE purchase_order = po_id LOOP
+
+        DELETE FROM asset.copy WHERE call_number IN (
+            SELECT id FROM asset.call_number WHERE record = li.eg_bib_id);
+        DELETE FROM asset.call_number WHERE record = li.eg_bib_id;
+        DELETE FROM biblio.record_entry WHERE id = li.eg_bib_id;
+
+        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;
+        DELETE FROM acq.lineitem_attr WHERE lineitem = li.id;
+        DELETE from acq.lineitem WHERE id = li.id;
+    END LOOP;
+
+    DELETE FROM acq.purchase_order WHERE id = po_id;
+END;
+$$ LANGUAGE plpgsql;



More information about the open-ils-commits mailing list