summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoreinhverfr <einhverfr@4979c152-3d1c-0410-bac9-87ea11338e46>2008-10-22 20:29:16 +0000
committereinhverfr <einhverfr@4979c152-3d1c-0410-bac9-87ea11338e46>2008-10-22 20:29:16 +0000
commit27b2c2caf5ea455663253189c797bbbf4ab0807f (patch)
treebb984202a6eb2cf5611f60eebc4d1f66cc441344
parent7a3fecc9998b03b6d463cea508cee7824942589b (diff)
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
-rw-r--r--LedgerSMB/DBObject/Draft.pm1
-rw-r--r--sql/modules/Drafts.sql9
-rw-r--r--sql/modules/test/Draft.sql11
3 files changed, 17 insertions, 4 deletions
diff --git a/LedgerSMB/DBObject/Draft.pm b/LedgerSMB/DBObject/Draft.pm
index b57bd238..1cfe16b4 100644
--- a/LedgerSMB/DBObject/Draft.pm
+++ b/LedgerSMB/DBObject/Draft.pm
@@ -24,6 +24,7 @@ sub delete {
$self->error($self->{_locale}->text('No ID Set'));
}
($self->{deleted}) = $self->exec_method(funcname => 'draft_delete');
+ $self->{dbh}->commit;
return $self->{deleted};
}
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)