Skip to content
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

NOI COALESCE on update for fee_paid_date #1115

Merged
merged 4 commits into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions bin/migrate-oats-data/noi/notice_of_intent_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ def _noi_insert_query(number_of_rows_to_insert):
VALUES{nois_to_insert}
ON CONFLICT (file_number) DO UPDATE SET
file_number = EXCLUDED.file_number,
applicant = EXCLUDED.applicant,
region_code = EXCLUDED.region_code,
local_government_uuid = EXCLUDED.local_government_uuid,
applicant = COALESCE((CASE WHEN EXCLUDED.applicant = 'Unknown' THEN alcs.notice_of_intent.applicant ELSE EXCLUDED.applicant END), EXCLUDED.applicant),
region_code = COALESCE(EXCLUDED.region_code, alcs.notice_of_intent.region_code),
local_government_uuid = COALESCE(EXCLUDED.local_government_uuid, alcs.notice_of_intent.local_government_uuid),
audit_created_by = EXCLUDED.audit_created_by,
type_code = EXCLUDED.type_code
"""
Original file line number Diff line number Diff line change
Expand Up @@ -102,18 +102,18 @@ def _update_fee_fields_records(conn, batch_size, cursor, rows):
def _get_update_query_from_oats_alr_applications_fields():
query = """
UPDATE alcs.notice_of_intent
SET fee_paid_date = %(fee_received_date)s,
fee_waived = %(fee_waived_ind)s,
fee_amount = %(applied_fee_amt)s,
fee_split_with_lg = %(split_fee_with_local_gov_ind)s,
date_submitted_to_alc = %(submitted_to_alc_date)s,
staff_observations = %(staff_comment_observations)s,
alr_area = %(component_area)s,
ag_cap_source = %(capability_source_code)s,
ag_cap_map = %(agri_cap_map)s,
ag_cap_consultant = %(agri_cap_consultant)s,
ag_cap = %(agri_capability_code)s,
legacy_id=%(legacy_application_nbr)s,
SET fee_paid_date = COALESCE(%(fee_received_date)s, fee_paid_date),
fee_waived = COALESCE(%(fee_waived_ind)s, fee_waived),
fee_amount = COALESCE(%(applied_fee_amt)s, fee_amount),
fee_split_with_lg = COALESCE(%(split_fee_with_local_gov_ind)s, fee_split_with_lg),
date_submitted_to_alc = COALESCE(%(submitted_to_alc_date)s, date_submitted_to_alc),
staff_observations = COALESCE(%(staff_comment_observations)s, staff_observations),
alr_area = COALESCE(%(component_area)s, alr_area),
ag_cap_source = COALESCE(%(capability_source_code)s, ag_cap_source),
ag_cap_map = COALESCE(%(agri_cap_map)s, ag_cap_map),
ag_cap_consultant = COALESCE(%(agri_cap_consultant)s, ag_cap_consultant),
ag_cap = COALESCE(%(agri_capability_code)s, ag_cap),
legacy_id= COALESCE(%(legacy_application_nbr)s, legacy_id),
source = 'APPLICANT'
WHERE
alcs.notice_of_intent.file_number = %(alr_application_id)s::TEXT;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
-- this query checks that OATS NULL does not override fee_paid_date if it has value in ALCS
WITH noi_with_one_component AS (
SELECT oaac.alr_application_id
FROM oats.oats_alr_appl_components oaac
JOIN oats.oats_alr_applications oaa ON oaa.alr_application_id = oaac.alr_application_id
WHERE oaa.application_class_code = 'NOI'
GROUP BY oaac.alr_application_id
HAVING count(oaac.alr_application_id) < 2 -- ignore notice of intents wit multiple components
)
SELECT noi.fee_paid_date AT TIME ZONE 'UTC',
oaa.fee_received_date,
oats_noi.alr_application_id
FROM alcs.notice_of_intent noi
JOIN noi_with_one_component oats_noi ON oats_noi.alr_application_id::TEXT = noi.file_number
JOIN oats.oats_alr_applications oaa ON oaa.alr_application_id = oats_noi.alr_application_id
WHERE oaa.fee_received_date IS NULL
AND noi.fee_paid_date IS NOT NULL;