Skip to content

Commit

Permalink
fix(vouchers): use voucher before removing
Browse files Browse the repository at this point in the history
This commit switches the ordering of statements executed in the DELETE
route to use the voucher before removing it.  Previously, the voucher
was removed and then attempted to be JOINed with other tables.
Obviously, this would never work.
  • Loading branch information
jniles committed Oct 19, 2017
1 parent 96a4b73 commit 581ce95
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
14 changes: 9 additions & 5 deletions server/controllers/finance/vouchers.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ function find(options) {
filters.custom('account_id', 'v.uuid IN (SELECT DISTINCT voucher_uuid FROM voucher_item WHERE account_id = ?)');

filters.custom('invoice_uuid', REFERENCE_SQL, [options.invoice_uuid, options.invoice_uuid]);
filters.custom('cash_uuid', REFERENCE_SQL, [options.invoice_uuid, options.invoice_uuid]);
filters.custom('cash_uuid', REFERENCE_SQL, [options.cash_uuid, options.cash_uuid]);

// @TODO Support ordering query (reference support for limit)?
filters.setOrder('ORDER BY v.date DESC');
Expand Down Expand Up @@ -302,11 +302,15 @@ function safelyDeleteVoucher(guid) {

transaction
.addQuery(DELETE_TRANSACTION, binaryUuid)
.addQuery(DELETE_TRANSACTION_HISTORY, binaryUuid)
.addQuery(DELETE_VOUCHER, binaryUuid)
.addQuery(DELETE_DOCUMENT_MAP, binaryUuid)

// note that we have to delete the toggles before removing the voucher
// wholesale.
.addQuery(TOGGLE_INVOICE_REVERSAL, binaryUuid)
.addQuery(TOGGLE_CASH_REVERSAL, binaryUuid);
.addQuery(TOGGLE_CASH_REVERSAL, binaryUuid)

.addQuery(DELETE_VOUCHER, binaryUuid)
.addQuery(DELETE_TRANSACTION_HISTORY, binaryUuid)
.addQuery(DELETE_DOCUMENT_MAP, binaryUuid);

return transaction.execute();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ describe('Check Inter-Registry Links', () => {
it('Checks the link between Cash Registry -> Voucher Registry', () => {
helpers.navigate('#!/payments');
filters.resetFilters();
const row = new GridRow('CP.TPA.1');
const row = new GridRow('CP.TPA.3');
row.dropdown().click();
row.goToVoucher().click();

Expand Down

0 comments on commit 581ce95

Please sign in to comment.