From: erickson Date: Tue, 14 Apr 2009 16:35:35 +0000 (+0000) Subject: sql function to remove all traces of a PO. This is for testing/development purposes... X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=cc1e5ca9bf66cd142a481996c0ad2d92361e6b5f;p=Evergreen.git sql function to remove all traces of a PO. This is for testing/development purposes only git-svn-id: svn://svn.open-ils.org/ILS/trunk@12869 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- diff --git a/Open-ILS/src/support-scripts/test-scripts/purge_po.sql b/Open-ILS/src/support-scripts/test-scripts/purge_po.sql new file mode 100644 index 0000000000..6343b352e9 --- /dev/null +++ b/Open-ILS/src/support-scripts/test-scripts/purge_po.sql @@ -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;