-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix:1802 project summary bug #1815
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
e9b0ade
test: pgtap test for missing forms
BCerki 20a2959
fix: project summary report correctly updates
BCerki 578a78c
chore: apply suggestions from code review
BCerki 5128a55
chore: migration to fix missing project summary form_data_record_id
BCerki 65f61fe
chore: apply suggestions from code review
BCerki 81f1343
chore: apply suggestions from code review
BCerki 272b800
chore: apply suggestions from code review
BCerki 2afce18
chore: fix hidden summary
BCerki 00246c4
chore: fix CI
BCerki 529079d
chore: apply suggestions from code review
BCerki 9541a2d
chore: apply suggestions from code review
BCerki 04c3f10
chore: apply suggestions from code review
BCerki File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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
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
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
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
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
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,89 @@ | ||
-- Deploy cif:functions/handle_project_summary_report_form_change_commit to pg | ||
-- requires: tables/form_change | ||
|
||
begin; | ||
|
||
create or replace function cif_private.handle_project_summary_report_form_change_commit(fc cif.form_change) | ||
returns int as $$ | ||
declare | ||
reporting_requirement_record_id int; | ||
begin | ||
-- If there is no change in the form data, return the form_change record and do not touch the associated table. | ||
if (fc.new_form_data = '{}') then | ||
return fc.form_data_record_id; | ||
end if; | ||
|
||
if (fc.change_status = 'committed') then | ||
raise exception 'Cannot commit form_change. It has already been committed.'; | ||
end if; | ||
|
||
if fc.operation = 'create' then | ||
insert into cif.reporting_requirement( | ||
project_id, | ||
report_type, | ||
report_due_date, | ||
submitted_date, | ||
comments, | ||
reporting_requirement_index, | ||
description | ||
) values ( | ||
(select form_data_record_id from cif.form_change pfc where form_data_table_name = 'project' and pfc.project_revision_id = fc.project_revision_id), | ||
(fc.new_form_data->>'reportType'), | ||
(fc.new_form_data->>'reportDueDate')::timestamptz, | ||
(fc.new_form_data->>'submittedDate')::timestamptz, | ||
(fc.new_form_data->>'comments'), | ||
(fc.new_form_data->>'reportingRequirementIndex')::int, | ||
(fc.new_form_data->>'description') | ||
) returning id into reporting_requirement_record_id; | ||
|
||
insert into cif.payment( | ||
reporting_requirement_id, | ||
gross_amount, | ||
net_amount, | ||
date_sent_to_csnr | ||
) values ( | ||
reporting_requirement_record_id, | ||
(fc.new_form_data->>'projectSummaryReportPayment')::numeric, | ||
(fc.new_form_data->>'projectSummaryReportPayment')::numeric, | ||
(fc.new_form_data->>'dateSentToCsnr')::timestamptz | ||
); | ||
|
||
update cif.form_change set form_data_record_id = reporting_requirement_record_id where id = fc.id; | ||
|
||
elsif fc.operation = 'update' then | ||
|
||
update cif.reporting_requirement rr set | ||
report_type = (fc.new_form_data->>'reportType'), | ||
report_due_date = (fc.new_form_data->>'reportDueDate')::timestamptz, | ||
submitted_date = (fc.new_form_data->>'submittedDate')::timestamptz, | ||
comments = (fc.new_form_data->>'comments'), | ||
reporting_requirement_index = (fc.new_form_data->>'reportingRequirementIndex')::int, | ||
description = (fc.new_form_data->>'description') | ||
where rr.id = fc.form_data_record_id; | ||
|
||
update cif.payment py set | ||
gross_amount = (fc.new_form_data->>'projectSummaryReportPayment')::numeric, | ||
net_amount = (fc.new_form_data->>'projectSummaryReportPayment')::numeric, | ||
date_sent_to_csnr = (fc.new_form_data->>'dateSentToCsnr')::timestamptz | ||
where py.reporting_requirement_id = fc.form_data_record_id; | ||
|
||
elsif fc.operation = 'archive' then | ||
|
||
update cif.reporting_requirement set archived_at = now() where id = fc.form_data_record_id; | ||
update cif.payment set archived_at = now() where reporting_requirement_id = fc.form_data_record_id; | ||
|
||
end if; | ||
|
||
return reporting_requirement_record_id; | ||
end; | ||
$$ language plpgsql volatile; | ||
|
||
grant execute on function cif_private.handle_project_summary_report_form_change_commit to cif_internal, cif_external, cif_admin; | ||
|
||
comment on function cif_private.handle_project_summary_report_form_change_commit | ||
is $$ | ||
The custom function used to parse project summary form_change data into table data. | ||
The data within the single form_change record is parsed into the reporting_requirement, and payment tables. | ||
$$; | ||
|
||
commit; |
27 changes: 27 additions & 0 deletions
27
schema/deploy/functions/migration_rebuild_project_summary_report_history.sql
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 @@ | ||
-- Deploy cif:migration_rebuild_project_summary_report_history to pg | ||
|
||
begin; | ||
|
||
create or replace function cif_private.migration_rebuild_project_summary_report_history() | ||
returns void as | ||
$migration$ | ||
|
||
with records as ( | ||
select fc1.id as id1,fc1.previous_form_change_id as prfid, fc2.form_data_record_id as fdrid, fc2.id as id2 | ||
from cif.form_change as fc1 | ||
join cif.form_change as fc2 | ||
on fc1.previous_form_change_id=fc2.id | ||
and fc1.json_schema_name='project_summary_report' | ||
) | ||
|
||
update cif.form_change fc set form_data_record_id= | ||
( | ||
select fdrid from records where fc.id=id1 | ||
) | ||
where form_data_record_id is null | ||
and change_status='committed' | ||
and json_schema_name='project_summary_report'; | ||
|
||
$migration$ language sql volatile; | ||
|
||
commit; |
11 changes: 11 additions & 0 deletions
11
schema/deploy/migrations/009_rebuild_project_summary_history.sql
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,11 @@ | ||
-- Deploy cif:migrations/009_rebuild_project_summary_history to pg | ||
|
||
begin; | ||
|
||
alter table cif.form_change disable trigger _100_committed_changes_are_immutable, disable trigger _set_previous_form_change_id, disable trigger _100_timestamps; | ||
|
||
select cif_private.migration_rebuild_project_summary_report_history(); | ||
|
||
alter table cif.form_change enable trigger _100_committed_changes_are_immutable, enable trigger _set_previous_form_change_id, enable trigger _100_timestamps; | ||
|
||
commit; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line was missing and that's what created the bug. This function returns
reporting_requirement_record_id
, so if we don't assign here, then the update and archive cases return null.