From 27b2c2caf5ea455663253189c797bbbf4ab0807f Mon Sep 17 00:00:00 2001 From: einhverfr Date: Wed, 22 Oct 2008 20:29:16 +0000 Subject: Corrected missing commit on draft deletion Corrected inadequate cleanup on draft deletion git-svn-id: https://ledger-smb.svn.sourceforge.net/svnroot/ledger-smb/trunk@2377 4979c152-3d1c-0410-bac9-87ea11338e46 --- sql/modules/Drafts.sql | 9 +++++++-- sql/modules/test/Draft.sql | 11 +++++++++-- 2 files changed, 16 insertions(+), 4 deletions(-) (limited to 'sql') diff --git a/sql/modules/Drafts.sql b/sql/modules/Drafts.sql index e5a7b940..850fae4e 100644 --- a/sql/modules/Drafts.sql +++ b/sql/modules/Drafts.sql @@ -91,7 +91,9 @@ $$ declare t_table text; begin - SELECT table_name into t_table FROM transactions where id = in_id; + DELETE FROM acc_trans WHERE trans_id = in_id; + SELECT lower(table_name) into t_table FROM transactions where id = in_id; + IF t_table = 'ar' THEN DELETE FROM ar WHERE id = in_id AND approved IS FALSE; ELSIF t_table = 'ap' THEN @@ -101,7 +103,10 @@ begin ELSE raise exception 'Invalid table % in draft_delete for transaction %', t_table, in_id; END IF; - RETURN FOUND; + IF NOT FOUND THEN + RAISE EXCEPTION 'Invalid transaction id %', in_id; + END IF; + RETURN TRUE; END; $$ LANGUAGE PLPGSQL SECURITY DEFINER; diff --git a/sql/modules/test/Draft.sql b/sql/modules/test/Draft.sql index a5f799c6..53db5349 100644 --- a/sql/modules/test/Draft.sql +++ b/sql/modules/test/Draft.sql @@ -63,8 +63,6 @@ SELECT '"AR" search successful', count(*) = 1 FROM draft__search('AR', NULL, NULL, NULL, NULL, NULL) WHERE reference = '_TEST AR'; -SELECT * -FROM draft__search('gl', NULL, NULL, NULL, NULL, NULL); INSERT INTO test_result(test_name, success) SELECT '"gl" search successful', count(*) = 1 FROM draft__search('gl', NULL, NULL, NULL, NULL, NULL) @@ -75,6 +73,15 @@ SELECT '"GL" search successful', count(*) = 1 FROM draft__search('GL', NULL, NULL, NULL, NULL, NULL) WHERE reference = '_TEST GL'; +INSERT INTO test_result(test_name, success) +SELECT 'gl draft deletion', draft_delete(currval('id')::int); + +INSERT INTO test_result(test_name, success) +SELECT 'gl table cleanup', count(*) = 0 from gl where id = currval('id'); + +INSERT INTO test_result(test_name, success) +SELECT 'acc_trans table cleanup', count(*) = 0 from acc_trans where trans_id = currval('id'); + SELECT * FROM test_result; SELECT (select count(*) from test_result where success is true) -- cgit v1.2.3