diff options
-rw-r--r-- | LedgerSMB/DBObject/Draft.pm | 1 | ||||
-rw-r--r-- | sql/modules/Drafts.sql | 9 | ||||
-rw-r--r-- | sql/modules/test/Draft.sql | 11 |
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) |