-
-
Notifications
You must be signed in to change notification settings - Fork 150
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7764 from ehuelsmann/fix/master/missing-aa-trx-wo…
…rkflows Add missing workflows for AR/AP transactions
- Loading branch information
Showing
2 changed files
with
28 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
|
||
|
||
WITH aa_transactions AS ( | ||
UPDATE transactions trx | ||
SET workflow_id = nextval('workflow_seq') | ||
WHERE workflow_id IS NULL | ||
AND (EXISTS (select 1 from ar where trx.id = ar.id and not ar.invoice) | ||
OR EXISTS (select 1 from ap where trx.id = ap.id and not ap.invoice)) | ||
RETURNING * | ||
), | ||
new_workflow AS ( | ||
INSERT INTO workflow | ||
SELECT workflow_id, 'AR/AP' as type, | ||
CASE WHEN approved THEN 'POSTED' ELSE 'SAVED' END as state, | ||
now() as last_update | ||
FROM aa_transactions | ||
RETURNING workflow_id, state, last_update | ||
) | ||
INSERT INTO workflow_history | ||
SELECT nextval('workflow_History_seq') as workflow_hist_id, | ||
workflow_id, | ||
'<upgrade>' as action, | ||
'History item created for existing transaction during schema upgrade' as description, | ||
state, | ||
'<upgrade>' as workflow_user, | ||
last_update as history_date | ||
FROM new_workflow; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters