From 9bf6f45c2429c12071ee91662a8a1752c42f3970 Mon Sep 17 00:00:00 2001 From: Hakan Date: Tue, 26 Nov 2024 17:37:40 +0300 Subject: [PATCH 01/15] add sql query for loaders;location,office, partner, intervention --- .../apps/mart/data/models/intervention.py | 242 ++++++++++++++++++ .../apps/mart/data/models/location.py | 28 ++ .../apps/mart/data/models/partner.py | 192 ++++++++++++++ .../apps/mart/data/models/reports_office.py | 10 + 4 files changed, 472 insertions(+) diff --git a/src/etools_datamart/apps/mart/data/models/intervention.py b/src/etools_datamart/apps/mart/data/models/intervention.py index b17ee42ba..0e5e81711 100644 --- a/src/etools_datamart/apps/mart/data/models/intervention.py +++ b/src/etools_datamart/apps/mart/data/models/intervention.py @@ -220,6 +220,248 @@ class Options: class InterventionLoader(NestedLocationLoaderMixin, EtoolsLoader): + """ + -- TODO: Pick only the required fields + SET search_path = public; + SELECT "users_country"."id", + "users_country"."schema_name", + "users_country"."name", + "users_country"."business_area_code", + "users_country"."initial_zoom", + "users_country"."latitude", + "users_country"."longitude", + "users_country"."country_short_code", + "users_country"."vision_sync_enabled", + "users_country"."vision_last_synced", + "users_country"."local_currency_id", + "users_country"."long_name", + "users_country"."iso3_code", + "users_country"."custom_dashboards" FROM + "users_country" WHERE "users_country"."schema_name" = '##COUNTRY##' LIMIT 21 + + -- TODO: Pick only the required fields + SET search_path = public, albania; + SELECT '##COUNTRY##' AS __schema, + "partners_intervention"."id", + "partners_intervention"."created", + "partners_intervention"."modified", + "partners_intervention"."document_type", + "partners_intervention"."number", + "partners_intervention"."title", + "partners_intervention"."status", + "partners_intervention"."start", "partners_intervention"."end", "partners_intervention"."submission_date", + "partners_intervention"."submission_date_prc", "partners_intervention"."review_date_prc", + "partners_intervention"."prc_review_document", + "partners_intervention"."signed_by_unicef_date", + "partners_intervention"."signed_by_partner_date", + "partners_intervention"."population_focus", + "partners_intervention"."agreement_id", + "partners_intervention"."unicef_signatory_id", + "partners_intervention"."signed_pd_document", + "partners_intervention"."country_programme_id", + "partners_intervention"."contingency_pd", + "partners_intervention"."metadata", + "partners_intervention"."in_amendment", + "partners_intervention"."reference_number_year", + "partners_intervention"."activation_letter", + "partners_intervention"."termination_doc", + "partners_intervention"."cfei_number", + "partners_intervention"."budget_owner_id", + "partners_intervention"."context", + "partners_intervention"."date_sent_to_partner", + "partners_intervention"."equity_narrative", + "partners_intervention"."equity_rating", + "partners_intervention"."gender_narrative", + "partners_intervention"."gender_rating", + "partners_intervention"."hq_support_cost", + "partners_intervention"."implementation_strategy", + "partners_intervention"."ip_program_contribution", + "partners_intervention"."partner_accepted", + "partners_intervention"."sustainability_narrative", + "partners_intervention"."sustainability_rating", + "partners_intervention"."unicef_accepted", + "partners_intervention"."unicef_court", + "partners_intervention"."unicef_review_type", + "partners_intervention"."humanitarian_flag", + "partners_intervention"."capacity_development", + "partners_intervention"."other_info", + "partners_intervention"."other_partners_involved", + "partners_intervention"."technical_guidance", + "partners_intervention"."cash_transfer_modalities", + "partners_intervention"."cancel_justification", + "partners_intervention"."date_partnership_review_performed", + "partners_intervention"."accepted_on_behalf_of_partner", + "partners_intervention"."activation_protocol", + "partners_intervention"."confidential", + "partners_intervention"."has_activities_involving_children", + "partners_intervention"."has_data_processing_agreement", + "partners_intervention"."has_special_conditions_for_construction", + "partners_intervention"."final_review_approved", + "partners_intervention"."other_details", + "partners_intervention"."partner_authorized_officer_signatory_id", + + "partners_agreement"."id", + "partners_agreement"."created", + "partners_agreement"."modified", + "partners_agreement"."start", + "partners_agreement"."end", + "partners_agreement"."agreement_type", + "partners_agreement"."agreement_number", + "partners_agreement"."attached_agreement", + "partners_agreement"."signed_by_unicef_date", + "partners_agreement"."signed_by_partner_date", + "partners_agreement"."partner_id", + "partners_agreement"."signed_by_id", + "partners_agreement"."status", + "partners_agreement"."country_programme_id", + "partners_agreement"."reference_number_year", + "partners_agreement"."special_conditions_pca", + "partners_agreement"."terms_acknowledged_by_id", + "partners_agreement"."partner_manager_id", + + "partners_partnerorganization"."id", + "partners_partnerorganization"."description", + "partners_partnerorganization"."address", + "partners_partnerorganization"."email", + "partners_partnerorganization"."phone_number", + "partners_partnerorganization"."alternate_id", + "partners_partnerorganization"."alternate_name", + "partners_partnerorganization"."rating", + "partners_partnerorganization"."core_values_assessment_date", + "partners_partnerorganization"."vision_synced", + "partners_partnerorganization"."type_of_assessment", + "partners_partnerorganization"."last_assessment_date", + "partners_partnerorganization"."hidden", + "partners_partnerorganization"."deleted_flag", + "partners_partnerorganization"."total_ct_cp", + "partners_partnerorganization"."total_ct_cy", + "partners_partnerorganization"."blocked", + "partners_partnerorganization"."city", + "partners_partnerorganization"."country", + "partners_partnerorganization"."postal_code", + "partners_partnerorganization"."shared_with", + "partners_partnerorganization"."street_address", + "partners_partnerorganization"."hact_values", + "partners_partnerorganization"."created", + "partners_partnerorganization"."modified", + "partners_partnerorganization"."net_ct_cy", + "partners_partnerorganization"."reported_cy", + "partners_partnerorganization"."total_ct_ytd", + "partners_partnerorganization"."basis_for_risk_rating", + "partners_partnerorganization"."manually_blocked", + "partners_partnerorganization"."outstanding_dct_amount_6_to_9_months_usd", + "partners_partnerorganization"."outstanding_dct_amount_more_than_9_months_usd", + "partners_partnerorganization"."highest_risk_rating_name", + "partners_partnerorganization"."highest_risk_rating_type", + "partners_partnerorganization"."psea_assessment_date", + "partners_partnerorganization"."sea_risk_rating_name", + "partners_partnerorganization"."lead_office_id", + "partners_partnerorganization"."lead_section_id", + "partners_partnerorganization"."organization_id", + + "organizations_organization"."id", + "organizations_organization"."created", + "organizations_organization"."modified", + "organizations_organization"."name", + "organizations_organization"."vendor_number", + "organizations_organization"."organization_type", + "organizations_organization"."cso_type", + "organizations_organization"."short_name", + "organizations_organization"."other", + "organizations_organization"."parent_id", + + "auth_user"."id", + "auth_user"."password", + "auth_user"."last_login", + "auth_user"."is_superuser", + "auth_user"."username", + "auth_user"."first_name", + "auth_user"."last_name", + "auth_user"."email", + "auth_user"."is_staff", + "auth_user"."is_active", + "auth_user"."date_joined", + "auth_user"."middle_name", + "auth_user"."created", + "auth_user"."modified", + "auth_user"."preferences", + + "reports_countryprogramme"."id", + "reports_countryprogramme"."name", + "reports_countryprogramme"."wbs", + "reports_countryprogramme"."from_date", + "reports_countryprogramme"."to_date", + "reports_countryprogramme"."invalid", + + "partners_interventionbudget"."id", + "partners_interventionbudget"."partner_contribution", + "partners_interventionbudget"."unicef_cash", + "partners_interventionbudget"."in_kind_amount", + "partners_interventionbudget"."partner_contribution_local", + "partners_interventionbudget"."unicef_cash_local", + "partners_interventionbudget"."in_kind_amount_local", + "partners_interventionbudget"."total", + "partners_interventionbudget"."intervention_id", + "partners_interventionbudget"."total_local", + "partners_interventionbudget"."currency", + + "partners_interventionamendment"."id", + "partners_interventionamendment"."signed_date", + "partners_interventionamendment"."intervention_id", + "partners_interventionamendment"."types", + + "funds_fundsreservationheader"."id", + "funds_fundsreservationheader"."fr_number", + "funds_fundsreservationheader"."intervention_id", + "funds_fundsreservationheader"."outstanding_amt_local", + + "partners_interventionattachment"."id", + "partners_interventionattachment"."intervention_id", + "partners_interventionattachment"."type_id", + + "partners_interventionplannedvisits"."id", + "partners_interventionplannedvisits"."intervention_id", + "partners_interventionplannedvisits"."programmatic_q1", + "partners_interventionplannedvisits"."programmatic_q2", + "partners_interventionplannedvisits"."programmatic_q3", + + "partners_intervention_unicef_focal_points"."id", + "partners_intervention_unicef_focal_points"."user_id", + + "partners_intervention_partner_focal_points"."id", + "partners_intervention_partner_focal_points"."intervention_id", + "partners_intervention_partner_focal_points"."user_id", + + "partners_intervention_flat_locations"."id", + "partners_intervention_flat_locations"."intervention_id", + "partners_intervention_flat_locations"."location_id", + + "locations_location"."id", + "locations_location"."name", + "locations_location"."latitude", + "locations_location"."longitude", + "locations_location"."p_code", + "locations_location"."admin_level", + "locations_location"."admin_level_name" + FROM "partners_intervention" + INNER JOIN "partners_agreement" ON ("partners_intervention"."agreement_id" = "partners_agreement"."id") + INNER JOIN "partners_partnerorganization" ON ("partners_agreement"."partner_id" = "partners_partnerorganization"."id") + INNER JOIN "organizations_organization" ON ("partners_partnerorganization"."organization_id" = "organizations_organization"."id") + LEFT OUTER JOIN "auth_user" ON ("partners_intervention"."unicef_signatory_id" = "auth_user"."id") + LEFT OUTER JOIN "reports_countryprogramme" ON ("partners_intervention"."country_programme_id" = "reports_countryprogramme"."id") + INNER JOIN "partners_interventionbudget" ON("partners_interventionbudget"."intervention_id" = "partners_intervention"."id") + INNER JOIN "partners_interventionamendment" ON ("partners_interventionamendment"."intervention_id" = "partners_intervention"."id" ) + INNER JOIN "funds_fundsreservationheader" ON ("funds_fundsreservationheader"."intervention_id" = "partners_intervention"."id" ) + INNER JOIN "partners_interventionattachment" ON ("partners_interventionattachment"."intervention_id" = "partners_intervention"."id" ) + INNER JOIN "partners_interventionplannedvisits" ON ("partners_interventionplannedvisits"."intervention_id" = "partners_intervention"."id" ) + INNER JOIN "partners_intervention_unicef_focal_points" ON ("partners_intervention_unicef_focal_points"."intervention_id" = "partners_intervention"."id" ) + INNER JOIN "partners_intervention_partner_focal_points" ON ("partners_intervention_partner_focal_points" ."intervention_id" = "partners_intervention"."id" ) + INNER JOIN "partners_intervention_flat_locations" ON ("partners_intervention_flat_locations"."intervention_id" = "partners_intervention"."id" ) + INNER JOIN "locations_location" ON ("locations_location"."id" = "partners_intervention_flat_locations"."location_id" ) + ORDER BY "partners_intervention"."id" ASC + + """ + location_m2m_field = "flat_locations" def get_queryset(self): diff --git a/src/etools_datamart/apps/mart/data/models/location.py b/src/etools_datamart/apps/mart/data/models/location.py index 1c0a96d98..9001cc489 100644 --- a/src/etools_datamart/apps/mart/data/models/location.py +++ b/src/etools_datamart/apps/mart/data/models/location.py @@ -11,6 +11,34 @@ from ..loader import EtoolsLoader +""" +-- Set country; +SET search_path = public, +-- Get count for paging calculation; +SELECT COUNT(*) AS "__count" FROM "locations_location" +-- Paged fetch; +SELECT '' AS __schema, + "locations_location"."id", + "locations_location"."name", + "locations_location"."latitude", + "locations_location"."longitude", + "locations_location"."p_code", + "locations_location"."point", + "locations_location"."geom", + "locations_location"."level", + "locations_location"."lft", + "locations_location"."parent_id", + "locations_location"."rght", + "locations_location"."tree_id", + "locations_location"."created", + "locations_location"."modified", + "locations_location"."is_active", + "locations_location"."admin_level", + "locations_location"."admin_level_name" +FROM "locations_location" +ORDER BY "locations_location"."id" ASC +""" + class LocationQuerySet(DataMartQuerySet): def batch_update_centroid(self): diff --git a/src/etools_datamart/apps/mart/data/models/partner.py b/src/etools_datamart/apps/mart/data/models/partner.py index 5baf8d686..6b28d2927 100644 --- a/src/etools_datamart/apps/mart/data/models/partner.py +++ b/src/etools_datamart/apps/mart/data/models/partner.py @@ -11,6 +11,198 @@ from etools_datamart.apps.sources.etools.enrichment.consts import PartnerOrganizationConst, PartnerType, TravelType from etools_datamart.apps.sources.etools.models import PartnersPartnerorganization, ReportsOffice, T2FTravelactivity +""" +SET search_path = public,; + +SELECT '' AS __schema, + "partners_partnerorganization"."id", + "partners_partnerorganization"."description", + "partners_partnerorganization"."address", + "partners_partnerorganization"."email", + "partners_partnerorganization"."phone_number", + "partners_partnerorganization"."alternate_id", + "partners_partnerorganization"."alternate_name", + "partners_partnerorganization"."rating", + "partners_partnerorganization"."core_values_assessment_date", + "partners_partnerorganization"."vision_synced", + "partners_partnerorganization"."type_of_assessment", + "partners_partnerorganization"."last_assessment_date", + "partners_partnerorganization"."hidden", + "partners_partnerorganization"."deleted_flag", + "partners_partnerorganization"."total_ct_cp", + "partners_partnerorganization"."total_ct_cy", + "partners_partnerorganization"."blocked", + "partners_partnerorganization"."city", + "partners_partnerorganization"."country", + "partners_partnerorganization"."postal_code", + "partners_partnerorganization"."shared_with", + "partners_partnerorganization"."street_address", + "partners_partnerorganization"."hact_values", + "partners_partnerorganization"."created", + "partners_partnerorganization"."modified", + "partners_partnerorganization"."net_ct_cy", + "partners_partnerorganization"."reported_cy", + "partners_partnerorganization"."total_ct_ytd", + "partners_partnerorganization"."basis_for_risk_rating", + "partners_partnerorganization"."manually_blocked", + "partners_partnerorganization"."outstanding_dct_amount_6_to_9_months_usd", + "partners_partnerorganization"."outstanding_dct_amount_more_than_9_months_usd", + "partners_partnerorganization"."highest_risk_rating_name", + "partners_partnerorganization"."highest_risk_rating_type", + "partners_partnerorganization"."psea_assessment_date", + "partners_partnerorganization"."sea_risk_rating_name", + "partners_partnerorganization"."lead_office_id", + "partners_partnerorganization"."lead_section_id", + "partners_partnerorganization"."organization_id", + '' AS __schema, + "reports_office"."id", + "reports_office"."name", + '' AS __schema, + "reports_sector"."id", + "reports_sector"."name", + "reports_sector"."description", + "reports_sector"."alternate_id", + "reports_sector"."alternate_name", + "reports_sector"."dashboard", + "reports_sector"."color", + "reports_sector"."created", + "reports_sector"."modified", + "reports_sector"."active", "organizations_organization"."id", + "organizations_organization"."created", + "organizations_organization"."modified", + "organizations_organization"."name", + "organizations_organization"."vendor_number", + "organizations_organization"."organization_type", + "organizations_organization"."cso_type", + "organizations_organization"."short_name", + "organizations_organization"."other", + "organizations_organization"."parent_id", + '' AS __schema, + "partners_plannedengagement"."id", + "partners_plannedengagement"."created", + "partners_plannedengagement"."modified", + "partners_plannedengagement"."spot_check_planned_q1", + "partners_plannedengagement"."spot_check_planned_q2", + "partners_plannedengagement"."spot_check_planned_q3", + "partners_plannedengagement"."spot_check_planned_q4", + "partners_plannedengagement"."scheduled_audit", + "partners_plannedengagement"."special_audit", + "partners_plannedengagement"."spot_check_follow_up", + "partners_plannedengagement"."partner_id" + FROM "partners_partnerorganization" + LEFT OUTER JOIN "reports_office" ON ("partners_partnerorganization"."lead_office_id" = "reports_office"."id") + LEFT OUTER JOIN "reports_sector" ON ("partners_partnerorganization"."lead_section_id" = "reports_sector"."id") + INNER JOIN "organizations_organization" ON ("partners_partnerorganization"."organization_id" = "organizations_organization"."id") + LEFT OUTER JOIN "partners_plannedengagement" ON ("partners_partnerorganization"."id" = "partners_plannedengagement"."partner_id") + ORDER BY "partners_partnerorganization"."id" ASC LIMIT OFFSET + + + SELECT '##COUNTRY##' AS __schema, + "t2f_travelactivity"."id", + "t2f_travelactivity"."travel_type", + "t2f_travelactivity"."date", + "t2f_travelactivity"."partner_id", + "t2f_travelactivity"."partnership_id", + "t2f_travelactivity"."primary_traveler_id", + "t2f_travelactivity"."result_id" + FROM "t2f_travelactivity" + INNER JOIN "t2f_travelactivity_travels" ON ("t2f_travelactivity"."id" = "t2f_travelactivity_travels"."travelactivity_id") + INNER JOIN "t2f_travel" ON ("t2f_travelactivity_travels"."travel_id" = "t2f_travel"."id") + WHERE ("t2f_travelactivity"."date" IS NOT NULL AND "t2f_travelactivity"."travel_type" = 'Programmatic Visit' + AND "t2f_travel"."status" = 'completed' AND "t2f_travel"."traveler_id" = ("t2f_travelactivity"."primary_traveler_id") + AND "t2f_travelactivity"."partner_id" IN (805, 806, 807, 808, 809, 810, 811, 812, 813, 814, 815, 816, 817, 818, 819, 820, 821, 822, 823, 824, 825, 826, 827, 828, 829, 830, 831, 832, 833, 835, 836, 837, 838, 839, 840, 841, 842, 843, 844, 845, 846, 847, 848, 849, 850, 851, 852, 853, 854, 855, 856, 857, 858, 859, 860, 861, 862, 863, 864, 865, 866, 867, 868, 869, 870, 871, 872, 873, 874, 875, 876, 877, 878, 879, 880, 881, 882, 883, 884, 885, 886, 887, 888, 889, 890, 891, 892, 893, 894, 895, 896, 897, 898, 899, 900, 901, 902, 903, 904, 905, 906, 907, 908, 909, 910, 911, 912, 913, 914, 915, 916, 917, 918, 919, 920, 921, 922, 923, 924, 925, 926, 927, 928, 929, 930, 931, 932, 933, 934, 935, 936, 937, 938, 939, 940, 941, 942, 943, 944, 945, 946, 947, 948, 949, 950, 951, 952, 953, 954, 955, 956, 957, 958, 963, 964, 965, 966, 967, 968, 969, 970, 971, 972, 973, 974, 975, 976, 977, 978, 979, 980, 981, 982, 983, 984, 985, 986, 987, 988, 1021, 1022, 1023, 1024, 1025, 1026, 1027, 1028, 1029, 1030, 1031, 1064, 1065, 1066, 1067, 1068, 1069, 1071, 1072, 1073, 1074, 1076, 1077, 1078, 1079, 1080, 1081, 1082, 1083, 1084, 1085, 1086, 1087, 1088, 1089, 1090, 1091, 1092, 1093, 1094, 1095, 1096, 1097, 1098, 1099, 1100, 1101, 1102, 1103, 1104, 1105, 1106, 1107, 1108, 1109, 1110, 1111, 1112, 1113, 1114, 1115, 1116, 1117, 1118, 1119, 1120, 1121, 1122, 1123, 1124, 1125, 1126, 1127, 1128, 1129, 1130, 1131, 1132, 1133, 1134, 1135, 1136, 1138, 1139, 1140, 1143, 1144, 1145, 1146, 1148, 1150, 1151, 1152, 1153, 1154, 1155, 1156, 1157, 1158, 1159, 1160, 1161, 1162, 1163, 1164, 1165, 1166, 1167, 1168, 1169, 1170, 1171, 1172, 1173, 1174, 1175, 1176, 1177, 1178, 1179, 1180, 1181, 1182, 1183, 1184, 1185, 1186, 1187, 1188, 1189, 1190, 1191, 1192, 1193, 1194, 1195, 1196, 1197, 1198, 1199, 1200, 1201, 1202, 1203, 1204, 1205, 1206, 1207, 1208, 1209, 1210, 1211, 1212, 1213, 1214, 1215, 1216, 1217, 1218, 1219, 1220, 1221, 1222)) ORDER BY "t2f_travelactivity"."date" DESC + + + SELECT COUNT(*) AS "__count" FROM "partners_partnerorganization + + SET search_path = public,##COUNTRY##; + SELECT 'afghanistan' AS __schema, + "partners_partnerorganization"."id", + "partners_partnerorganization"."description", + "partners_partnerorganization"."address", + "partners_partnerorganization"."email", + "partners_partnerorganization"."phone_number", + "partners_partnerorganization"."alternate_id", + "partners_partnerorganization"."alternate_name", + "partners_partnerorganization"."rating", + "partners_partnerorganization"."core_values_assessment_date", + "partners_partnerorganization"."vision_synced", + "partners_partnerorganization"."type_of_assessment", + "partners_partnerorganization"."last_assessment_date", + "partners_partnerorganization"."hidden", + "partners_partnerorganization"."deleted_flag", + "partners_partnerorganization"."total_ct_cp", + "partners_partnerorganization"."total_ct_cy", + "partners_partnerorganization"."blocked", + "partners_partnerorganization"."city", + "partners_partnerorganization"."country", + "partners_partnerorganization"."postal_code", + "partners_partnerorganization"."shared_with", + "partners_partnerorganization"."street_address", + "partners_partnerorganization"."hact_values", + "partners_partnerorganization"."created", + "partners_partnerorganization"."modified", + "partners_partnerorganization"."net_ct_cy", + "partners_partnerorganization"."reported_cy", + "partners_partnerorganization"."total_ct_ytd", + "partners_partnerorganization"."basis_for_risk_rating", + "partners_partnerorganization"."manually_blocked", + "partners_partnerorganization"."outstanding_dct_amount_6_to_9_months_usd", + "partners_partnerorganization"."outstanding_dct_amount_more_than_9_months_usd", + "partners_partnerorganization"."highest_risk_rating_name", + "partners_partnerorganization"."highest_risk_rating_type", + "partners_partnerorganization"."psea_assessment_date", + "partners_partnerorganization"."sea_risk_rating_name", + "partners_partnerorganization"."lead_office_id", + "partners_partnerorganization"."lead_section_id", + "partners_partnerorganization"."organization_id", + 'afghanistan' AS __schema, + "reports_office"."id", + "reports_office"."name", + 'afghanistan' AS __schema, + "reports_sector"."id", + "reports_sector"."name", + "reports_sector"."description", + "reports_sector"."alternate_id", + "reports_sector"."alternate_name", + "reports_sector"."dashboard", + "reports_sector"."color", + "reports_sector"."created", + "reports_sector"."modified", + "reports_sector"."active", "organizations_organization"."id", + "organizations_organization"."created", + "organizations_organization"."modified", + "organizations_organization"."name", + "organizations_organization"."vendor_number", + "organizations_organization"."organization_type", + "organizations_organization"."cso_type", + "organizations_organization"."short_name", + "organizations_organization"."other", + "organizations_organization"."parent_id", + 'afghanistan' AS __schema, + "partners_plannedengagement"."id", + "partners_plannedengagement"."created", + "partners_plannedengagement"."modified", + "partners_plannedengagement"."spot_check_planned_q1", + "partners_plannedengagement"."spot_check_planned_q2", + "partners_plannedengagement"."spot_check_planned_q3", + "partners_plannedengagement"."spot_check_planned_q4", + "partners_plannedengagement"."scheduled_audit", + "partners_plannedengagement"."special_audit", + "partners_plannedengagement"."spot_check_follow_up", + "partners_plannedengagement"."partner_id" + FROM "partners_partnerorganization" + LEFT OUTER JOIN "reports_office" ON ("partners_partnerorganization"."lead_office_id" = "reports_office"."id") + LEFT OUTER JOIN "reports_sector" ON ("partners_partnerorganization"."lead_section_id" = "reports_sector"."id") + INNER JOIN "organizations_organization" ON ("partners_partnerorganization"."organization_id" = "organizations_organization"."id") + LEFT OUTER JOIN "partners_plannedengagement" ON ("partners_partnerorganization"."id" = "partners_plannedengagement"."partner_id") + LEFT OUTER JOIN "t2f_travelactivity" ON ( "t2f_travelactivity"."partner_id" = "partners_plannedengagement"."partner_id" ) + INNER JOIN "t2f_travelactivity_travels" ON ("t2f_travelactivity"."id" = "t2f_travelactivity_travels"."travelactivity_id") + INNER JOIN "t2f_travel" ON ("t2f_travelactivity_travels"."travel_id" = "t2f_travel"."id") + ORDER BY "partners_partnerorganization"."id" ASC + +""" + class PartnerLoader(EtoolsLoader): def get_queryset(self): diff --git a/src/etools_datamart/apps/mart/data/models/reports_office.py b/src/etools_datamart/apps/mart/data/models/reports_office.py index 4b853f613..d208ae429 100644 --- a/src/etools_datamart/apps/mart/data/models/reports_office.py +++ b/src/etools_datamart/apps/mart/data/models/reports_office.py @@ -12,6 +12,16 @@ def get_queryset(self): class Office(EtoolsDataMartModel): name = models.CharField(max_length=254, null=True, blank=True) + """ + SET search_path = public, + SELECT COUNT(*) AS "__count" FROM "reports_office" + + SELECT '' AS __schema, + "reports_office"."id", + "reports_office"."name" + FROM "reports_office" + ORDER BY "reports_office"."id" ASC + """ loader = OfficeLoader() From a9f92c12a5f7670009c3ced4b65a68eb1025aae6 Mon Sep 17 00:00:00 2001 From: Hakan Date: Tue, 26 Nov 2024 17:43:14 +0300 Subject: [PATCH 02/15] bump up with temp version --- CHANGES | 4 ++++ src/etools_datamart/__init__.py | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGES b/CHANGES index 8ba0bbfae..83d393fb9 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,7 @@ +4.7.15.0 +---- +* DB Query for following etools loaders have been extracted; + 4.7.14 ---- * Fix logic error extract_longitude function diff --git a/src/etools_datamart/__init__.py b/src/etools_datamart/__init__.py index 2a7dd1b13..5ff8949b5 100644 --- a/src/etools_datamart/__init__.py +++ b/src/etools_datamart/__init__.py @@ -1,3 +1,3 @@ NAME = "etools-datamart" -VERSION = __version__ = "4.7.14" +VERSION = __version__ = "4.7.15.0" __author__ = "" From 58a7129369eaa76c1d976dae7fabce4e657010f4 Mon Sep 17 00:00:00 2001 From: Hakan Date: Tue, 3 Dec 2024 18:20:34 +0300 Subject: [PATCH 03/15] add queries for attachments, audit and spotcheck --- .../data/models/attachments_attachment.py | 74 +++++++ .../apps/mart/data/models/audit_audit.py | 192 ++++++++++++++++++ .../apps/mart/data/models/audit_spotcheck.py | 189 +++++++++++++++++ 3 files changed, 455 insertions(+) diff --git a/src/etools_datamart/apps/mart/data/models/attachments_attachment.py b/src/etools_datamart/apps/mart/data/models/attachments_attachment.py index 6f2ec1e0d..fc63f4524 100644 --- a/src/etools_datamart/apps/mart/data/models/attachments_attachment.py +++ b/src/etools_datamart/apps/mart/data/models/attachments_attachment.py @@ -8,6 +8,80 @@ class AttachmentLoader(EtoolsLoader): + """ + Load Queries: + + -- Set country schema + SET search_path = public, ##COUNTRY##; + + -- Count for paging; + SELECT COUNT(*) AS "__count" FROM "attachments_attachmentflat" + + SELECT '##COUNTRY##' AS __schema, + "attachments_attachmentflat"."id", + "attachments_attachmentflat"."partner", + "attachments_attachmentflat"."partner_type", + "attachments_attachmentflat"."vendor_number", + "attachments_attachmentflat"."pd_ssfa_number", + "attachments_attachmentflat"."file_type", + "attachments_attachmentflat"."file_link", + "attachments_attachmentflat"."uploaded_by", + "attachments_attachmentflat"."attachment_id", + "attachments_attachmentflat"."filename", + "attachments_attachmentflat"."agreement_reference_number", + "attachments_attachmentflat"."object_link", + "attachments_attachmentflat"."source", + "attachments_attachmentflat"."pd_ssfa", + "attachments_attachmentflat"."created", + "attachments_attachmentflat"."ip_address", + + "unicef_attachments_attachment"."id", + "unicef_attachments_attachment"."created", + "unicef_attachments_attachment"."modified", + "unicef_attachments_attachment"."file", + "unicef_attachments_attachment"."hyperlink", + "unicef_attachments_attachment"."object_id", + "unicef_attachments_attachment"."code", + "unicef_attachments_attachment"."content_type_id", + "unicef_attachments_attachment"."file_type_id", + "unicef_attachments_attachment"."uploaded_by_id", + "unicef_attachments_attachment"."ip_address", + + "django_content_type"."id", + "django_content_type"."app_label", + "django_content_type"."model", + + "unicef_attachments_filetype"."id", + "unicef_attachments_filetype"."order", + "unicef_attachments_filetype"."name", + "unicef_attachments_filetype"."label", + "unicef_attachments_filetype"."code", + "unicef_attachments_filetype"."group", + + "auth_user"."id", "auth_user"."password", + "auth_user"."last_login", + "auth_user"."is_superuser", + "auth_user"."username", + "auth_user"."first_name", + "auth_user"."last_name", + "auth_user"."email", + "auth_user"."is_staff", + "auth_user"."is_active", + "auth_user"."date_joined", + "auth_user"."middle_name", + "auth_user"."created", + "auth_user"."modified", + "auth_user"."preferences" + + FROM "attachments_attachmentflat" + INNER JOIN "unicef_attachments_attachment" ON ("attachments_attachmentflat"."attachment_id" = "unicef_attachments_attachment"."id") + LEFT OUTER JOIN "django_content_type" ON ("unicef_attachments_attachment"."content_type_id" = "django_content_type"."id") + LEFT OUTER JOIN "unicef_attachments_filetype" ON ("unicef_attachments_attachment"."file_type_id" = "unicef_attachments_filetype"."id") + LEFT OUTER JOIN "auth_user" ON ("unicef_attachments_attachment"."uploaded_by_id" = "auth_user"."id") + ORDER BY "attachments_attachmentflat"."id" ASC + LIMIT ##PAGE_SIZE## OFFSET ##PAGE_OFFSET## + """ + def get_queryset(self): return self.config.source.objects.select_related( "attachment", diff --git a/src/etools_datamart/apps/mart/data/models/audit_audit.py b/src/etools_datamart/apps/mart/data/models/audit_audit.py index 8ae2e3a8b..376addb76 100644 --- a/src/etools_datamart/apps/mart/data/models/audit_audit.py +++ b/src/etools_datamart/apps/mart/data/models/audit_audit.py @@ -22,6 +22,198 @@ class AuditLoader(EngagementMixin, EtoolsLoader): + """ + -- Set country schema + SET search_path = public, ##COUNTRY##; + -- Count for paging; + SELECT COUNT(*) AS "__count" FROM "audit_audit"; + -- Audit + SELECT '##COUNTRY##' AS __schema, + "audit_audit"."engagement_ptr_id", + "audit_audit"."audited_expenditure", + "audit_audit"."financial_findings", + "audit_audit"."audit_opinion", + "audit_audit"."audited_expenditure_local", + "audit_audit"."financial_findings_local", + + "audit_engagement"."id", + "audit_engagement"."created", + "audit_engagement"."modified", + "audit_engagement"."status", + "audit_engagement"."partner_contacted_at", + "audit_engagement"."engagement_type", + "audit_engagement"."start_date", + "audit_engagement"."end_date", + "audit_engagement"."total_value", + "audit_engagement"."date_of_field_visit", + "audit_engagement"."date_of_draft_report_to_ip", + "audit_engagement"."date_of_comments_by_ip", + "audit_engagement"."date_of_draft_report_to_unicef", + "audit_engagement"."date_of_comments_by_unicef", + "audit_engagement"."date_of_report_submit", + "audit_engagement"."date_of_final_report", + "audit_engagement"."date_of_cancel", + "audit_engagement"."amount_refunded", + "audit_engagement"."additional_supporting_documentation_provided", + "audit_engagement"."justification_provided_and_accepted", + "audit_engagement"."write_off_required", + "audit_engagement"."cancel_comment", + "audit_engagement"."explanation_for_additional_information", + "audit_engagement"."partner_id", + "audit_engagement"."joint_audit", + "audit_engagement"."agreement_id", + "audit_engagement"."po_item_id", + "audit_engagement"."shared_ip_with", + "audit_engagement"."exchange_rate", + "audit_engagement"."currency_of_report", + "audit_engagement"."reference_number", + "audit_engagement"."year_of_audit", + + "purchase_order_purchaseorder"."id", + "purchase_order_purchaseorder"."created", + "purchase_order_purchaseorder"."modified", + "purchase_order_purchaseorder"."order_number", + "purchase_order_purchaseorder"."contract_start_date", + "purchase_order_purchaseorder"."contract_end_date", + "purchase_order_purchaseorder"."auditor_firm_id", + "purchase_order_auditorfirm"."id", + "purchase_order_auditorfirm"."created", + "purchase_order_auditorfirm"."modified", + "purchase_order_auditorfirm"."street_address", + "purchase_order_auditorfirm"."city", + "purchase_order_auditorfirm"."postal_code", + "purchase_order_auditorfirm"."country", + "purchase_order_auditorfirm"."email", + "purchase_order_auditorfirm"."phone_number", + "purchase_order_auditorfirm"."blocked", + "purchase_order_auditorfirm"."hidden", + "purchase_order_auditorfirm"."deleted_flag", + "purchase_order_auditorfirm"."vision_synced", + "purchase_order_auditorfirm"."unicef_users_allowed", + "purchase_order_auditorfirm"."organization_id", + + "organizations_organization"."id", + "organizations_organization"."created", + "organizations_organization"."modified", + "organizations_organization"."name", + "organizations_organization"."vendor_number", + "organizations_organization"."organization_type", + "organizations_organization"."cso_type", + "organizations_organization"."short_name", + "organizations_organization"."other", + "organizations_organization"."parent_id", + + "partners_partnerorganization"."id", + "partners_partnerorganization"."description", + "partners_partnerorganization"."address", + "partners_partnerorganization"."email", + "partners_partnerorganization"."phone_number", + "partners_partnerorganization"."alternate_id", + "partners_partnerorganization"."alternate_name", + "partners_partnerorganization"."rating", + "partners_partnerorganization"."core_values_assessment_date", + "partners_partnerorganization"."vision_synced", + "partners_partnerorganization"."type_of_assessment", + "partners_partnerorganization"."last_assessment_date", + "partners_partnerorganization"."hidden", + "partners_partnerorganization"."deleted_flag", + "partners_partnerorganization"."total_ct_cp", + "partners_partnerorganization"."total_ct_cy", + "partners_partnerorganization"."blocked", + "partners_partnerorganization"."city", + "partners_partnerorganization"."country", + "partners_partnerorganization"."postal_code", + "partners_partnerorganization"."shared_with", + "partners_partnerorganization"."street_address", + "partners_partnerorganization"."hact_values", + "partners_partnerorganization"."created", + "partners_partnerorganization"."modified", + "partners_partnerorganization"."net_ct_cy", + "partners_partnerorganization"."reported_cy", + "partners_partnerorganization"."total_ct_ytd", + "partners_partnerorganization"."basis_for_risk_rating", + "partners_partnerorganization"."manually_blocked", + "partners_partnerorganization"."outstanding_dct_amount_6_to_9_months_usd", + "partners_partnerorganization"."outstanding_dct_amount_more_than_9_months_usd", + "partners_partnerorganization"."highest_risk_rating_name", + "partners_partnerorganization"."highest_risk_rating_type", + "partners_partnerorganization"."psea_assessment_date", + --"partners_partnerorganiazation"."sea_risk_rating_name", + "partners_partnerorganization"."lead_office_id", + "partners_partnerorganization"."lead_section_id", + "partners_partnerorganization"."organization_id" + + FROM "audit_audit" + INNER JOIN "audit_engagement" ON ("audit_audit"."engagement_ptr_id" = "audit_engagement"."id") + INNER JOIN "purchase_order_purchaseorder" ON ("audit_engagement"."agreement_id" = "purchase_order_purchaseorder"."id") + INNER JOIN "purchase_order_auditorfirm" ON ("purchase_order_purchaseorder"."auditor_firm_id" = "purchase_order_auditorfirm"."id") + INNER JOIN "organizations_organization" ON ("purchase_order_auditorfirm"."organization_id" = "organizations_organization"."id") + INNER JOIN "partners_partnerorganization" ON ("partners_partnerorganization"."id" = audit_engagement"."partner_id") + ORDER BY "audit_audit"."engagement_ptr_id" ASC + LIMIT ##PAGE_SIZE## OFFSET ##PAGE_OFFSET##; + + --Audit Engagement Sections + SELECT '##COUNTRY##' AS __schema, + "audit_engagement_sections"."id", + "audit_engagement_sections"."engagement_id", + "audit_engagement_sections"."section_id" + FROM "audit_engagement_sections" + WHERE "audit_engagement_sections"."engagement_id" in (##LIST_OF_ENAGAGEMENT_IDs_IN_THE_PAGE##); + + --Audit Engagement Offices + SELECT '##COUNTRY##' AS __schema, + "audit_engagement_offices"."id", + "audit_engagement_offices"."engagement_id", + "audit_engagement_offices"."office_id" + FROM "audit_engagement_offices" + WHERE "audit_engagement_sections"."engagement_id" in (##LIST_OF_ENAGAGEMENT_IDs_IN_THE_PAGE##); + + --Audit Financial Findings: Summing can be left to (T)ransform stage + SELECT "audit_financialfinding"."audit_id", + SUM("audit_financialfinding"."amount") as amount_sum + FROM "audit_financialfinding" + WHERE "audit_financialfinding"."audit_id" in (##LIST_OF_ENAGAGEMENT_IDs_IN_THE_PAGE##) + GROUP BY "audit_financialfinding"."audit_id" + ORDER BY "audit_financialfinding"."audit_id" ASC; + + --Audit Key Internal Count per audit_id + SELECT audit_id, + COUNT(*) AS "__count" + FROM "audit_keyinternalcontrol" + WHERE "audit_keyinternalcontrol"."audit_id" in (##LIST_OF_ENAGAGEMENT_IDs_IN_THE_PAGE##) + GROUP BY audit_id + ORDER BY audit_id ASC; + + -- Action Point Status Counts: Counting can be left to (T)ransform stage + SELECT "engagement_id", + "action_points_actionpoint"."status", + COUNT("action_points_actionpoint"."status") AS "count" + FROM "action_points_actionpoint" + WHERE "action_points_actionpoint"."engagement_id" in (##LIST_OF_ENAGAGEMENT_IDs_IN_THE_PAGE##) + GROUP BY "action_points_actionpoint"."engagement_id" + ORDER BY "action_points_actionpoint"."status" ASC; + + -- Action Point High Priority count per engagement_id : Counting can be left to (T)ransform stage + SELECT "action_points_actionpoint"."engagement_id" + "action_points_actionpoint"."high_priority", + COUNT("action_points_actionpoint"."high_priority") AS "count" + FROM "action_points_actionpoint" + WHERE "action_points_actionpoint"."engagement_id" in (##LIST_OF_ENAGAGEMENT_IDs_IN_THE_PAGE##) + GROUP BY "action_points_actionpoint"."engagement_id","action_points_actionpoint"."high_priority" + ORDER BY "action_points_actionpoint"."engagement_id","action_points_actionpoint"."high_priority" ASC + + -- Count description per engagement_id : Counting can be left to (T)ransform stage + SELECT "categories_category"."description", + "action_points_actionpoint"."engagement_id", + COUNT("categories_category"."description") AS "count" + FROM "action_points_actionpoint" + LEFT OUTER JOIN "categories_category" ON ("action_points_actionpoint"."category_id" = "categories_category"."id") + WHERE "action_points_actionpoint"."engagement_id" in (##LIST_OF_ENAGAGEMENT_IDs_IN_THE_PAGE##) + GROUP BY "action_points_actionpoint"."engagement_id", "categories_category"."description" + ORDER BY "action_points_actionpoint"."engagement_id", "categories_category"."description" ASC + + """ + def process_country(self): batch_size = settings.RESULTSET_BATCH_SIZE logger.debug(f"Batch size:{batch_size}") diff --git a/src/etools_datamart/apps/mart/data/models/audit_spotcheck.py b/src/etools_datamart/apps/mart/data/models/audit_spotcheck.py index c6a9b3a1f..f1ccc07ce 100644 --- a/src/etools_datamart/apps/mart/data/models/audit_spotcheck.py +++ b/src/etools_datamart/apps/mart/data/models/audit_spotcheck.py @@ -20,6 +20,195 @@ class SpotCheckLoader(EngagementMixin, EtoolsLoader): + """ + -- Set country schema + SET search_path = public, ##COUNTRY##; + -- Count for paging; + SELECT COUNT(*) AS "__count" FROM "audit_spotcheck"; + + -- Paged retreival of main recordset + SELECT '##COUNTRY##' AS __schema, + "audit_spotcheck"."engagement_ptr_id", + "audit_spotcheck"."total_amount_tested", + "audit_spotcheck"."total_amount_of_ineligible_expenditure", + "audit_spotcheck"."internal_controls", + + "audit_engagement"."id", + "audit_engagement"."created", + "audit_engagement"."modified", + "audit_engagement"."status", + "audit_engagement"."partner_contacted_at", + "audit_engagement"."engagement_type", + "audit_engagement"."start_date", + "audit_engagement"."end_date", + "audit_engagement"."total_value", + "audit_engagement"."date_of_field_visit", + "audit_engagement"."date_of_draft_report_to_ip", + "audit_engagement"."date_of_comments_by_ip", + "audit_engagement"."date_of_draft_report_to_unicef", + "audit_engagement"."date_of_comments_by_unicef", + "audit_engagement"."date_of_report_submit", + "audit_engagement"."date_of_final_report", + "audit_engagement"."date_of_cancel", + "audit_engagement"."amount_refunded", + "audit_engagement"."additional_supporting_documentation_provided", + "audit_engagement"."justification_provided_and_accepted", + "audit_engagement"."write_off_required", + "audit_engagement"."cancel_comment", + "audit_engagement"."explanation_for_additional_information", + "audit_engagement"."partner_id", + "audit_engagement"."joint_audit", + "audit_engagement"."agreement_id", + "audit_engagement"."po_item_id", + "audit_engagement"."shared_ip_with", + "audit_engagement"."exchange_rate", + "audit_engagement"."currency_of_report", + "audit_engagement"."reference_number", + "audit_engagement"."year_of_audit", + + "purchase_order_purchaseorder"."id", + "purchase_order_purchaseorder"."created", + "purchase_order_purchaseorder"."modified", + "purchase_order_purchaseorder"."order_number", + "purchase_order_purchaseorder"."contract_start_date", + "purchase_order_purchaseorder"."contract_end_date", + "purchase_order_purchaseorder"."auditor_firm_id", + "purchase_order_auditorfirm"."id", + "purchase_order_auditorfirm"."created", + "purchase_order_auditorfirm"."modified", + "purchase_order_auditorfirm"."street_address", + "purchase_order_auditorfirm"."city", + "purchase_order_auditorfirm"."postal_code", + "purchase_order_auditorfirm"."country", + "purchase_order_auditorfirm"."email", + "purchase_order_auditorfirm"."phone_number", + "purchase_order_auditorfirm"."blocked", + "purchase_order_auditorfirm"."hidden", + "purchase_order_auditorfirm"."deleted_flag", + "purchase_order_auditorfirm"."vision_synced", + "purchase_order_auditorfirm"."unicef_users_allowed", + "purchase_order_auditorfirm"."organization_id", + + "organizations_organization"."id", + "organizations_organization"."created", + "organizations_organization"."modified", + "organizations_organization"."name", + "organizations_organization"."vendor_number", + "organizations_organization"."organization_type", + "organizations_organization"."cso_type", + "organizations_organization"."short_name", + "organizations_organization"."other", + "organizations_organization"."parent_id" + FROM "audit_spotcheck" INNER JOIN "audit_engagement" ON ("audit_spotcheck"."engagement_ptr_id" = "audit_engagement"."id") + INNER JOIN "purchase_order_purchaseorder" ON ("audit_engagement"."agreement_id" = "purchase_order_purchaseorder"."id") + INNER JOIN "purchase_order_auditorfirm" ON ("purchase_order_purchaseorder"."auditor_firm_id" = "purchase_order_auditorfirm"."id") + INNER JOIN "organizations_organization" ON ("purchase_order_auditorfirm"."organization_id" = "organizations_organization"."id") + ORDER BY "audit_spotcheck"."engagement_ptr_id" ASC LIMIT ##PAGE_SIZE## OFSET ##PAGE_OFSET##; + + + SELECT '##COUNTRY##' AS __schema, + "audit_engagement_offices"."id", + "audit_engagement_offices"."engagement_id", + "audit_engagement_offices"."office_id" + FROM "audit_engagement_offices" + WHERE "audit_engagement_offices"."engagement_id" IN (##ENGAGEMENT_IDs_IN_THE_PAGE##); + + SELECT '##COUNTRY##' AS __schema, + "partners_partnerorganization"."id", + "partners_partnerorganization"."description", + "partners_partnerorganization"."address", + "partners_partnerorganization"."email", + "partners_partnerorganization"."phone_number", + "partners_partnerorganization"."alternate_id", + "partners_partnerorganization"."alternate_name", + "partners_partnerorganization"."rating", + "partners_partnerorganization"."core_values_assessment_date", + "partners_partnerorganization"."vision_synced", + "partners_partnerorganization"."type_of_assessment", + "partners_partnerorganization"."last_assessment_date", + "partners_partnerorganization"."hidden", + "partners_partnerorganization"."deleted_flag", + "partners_partnerorganization"."total_ct_cp", + "partners_partnerorganization"."total_ct_cy", + "partners_partnerorganization"."blocked", + "partners_partnerorganization"."city", + "partners_partnerorganization"."country", + "partners_partnerorganization"."postal_code", + "partners_partnerorganization"."shared_with", + "partners_partnerorganization"."street_address", + "partners_partnerorganization"."hact_values", + "partners_partnerorganization"."created", + "partners_partnerorganization"."modified", + "partners_partnerorganization"."net_ct_cy", + "partners_partnerorganization"."reported_cy", + "partners_partnerorganization"."total_ct_ytd", + "partners_partnerorganization"."basis_for_risk_rating", + "partners_partnerorganization"."manually_blocked", + "partners_partnerorganization"."outstanding_dct_amount_6_to_9_months_usd", + "partners_partnerorganization"."outstanding_dct_amount_more_than_9_months_usd", + "partners_partnerorganization"."highest_risk_rating_name", + "partners_partnerorganization"."highest_risk_rating_type", + "partners_partnerorganization"."psea_assessment_date", + "partners_partnerorganization"."sea_risk_rating_name", + "partners_partnerorganization"."lead_office_id", + "partners_partnerorganization"."lead_section_id", + "partners_partnerorganization"."organization_id" + FROM "partners_partnerorganization" + WHERE "partners_partnerorganization"."id" in (##PARTNER_ORGANIZATION_IDs_IN_THE_PAGE##) + + SELECT '##COUNTRY##' AS __schema, + "audit_engagement_sections"."id", + "audit_engagement_sections"."engagement_id", + "audit_engagement_sections"."section_id" + FROM "audit_engagement_sections" + WHERE "audit_engagement_sections"."engagement_id" IN (##ENGAGEMENT_IDs_IN_THE_PAGE##); + + SELECT "audit_finding"."spot_check_id". + "audit_finding"."category_of_observation", + COUNT("audit_finding"."category_of_observation") AS "count" + FROM "audit_finding" WHERE ("audit_finding"."priority" = 'high' + AND "audit_finding"."spot_check_id" in ( ##SPOTECHECK_IDs_IN_T?HE_PAGE##) ) + GROUP BY "audit_finding"."spot_check_id", "audit_finding"."category_of_observation" + ORDER BY "audit_finding"."spot_check_id", "audit_finding"."category_of_observation" ASC + + + SELECT "audit_finding"."spot_check_id". + "audit_finding"."category_of_observation", + COUNT("audit_finding"."category_of_observation") AS "count" + FROM "audit_finding" WHERE ("audit_finding"."priority" = 'low' + AND "audit_finding"."spot_check_id" in ( ##SPOTECHECK_IDs_IN_THE_PAGE##) ) + GROUP BY "audit_finding"."spot_check_id", "audit_finding"."category_of_observation" + ORDER BY "audit_finding"."spot_check_id", "audit_finding"."category_of_observation" ASC + + + SELECT "action_points_actionpoint"."engagement_id", + "action_points_actionpoint"."status", + COUNT("action_points_actionpoint"."status") AS "count" + FROM "action_points_actionpoint" + WHERE "action_points_actionpoint"."engagement_id" IN (##ENGAGEMENT_IDs_IN_THE_PAGE##) + GROUP BY "action_points_actionpoint"."engagement_id","action_points_actionpoint"."status" + ORDER BY "action_points_actionpoint"."engagement_id","action_points_actionpoint"."status" ASC; + + + SELECT action_points_actionpoint"."engagement_id" + "action_points_actionpoint"."high_priority", + COUNT("action_points_actionpoint"."high_priority") AS "count" + FROM "action_points_actionpoint" + WHERE "action_points_actionpoint"."engagement_id" IN (##ENGAGEMENT_IDs_IN_THE_PAGE##) + GROUP BY action_points_actionpoint"."engagement_id","action_points_actionpoint"."high_priority" + ORDER BY action_points_actionpoint"."engagement_id"."action_points_actionpoint"."high_priority" ASC + + + SELECT "categories_category"."id", + "categories_category"."description", + COUNT("categories_category"."description") AS "count" + FROM "action_points_actionpoint" + LEFT OUTER JOIN "categories_category" ON ("action_points_actionpoint"."category_id" = "categories_category"."id") + WHERE "action_points_actionpoint"."engagement_id" IN (##ENGAGEMENT_IDs_IN_THE_PAGE##) + GROUP BY "categories_category"."id", "categories_category"."description" + ORDER BY "categories_category"."id", "categories_category"."description" ASC + """ + def process_country(self): batch_size = settings.RESULTSET_BATCH_SIZE logger.debug(f"Batch size:{batch_size}") From 1f595f9bf63d82db82b8d2b8059ef0cafb71ea40 Mon Sep 17 00:00:00 2001 From: Hakan Date: Wed, 4 Dec 2024 17:12:41 +0300 Subject: [PATCH 04/15] update auditspotcheck, partner, office --- .../apps/mart/data/models/audit_spotcheck.py | 2 +- .../apps/mart/data/models/partner.py | 291 +++++++----------- .../apps/mart/data/models/reports_office.py | 26 +- 3 files changed, 122 insertions(+), 197 deletions(-) diff --git a/src/etools_datamart/apps/mart/data/models/audit_spotcheck.py b/src/etools_datamart/apps/mart/data/models/audit_spotcheck.py index f1ccc07ce..320a213a1 100644 --- a/src/etools_datamart/apps/mart/data/models/audit_spotcheck.py +++ b/src/etools_datamart/apps/mart/data/models/audit_spotcheck.py @@ -103,7 +103,7 @@ class SpotCheckLoader(EngagementMixin, EtoolsLoader): INNER JOIN "purchase_order_purchaseorder" ON ("audit_engagement"."agreement_id" = "purchase_order_purchaseorder"."id") INNER JOIN "purchase_order_auditorfirm" ON ("purchase_order_purchaseorder"."auditor_firm_id" = "purchase_order_auditorfirm"."id") INNER JOIN "organizations_organization" ON ("purchase_order_auditorfirm"."organization_id" = "organizations_organization"."id") - ORDER BY "audit_spotcheck"."engagement_ptr_id" ASC LIMIT ##PAGE_SIZE## OFSET ##PAGE_OFSET##; + ORDER BY "audit_spotcheck"."engagement_ptr_id" ASC LIMIT ##PAGE_SIZE## OFFSET ##PAGE_OFFSET##; SELECT '##COUNTRY##' AS __schema, diff --git a/src/etools_datamart/apps/mart/data/models/partner.py b/src/etools_datamart/apps/mart/data/models/partner.py index 6b28d2927..02f651d20 100644 --- a/src/etools_datamart/apps/mart/data/models/partner.py +++ b/src/etools_datamart/apps/mart/data/models/partner.py @@ -11,200 +11,121 @@ from etools_datamart.apps.sources.etools.enrichment.consts import PartnerOrganizationConst, PartnerType, TravelType from etools_datamart.apps.sources.etools.models import PartnersPartnerorganization, ReportsOffice, T2FTravelactivity -""" -SET search_path = public,; -SELECT '' AS __schema, - "partners_partnerorganization"."id", - "partners_partnerorganization"."description", - "partners_partnerorganization"."address", - "partners_partnerorganization"."email", - "partners_partnerorganization"."phone_number", - "partners_partnerorganization"."alternate_id", - "partners_partnerorganization"."alternate_name", - "partners_partnerorganization"."rating", - "partners_partnerorganization"."core_values_assessment_date", - "partners_partnerorganization"."vision_synced", - "partners_partnerorganization"."type_of_assessment", - "partners_partnerorganization"."last_assessment_date", - "partners_partnerorganization"."hidden", - "partners_partnerorganization"."deleted_flag", - "partners_partnerorganization"."total_ct_cp", - "partners_partnerorganization"."total_ct_cy", - "partners_partnerorganization"."blocked", - "partners_partnerorganization"."city", - "partners_partnerorganization"."country", - "partners_partnerorganization"."postal_code", - "partners_partnerorganization"."shared_with", - "partners_partnerorganization"."street_address", - "partners_partnerorganization"."hact_values", - "partners_partnerorganization"."created", - "partners_partnerorganization"."modified", - "partners_partnerorganization"."net_ct_cy", - "partners_partnerorganization"."reported_cy", - "partners_partnerorganization"."total_ct_ytd", - "partners_partnerorganization"."basis_for_risk_rating", - "partners_partnerorganization"."manually_blocked", - "partners_partnerorganization"."outstanding_dct_amount_6_to_9_months_usd", - "partners_partnerorganization"."outstanding_dct_amount_more_than_9_months_usd", - "partners_partnerorganization"."highest_risk_rating_name", - "partners_partnerorganization"."highest_risk_rating_type", - "partners_partnerorganization"."psea_assessment_date", - "partners_partnerorganization"."sea_risk_rating_name", - "partners_partnerorganization"."lead_office_id", - "partners_partnerorganization"."lead_section_id", - "partners_partnerorganization"."organization_id", - '' AS __schema, - "reports_office"."id", - "reports_office"."name", - '' AS __schema, - "reports_sector"."id", - "reports_sector"."name", - "reports_sector"."description", - "reports_sector"."alternate_id", - "reports_sector"."alternate_name", - "reports_sector"."dashboard", - "reports_sector"."color", - "reports_sector"."created", - "reports_sector"."modified", - "reports_sector"."active", "organizations_organization"."id", - "organizations_organization"."created", - "organizations_organization"."modified", - "organizations_organization"."name", - "organizations_organization"."vendor_number", - "organizations_organization"."organization_type", - "organizations_organization"."cso_type", - "organizations_organization"."short_name", - "organizations_organization"."other", - "organizations_organization"."parent_id", - '' AS __schema, - "partners_plannedengagement"."id", - "partners_plannedengagement"."created", - "partners_plannedengagement"."modified", - "partners_plannedengagement"."spot_check_planned_q1", - "partners_plannedengagement"."spot_check_planned_q2", - "partners_plannedengagement"."spot_check_planned_q3", - "partners_plannedengagement"."spot_check_planned_q4", - "partners_plannedengagement"."scheduled_audit", - "partners_plannedengagement"."special_audit", - "partners_plannedengagement"."spot_check_follow_up", - "partners_plannedengagement"."partner_id" - FROM "partners_partnerorganization" - LEFT OUTER JOIN "reports_office" ON ("partners_partnerorganization"."lead_office_id" = "reports_office"."id") - LEFT OUTER JOIN "reports_sector" ON ("partners_partnerorganization"."lead_section_id" = "reports_sector"."id") - INNER JOIN "organizations_organization" ON ("partners_partnerorganization"."organization_id" = "organizations_organization"."id") - LEFT OUTER JOIN "partners_plannedengagement" ON ("partners_partnerorganization"."id" = "partners_plannedengagement"."partner_id") - ORDER BY "partners_partnerorganization"."id" ASC LIMIT OFFSET +class PartnerLoader(EtoolsLoader): + """ + -- To run per country schema + SET search_path = public,##COUNTRY##; + -- Count for paging + SELECT COUNT(*) AS "__count" FROM "partners_partnerorganization - SELECT '##COUNTRY##' AS __schema, - "t2f_travelactivity"."id", - "t2f_travelactivity"."travel_type", - "t2f_travelactivity"."date", - "t2f_travelactivity"."partner_id", - "t2f_travelactivity"."partnership_id", - "t2f_travelactivity"."primary_traveler_id", - "t2f_travelactivity"."result_id" - FROM "t2f_travelactivity" - INNER JOIN "t2f_travelactivity_travels" ON ("t2f_travelactivity"."id" = "t2f_travelactivity_travels"."travelactivity_id") - INNER JOIN "t2f_travel" ON ("t2f_travelactivity_travels"."travel_id" = "t2f_travel"."id") - WHERE ("t2f_travelactivity"."date" IS NOT NULL AND "t2f_travelactivity"."travel_type" = 'Programmatic Visit' - AND "t2f_travel"."status" = 'completed' AND "t2f_travel"."traveler_id" = ("t2f_travelactivity"."primary_traveler_id") - AND "t2f_travelactivity"."partner_id" IN (805, 806, 807, 808, 809, 810, 811, 812, 813, 814, 815, 816, 817, 818, 819, 820, 821, 822, 823, 824, 825, 826, 827, 828, 829, 830, 831, 832, 833, 835, 836, 837, 838, 839, 840, 841, 842, 843, 844, 845, 846, 847, 848, 849, 850, 851, 852, 853, 854, 855, 856, 857, 858, 859, 860, 861, 862, 863, 864, 865, 866, 867, 868, 869, 870, 871, 872, 873, 874, 875, 876, 877, 878, 879, 880, 881, 882, 883, 884, 885, 886, 887, 888, 889, 890, 891, 892, 893, 894, 895, 896, 897, 898, 899, 900, 901, 902, 903, 904, 905, 906, 907, 908, 909, 910, 911, 912, 913, 914, 915, 916, 917, 918, 919, 920, 921, 922, 923, 924, 925, 926, 927, 928, 929, 930, 931, 932, 933, 934, 935, 936, 937, 938, 939, 940, 941, 942, 943, 944, 945, 946, 947, 948, 949, 950, 951, 952, 953, 954, 955, 956, 957, 958, 963, 964, 965, 966, 967, 968, 969, 970, 971, 972, 973, 974, 975, 976, 977, 978, 979, 980, 981, 982, 983, 984, 985, 986, 987, 988, 1021, 1022, 1023, 1024, 1025, 1026, 1027, 1028, 1029, 1030, 1031, 1064, 1065, 1066, 1067, 1068, 1069, 1071, 1072, 1073, 1074, 1076, 1077, 1078, 1079, 1080, 1081, 1082, 1083, 1084, 1085, 1086, 1087, 1088, 1089, 1090, 1091, 1092, 1093, 1094, 1095, 1096, 1097, 1098, 1099, 1100, 1101, 1102, 1103, 1104, 1105, 1106, 1107, 1108, 1109, 1110, 1111, 1112, 1113, 1114, 1115, 1116, 1117, 1118, 1119, 1120, 1121, 1122, 1123, 1124, 1125, 1126, 1127, 1128, 1129, 1130, 1131, 1132, 1133, 1134, 1135, 1136, 1138, 1139, 1140, 1143, 1144, 1145, 1146, 1148, 1150, 1151, 1152, 1153, 1154, 1155, 1156, 1157, 1158, 1159, 1160, 1161, 1162, 1163, 1164, 1165, 1166, 1167, 1168, 1169, 1170, 1171, 1172, 1173, 1174, 1175, 1176, 1177, 1178, 1179, 1180, 1181, 1182, 1183, 1184, 1185, 1186, 1187, 1188, 1189, 1190, 1191, 1192, 1193, 1194, 1195, 1196, 1197, 1198, 1199, 1200, 1201, 1202, 1203, 1204, 1205, 1206, 1207, 1208, 1209, 1210, 1211, 1212, 1213, 1214, 1215, 1216, 1217, 1218, 1219, 1220, 1221, 1222)) ORDER BY "t2f_travelactivity"."date" DESC + -- Partner Organization + SELECT '##COUNTRY##' AS __schema, + "partners_partnerorganization"."id", + "partners_partnerorganization"."description", + "partners_partnerorganization"."address", + "partners_partnerorganization"."email", + "partners_partnerorganization"."phone_number", + "partners_partnerorganization"."alternate_id", + "partners_partnerorganization"."alternate_name", + "partners_partnerorganization"."rating", + "partners_partnerorganization"."core_values_assessment_date", + "partners_partnerorganization"."vision_synced", + "partners_partnerorganization"."type_of_assessment", + "partners_partnerorganization"."last_assessment_date", + "partners_partnerorganization"."hidden", + "partners_partnerorganization"."deleted_flag", + "partners_partnerorganization"."total_ct_cp", + "partners_partnerorganization"."total_ct_cy", + "partners_partnerorganization"."blocked", + "partners_partnerorganization"."city", + "partners_partnerorganization"."country", + "partners_partnerorganization"."postal_code", + "partners_partnerorganization"."shared_with", + "partners_partnerorganization"."street_address", + "partners_partnerorganization"."hact_values", + "partners_partnerorganization"."created", + "partners_partnerorganization"."modified", + "partners_partnerorganization"."net_ct_cy", + "partners_partnerorganization"."reported_cy", + "partners_partnerorganization"."total_ct_ytd", + "partners_partnerorganization"."basis_for_risk_rating", + "partners_partnerorganization"."manually_blocked", + "partners_partnerorganization"."outstanding_dct_amount_6_to_9_months_usd", + "partners_partnerorganization"."outstanding_dct_amount_more_than_9_months_usd", + "partners_partnerorganization"."highest_risk_rating_name", + "partners_partnerorganization"."highest_risk_rating_type", + "partners_partnerorganization"."psea_assessment_date", + "partners_partnerorganization"."sea_risk_rating_name", + "partners_partnerorganization"."lead_office_id", + "partners_partnerorganization"."lead_section_id", + "partners_partnerorganization"."organization_id", + "reports_office"."id", + "reports_office"."name", ' - SELECT COUNT(*) AS "__count" FROM "partners_partnerorganization + "reports_sector"."id", + "reports_sector"."name", + "reports_sector"."description", + "reports_sector"."alternate_id", + "reports_sector"."alternate_name", + "reports_sector"."dashboard", + "reports_sector"."color", + "reports_sector"."created", + "reports_sector"."modified", + "reports_sector"."active", - SET search_path = public,##COUNTRY##; - SELECT 'afghanistan' AS __schema, - "partners_partnerorganization"."id", - "partners_partnerorganization"."description", - "partners_partnerorganization"."address", - "partners_partnerorganization"."email", - "partners_partnerorganization"."phone_number", - "partners_partnerorganization"."alternate_id", - "partners_partnerorganization"."alternate_name", - "partners_partnerorganization"."rating", - "partners_partnerorganization"."core_values_assessment_date", - "partners_partnerorganization"."vision_synced", - "partners_partnerorganization"."type_of_assessment", - "partners_partnerorganization"."last_assessment_date", - "partners_partnerorganization"."hidden", - "partners_partnerorganization"."deleted_flag", - "partners_partnerorganization"."total_ct_cp", - "partners_partnerorganization"."total_ct_cy", - "partners_partnerorganization"."blocked", - "partners_partnerorganization"."city", - "partners_partnerorganization"."country", - "partners_partnerorganization"."postal_code", - "partners_partnerorganization"."shared_with", - "partners_partnerorganization"."street_address", - "partners_partnerorganization"."hact_values", - "partners_partnerorganization"."created", - "partners_partnerorganization"."modified", - "partners_partnerorganization"."net_ct_cy", - "partners_partnerorganization"."reported_cy", - "partners_partnerorganization"."total_ct_ytd", - "partners_partnerorganization"."basis_for_risk_rating", - "partners_partnerorganization"."manually_blocked", - "partners_partnerorganization"."outstanding_dct_amount_6_to_9_months_usd", - "partners_partnerorganization"."outstanding_dct_amount_more_than_9_months_usd", - "partners_partnerorganization"."highest_risk_rating_name", - "partners_partnerorganization"."highest_risk_rating_type", - "partners_partnerorganization"."psea_assessment_date", - "partners_partnerorganization"."sea_risk_rating_name", - "partners_partnerorganization"."lead_office_id", - "partners_partnerorganization"."lead_section_id", - "partners_partnerorganization"."organization_id", - 'afghanistan' AS __schema, - "reports_office"."id", - "reports_office"."name", - 'afghanistan' AS __schema, - "reports_sector"."id", - "reports_sector"."name", - "reports_sector"."description", - "reports_sector"."alternate_id", - "reports_sector"."alternate_name", - "reports_sector"."dashboard", - "reports_sector"."color", - "reports_sector"."created", - "reports_sector"."modified", - "reports_sector"."active", "organizations_organization"."id", - "organizations_organization"."created", - "organizations_organization"."modified", - "organizations_organization"."name", - "organizations_organization"."vendor_number", - "organizations_organization"."organization_type", - "organizations_organization"."cso_type", - "organizations_organization"."short_name", - "organizations_organization"."other", - "organizations_organization"."parent_id", - 'afghanistan' AS __schema, - "partners_plannedengagement"."id", - "partners_plannedengagement"."created", - "partners_plannedengagement"."modified", - "partners_plannedengagement"."spot_check_planned_q1", - "partners_plannedengagement"."spot_check_planned_q2", - "partners_plannedengagement"."spot_check_planned_q3", - "partners_plannedengagement"."spot_check_planned_q4", - "partners_plannedengagement"."scheduled_audit", - "partners_plannedengagement"."special_audit", - "partners_plannedengagement"."spot_check_follow_up", - "partners_plannedengagement"."partner_id" - FROM "partners_partnerorganization" - LEFT OUTER JOIN "reports_office" ON ("partners_partnerorganization"."lead_office_id" = "reports_office"."id") - LEFT OUTER JOIN "reports_sector" ON ("partners_partnerorganization"."lead_section_id" = "reports_sector"."id") - INNER JOIN "organizations_organization" ON ("partners_partnerorganization"."organization_id" = "organizations_organization"."id") - LEFT OUTER JOIN "partners_plannedengagement" ON ("partners_partnerorganization"."id" = "partners_plannedengagement"."partner_id") - LEFT OUTER JOIN "t2f_travelactivity" ON ( "t2f_travelactivity"."partner_id" = "partners_plannedengagement"."partner_id" ) - INNER JOIN "t2f_travelactivity_travels" ON ("t2f_travelactivity"."id" = "t2f_travelactivity_travels"."travelactivity_id") - INNER JOIN "t2f_travel" ON ("t2f_travelactivity_travels"."travel_id" = "t2f_travel"."id") - ORDER BY "partners_partnerorganization"."id" ASC + "organizations_organization"."id", + "organizations_organization"."created", + "organizations_organization"."modified", + "organizations_organization"."name", + "organizations_organization"."vendor_number", + "organizations_organization"."organization_type", + "organizations_organization"."cso_type", + "organizations_organization"."short_name", + "organizations_organization"."other", + "organizations_organization"."parent_id", -""" + "partners_plannedengagement"."id", + "partners_plannedengagement"."created", + "partners_plannedengagement"."modified", + "partners_plannedengagement"."spot_check_planned_q1", + "partners_plannedengagement"."spot_check_planned_q2", + "partners_plannedengagement"."spot_check_planned_q3", + "partners_plannedengagement"."spot_check_planned_q4", + "partners_plannedengagement"."scheduled_audit", + "partners_plannedengagement"."special_audit", + "partners_plannedengagement"."spot_check_follow_up", + "partners_plannedengagement"."partner_id" + FROM "partners_partnerorganization" + LEFT OUTER JOIN "reports_office" ON ("partners_partnerorganization"."lead_office_id" = "reports_office"."id") + LEFT OUTER JOIN "reports_sector" ON ("partners_partnerorganization"."lead_section_id" = "reports_sector"."id") + INNER JOIN "organizations_organization" ON ("partners_partnerorganization"."organization_id" = "organizations_organization"."id") + LEFT OUTER JOIN "partners_plannedengagement" ON ("partners_partnerorganization"."id" = "partners_plannedengagement"."partner_id") + ORDER BY "partners_partnerorganization"."id" ASC + LIMIT ##PAGE_SIZE## OFFSET ##PAGE_OFFSET## -class PartnerLoader(EtoolsLoader): + -- Travel Activity + SELECT '##COUNTRY##' AS __schema, + "t2f_travelactivity"."id", + "t2f_travelactivity"."travel_type", + "t2f_travelactivity"."date", + "t2f_travelactivity"."partner_id", + "t2f_travelactivity"."partnership_id", + "t2f_travelactivity"."primary_traveler_id", + "t2f_travelactivity"."result_id" + FROM "t2f_travelactivity" + INNER JOIN "t2f_travelactivity_travels" ON ("t2f_travelactivity"."id" = "t2f_travelactivity_travels"."travelactivity_id") + INNER JOIN "t2f_travel" ON ("t2f_travelactivity_travels"."travel_id" = "t2f_travel"."id") + WHERE ("t2f_travelactivity"."date" IS NOT NULL AND "t2f_travelactivity"."travel_type" = 'Programmatic Visit' + AND "t2f_travel"."status" = 'completed' AND "t2f_travel"."traveler_id" = ("t2f_travelactivity"."primary_traveler_id") + AND "t2f_travelactivity"."partner_id" IN (##PARTNER_ID_LIST_IN_THE_PAGE##) + ORDER BY "t2f_travelactivity"."date" DESC + + """ + def get_queryset(self): return ( PartnersPartnerorganization.objects.select_related( diff --git a/src/etools_datamart/apps/mart/data/models/reports_office.py b/src/etools_datamart/apps/mart/data/models/reports_office.py index d208ae429..30f05535a 100644 --- a/src/etools_datamart/apps/mart/data/models/reports_office.py +++ b/src/etools_datamart/apps/mart/data/models/reports_office.py @@ -6,23 +6,27 @@ class OfficeLoader(EtoolsLoader): + """ + -- Office queries; + -- To be run per country schema + SET search_path = public,##COUNTRY## + -- Count for paging + SELECT COUNT(*) AS "__count" FROM "reports_office" + -- + SELECT '##COUNTRY##' AS __schema, + "reports_office"."id", + "reports_office"."name" + FROM "reports_office" + ORDER BY "reports_office"."id" ASC + LIMIT ##PAGE_SIZE## OFFSET ##PAGE_OFFSET##; + """ + def get_queryset(self): return ReportsOffice.objects.all() class Office(EtoolsDataMartModel): name = models.CharField(max_length=254, null=True, blank=True) - """ - SET search_path = public, - SELECT COUNT(*) AS "__count" FROM "reports_office" - - SELECT '' AS __schema, - "reports_office"."id", - "reports_office"."name" - FROM "reports_office" - ORDER BY "reports_office"."id" ASC - """ - loader = OfficeLoader() class Options: From da7aab21545574b20c533f01c2ed2bfe1a809f8c Mon Sep 17 00:00:00 2001 From: Hakan Date: Wed, 4 Dec 2024 17:13:56 +0300 Subject: [PATCH 05/15] add fmquestion, update actionpoint and intervention --- .../apps/mart/data/models/actionpoint.py | 218 +++++++++ .../apps/mart/data/models/fm_questions.py | 273 +++++++++++ .../apps/mart/data/models/intervention.py | 431 +++++++++++++++++- 3 files changed, 921 insertions(+), 1 deletion(-) diff --git a/src/etools_datamart/apps/mart/data/models/actionpoint.py b/src/etools_datamart/apps/mart/data/models/actionpoint.py index b9471dfc6..824e3999b 100644 --- a/src/etools_datamart/apps/mart/data/models/actionpoint.py +++ b/src/etools_datamart/apps/mart/data/models/actionpoint.py @@ -48,6 +48,224 @@ RELATED_MODULE_NAMES = [c.__name__ for c in RELATED_MODULES] RELATED_MODULE_CHOICES = zip(RELATED_MODULE_NAMES, RELATED_MODULE_NAMES) +""" +-- Set country schema +SET search_path = public, ##COUNTRY##; + +-- Count for paging; +SELECT COUNT(*) AS "__count" FROM "action_points_actionpoint" + +-- ActionPoint +SELECT '##COUNTRY##' AS __schema, + "action_points_actionpoint"."id", + "action_points_actionpoint"."created", + "action_points_actionpoint"."modified", + "action_points_actionpoint"."status", + "action_points_actionpoint"."description", + "action_points_actionpoint"."due_date", + "action_points_actionpoint"."date_of_completion", + + "action_points_actionpoint"."assigned_by_id", + "assigned_by_auth_user"."password", + "assigned_by_auth_user"."last_login", + "assigned_by_auth_user"."is_superuser", + "assigned_by_auth_user"."username", + "assigned_by_auth_user"."first_name", + "assigned_by_auth_user"."last_name", + "assigned_by_auth_user"."email", + "assigned_by_auth_user"."is_staff", + "assigned_by_auth_user"."is_active", + "assigned_by_auth_user"."date_joined", + "assigned_by_auth_user"."middle_name", + "assigned_by_auth_user"."created", + "assigned_by_auth_user"."modified", + "assigned_by_auth_user"."preferences" + + "action_points_actionpoint"."assigned_to_id", + "assigned_to_auth_user"."password", + "assigned_to_auth_user"."last_login", + "assigned_to_auth_user"."is_superuser", + "assigned_to_auth_user"."username", + "assigned_to_auth_user"."first_name", + "assigned_to_auth_user"."last_name", + "assigned_to_auth_user"."email", + "assigned_to_auth_user"."is_staff", + "assigned_to_auth_user"."is_active", + "assigned_to_auth_user"."date_joined", + "assigned_to_auth_user"."middle_name", + "assigned_to_auth_user"."created", + "assigned_to_auth_user"."modified", + "assigned_to_auth_user"."preferences" + + "action_points_actionpoint"."author_id", + "author_auth_user"."password", + "author_auth_user"."last_login", + "author_auth_user"."is_superuser", + "author_auth_user"."username", + "author_auth_user"."first_name", + "author_auth_user"."last_name", + "author_auth_user"."email", + "author_auth_user"."is_staff", + "author_auth_user"."is_active", + "author_auth_user"."date_joined", + "author_auth_user"."middle_name", + "author_auth_user"."created", + "author_auth_user"."modified", + "author_auth_user"."preferences" + + "action_points_actionpoint"."cp_output_id", + "reports_result"."name", + "reports_result"."code", + "reports_result"."result_type_id", + "reports_result"."sector_id", + "reports_result"."gic_code", + "reports_result"."gic_name", + "reports_result"."humanitarian_tag", + "reports_result"."level", + "reports_result"."lft", + "reports_result"."parent_id", + "reports_result"."rght", + "reports_result"."sic_code", + "reports_result"."sic_name", + "reports_result"."tree_id", + "reports_result"."vision_id", + "reports_result"."wbs", + "reports_result"."activity_focus_code", + "reports_result"."activity_focus_name", + "reports_result"."hidden", + "reports_result"."from_date", + "reports_result"."to_date", + "reports_result"."ram", + "reports_result"."country_programme_id", + "reports_result"."created", + "reports_result"."modified", + "reports_result"."humanitarian_marker_code", + "reports_result"."humanitarian_marker_name", + "reports_result"."programme_area_code", + "reports_result"."programme_area_name" + + "action_points_actionpoint"."engagement_id", + "action_points_actionpoint"."intervention_id", + "action_points_actionpoint"."location_id", + "action_points_actionpoint"."office_id", + + "action_points_actionpoint"."partner_id", + "partners_partnerorganization"."id", + "partners_partnerorganization"."description", + "partners_partnerorganization"."address", + "partners_partnerorganization"."email", + "partners_partnerorganization"."phone_number", + "partners_partnerorganization"."alternate_id", + "partners_partnerorganization"."alternate_name", + "partners_partnerorganization"."rating", + "partners_partnerorganization"."core_values_assessment_date", + "partners_partnerorganization"."vision_synced", + "partners_partnerorganization"."type_of_assessment", + "partners_partnerorganization"."last_assessment_date", + "partners_partnerorganization"."hidden", + "partners_partnerorganization"."deleted_flag", + "partners_partnerorganization"."total_ct_cp", + "partners_partnerorganization"."total_ct_cy", + "partners_partnerorganization"."blocked", + "partners_partnerorganization"."city", + "partners_partnerorganization"."country", + "partners_partnerorganization"."postal_code", + "partners_partnerorganization"."shared_with", + "partners_partnerorganization"."street_address", + "partners_partnerorganization"."hact_values", + "partners_partnerorganization"."created", + "partners_partnerorganization"."modified", + "partners_partnerorganization"."net_ct_cy", + "partners_partnerorganization"."reported_cy", + "partners_partnerorganization"."total_ct_ytd", + "partners_partnerorganization"."basis_for_risk_rating", + "partners_partnerorganization"."manually_blocked", + "partners_partnerorganization"."outstanding_dct_amount_6_to_9_months_usd", + "partners_partnerorganization"."outstanding_dct_amount_more_than_9_months_usd", + "partners_partnerorganization"."highest_risk_rating_name", + "partners_partnerorganization"."highest_risk_rating_type", + "partners_partnerorganization"."psea_assessment_date", + "partners_partnerorganization"."sea_risk_rating_name", + "partners_partnerorganization"."lead_office_id", + "partners_partnerorganization"."lead_section_id", + + "partners_partnerorganization"."organization_id" + "organizations_organization"."created", + "organizations_organization"."modified", + "organizations_organization"."name", + "organizations_organization"."vendor_number", + "organizations_organization"."organization_type", + "organizations_organization"."cso_type", + "organizations_organization"."short_name", + "organizations_organization"."other", + "organizations_organization"."parent_id" + + + "action_points_actionpoint"."section_id", + + "action_points_actionpoint"."tpm_activity_id", + + "action_points_actionpoint"."high_priority", + + "action_points_actionpoint"."travel_activity_id", + "t2f_travelactivity"."travel_type", + "t2f_travelactivity"."date", + "t2f_travelactivity"."partner_id", + "t2f_travelactivity"."partnership_id", + "t2f_travelactivity"."primary_traveler_id", + "t2f_travelactivity"."result_id", + + + "action_points_actionpoint"."category_id", + + "action_points_actionpoint"."psea_assessment_id", + + "action_points_actionpoint"."reference_number", + + "action_points_actionpoint"."monitoring_activity_id" + +FROM "action_points_actionpoint" + "assigned_by_auth_user" + "assigned_to_auth_user" + "assigned_to_auth_user" + "reports_result" + "partners_partnerorganization" + "organizations_organization" + "t2f_travelactivity" + +ORDER BY "action_points_actionpoint"."id" ASC +LIMIT ##PAGE_SIZE## OFFSET ##PAGE_OFFSET##; + +-- + +-- +SELECT "django_content_type"."id", + "django_content_type"."app_label", + "django_content_type"."model" +FROM "django_content_type" +WHERE ("django_content_type"."app_label" = 'action_points' + AND "django_content_type"."model" = 'actionpoint') + +SELECT '##COUNTRY##' AS __schema, + "django_comments"."id", + "django_comments"."object_pk", + "django_comments"."user_name", + "django_comments"."user_email", + "django_comments"."user_url", + "django_comments"."comment", + "django_comments"."submit_date", + "django_comments"."ip_address", + "django_comments"."is_public", + "django_comments"."is_removed", + "django_comments"."content_type_id", + "django_comments"."site_id", + "django_comments"."user_id" +FROM "django_comments" +WHERE ("django_comments"."content_type_id" = 270 +AND "django_comments"."object_pk" = '2') + +""" + class ActionPointLoader(EtoolsLoader): def get_reference_number(self, record: ActionPointsActionpoint, values: dict, **kwargs): diff --git a/src/etools_datamart/apps/mart/data/models/fm_questions.py b/src/etools_datamart/apps/mart/data/models/fm_questions.py index 6213bf0f2..e26de9844 100644 --- a/src/etools_datamart/apps/mart/data/models/fm_questions.py +++ b/src/etools_datamart/apps/mart/data/models/fm_questions.py @@ -48,6 +48,279 @@ def extract_longitude(location): class FMQuestionLoader(EtoolsLoader): + """ + SELECT '##COUNTRY##' AS __schema, + "field_monitoring_data_collection_finding"."id", + "field_monitoring_data_collection_finding"."value", + "field_monitoring_data_collection_finding"."activity_question_id", + "field_monitoring_data_collection_finding"."started_checklist_id", + "field_monitoring_settings_locationsite"."name" AS "site_name", + "locations_location"."name" AS "location_name", + + (SELECT U0."narrative_finding" + FROM "field_monitoring_data_collection_checklistoverallfinding" U0 + WHERE (U0."started_checklist_id" = ("field_monitoring_data_collection_finding"."started_checklist_id") + AND (U0."partner_id" = ("field_monitoring_data_collection_activityquestion"."partner_id") + OR U0."cp_output_id" = ("field_monitoring_data_collection_activityquestion"."cp_output_id") + OR U0."intervention_id" = ("field_monitoring_data_collection_activityquestion"."intervention_id"))) LIMIT 1) AS "narrative_overall_finding", + + "field_monitoring_data_collection_finding"."value" AS "myvalue", + + "field_monitoring_data_collection_activityquestion"."specific_details", + "field_monitoring_data_collection_activityquestion"."is_enabled", + "field_monitoring_data_collection_activityquestion"."cp_output_id", + "field_monitoring_data_collection_activityquestion"."intervention_id", + "field_monitoring_data_collection_activityquestion"."monitoring_activity_id", + "field_monitoring_data_collection_activityquestion"."partner_id", + "field_monitoring_data_collection_activityquestion"."question_id", + "field_monitoring_data_collection_activityquestion"."is_hact", + "field_monitoring_data_collection_activityquestion"."text", + + "reports_result"."name", "reports_result"."code", + "reports_result"."result_type_id", + "reports_result"."sector_id", + "reports_result"."gic_code", + "reports_result"."gic_name", + "reports_result"."humanitarian_tag", + "reports_result"."level", "reports_result"."lft", + "reports_result"."parent_id", + "reports_result"."rght", + "reports_result"."sic_code", + "reports_result"."sic_name", + "reports_result"."tree_id", + "reports_result"."vision_id", + "reports_result"."wbs", + "reports_result"."activity_focus_code", + "reports_result"."activity_focus_name", + "reports_result"."hidden", + "reports_result"."from_date", + "reports_result"."to_date", + "reports_result"."ram", + "reports_result"."country_programme_id", + "reports_result"."created", + "reports_result"."modified", + "reports_result"."humanitarian_marker_code", + "reports_result"."humanitarian_marker_name", + "reports_result"."programme_area_code", + "reports_result"."programme_area_name", + + "partners_intervention"."id", + "partners_intervention"."created", + "partners_intervention"."modified", + "partners_intervention"."document_type", + "partners_intervention"."number", + "partners_intervention"."title", + "partners_intervention"."status", + "partners_intervention"."start", + "partners_intervention"."end", + "partners_intervention"."submission_date", + "partners_intervention"."submission_date_prc", + "partners_intervention"."review_date_prc", + "partners_intervention"."prc_review_document", + "partners_intervention"."signed_by_unicef_date", + "partners_intervention"."signed_by_partner_date", + "partners_intervention"."population_focus", + "partners_intervention"."agreement_id", + "partners_intervention"."unicef_signatory_id", + "partners_intervention"."signed_pd_document", + "partners_intervention"."country_programme_id", + "partners_intervention"."contingency_pd", + "partners_intervention"."metadata", + "partners_intervention"."in_amendment", + "partners_intervention"."reference_number_year", + "partners_intervention"."activation_letter", + "partners_intervention"."termination_doc", + "partners_intervention"."cfei_number", + "partners_intervention"."budget_owner_id", + "partners_intervention"."context", + "partners_intervention"."date_sent_to_partner", + "partners_intervention"."equity_narrative", + "partners_intervention"."equity_rating", + "partners_intervention"."gender_narrative", + "partners_intervention"."gender_rating", + "partners_intervention"."hq_support_cost", + "partners_intervention"."implementation_strategy", + "partners_intervention"."ip_program_contribution", + "partners_intervention"."partner_accepted", + "partners_intervention"."sustainability_narrative", + "partners_intervention"."sustainability_rating", + "partners_intervention"."unicef_accepted", + "partners_intervention"."unicef_court", + "partners_intervention"."unicef_review_type", + "partners_intervention"."humanitarian_flag", + "partners_intervention"."capacity_development", + "partners_intervention"."other_info", + "partners_intervention"."other_partners_involved", + "partners_intervention"."technical_guidance", + "partners_intervention"."cash_transfer_modalities", + "partners_intervention"."cancel_justification", + "partners_intervention"."date_partnership_review_performed", + "partners_intervention"."accepted_on_behalf_of_partner", + "partners_intervention"."activation_protocol", + "partners_intervention"."confidential", + "partners_intervention"."has_activities_involving_children", + "partners_intervention"."has_data_processing_agreement", + "partners_intervention"."has_special_conditions_for_construction", + "partners_intervention"."final_review_approved", "partners_intervention"."other_details", + "partners_intervention"."partner_authorized_officer_signatory_id", + + + "field_monitoring_planning_monitoringactivity"."id", + "field_monitoring_planning_monitoringactivity"."created", + "field_monitoring_planning_monitoringactivity"."modified", + "field_monitoring_planning_monitoringactivity"."deleted_at", + "field_monitoring_planning_monitoringactivity"."monitor_type", + "field_monitoring_planning_monitoringactivity"."start_date", + "field_monitoring_planning_monitoringactivity"."end_date", + "field_monitoring_planning_monitoringactivity"."status", + "field_monitoring_planning_monitoringactivity"."location_id", + "field_monitoring_planning_monitoringactivity"."location_site_id", + "field_monitoring_planning_monitoringactivity"."visit_lead_id", + "field_monitoring_planning_monitoringactivity"."tpm_partner_id", + "field_monitoring_planning_monitoringactivity"."cancel_reason", + "field_monitoring_planning_monitoringactivity"."reject_reason", + "field_monitoring_planning_monitoringactivity"."field_office_id", + "field_monitoring_planning_monitoringactivity"."report_reject_reason", + "field_monitoring_planning_monitoringactivity"."number", 'botswana' AS __schema, + + "locations_location"."id", + "locations_location"."name", + "locations_location"."latitude", + "locations_location"."longitude", + "locations_location"."p_code", + "locations_location"."point", + "locations_location"."geom", + "locations_location"."level", + "locations_location"."lft", + "locations_location"."parent_id", + "locations_location"."rght", + "locations_location"."tree_id", + "locations_location"."created", + "locations_location"."modified", + "locations_location"."is_active", + "locations_location"."admin_level", + "locations_location"."admin_level_name", + + "field_monitoring_settings_locationsite"."id", " + "field_monitoring_settings_locationsite"."created", + "field_monitoring_settings_locationsite"."modified", + "field_monitoring_settings_locationsite"."name", + "field_monitoring_settings_locationsite"."p_code", + "field_monitoring_settings_locationsite"."point", + "field_monitoring_settings_locationsite"."is_active", + "field_monitoring_settings_locationsite"."parent_id", + + "partners_partnerorganization"."id", + "partners_partnerorganization"."description", + "partners_partnerorganization"."address", + "partners_partnerorganization"."email", + "partners_partnerorganization"."phone_number", + "partners_partnerorganization"."alternate_id", + "partners_partnerorganization"."alternate_name", + "partners_partnerorganization"."rating", + "partners_partnerorganization"."core_values_assessment_date", + "partners_partnerorganization"."vision_synced", + "partners_partnerorganization"."type_of_assessment", + "partners_partnerorganization"."last_assessment_date", + "partners_partnerorganization"."hidden", + "partners_partnerorganization"."deleted_flag", + "partners_partnerorganization"."total_ct_cp", + "partners_partnerorganization"."total_ct_cy", + "partners_partnerorganization"."blocked", + "partners_partnerorganization"."city", + "partners_partnerorganization"."country", + "partners_partnerorganization"."postal_code", + "partners_partnerorganization"."shared_with", + "partners_partnerorganization"."street_address", + "partners_partnerorganization"."hact_values", + "partners_partnerorganization"."created", + "partners_partnerorganization"."modified", + "partners_partnerorganization"."net_ct_cy", + "partners_partnerorganization"."reported_cy", + "partners_partnerorganization"."total_ct_ytd", + "partners_partnerorganization"."basis_for_risk_rating", + "partners_partnerorganization"."manually_blocked", + "partners_partnerorganization"."outstanding_dct_amount_6_to_9_months_usd", + "partners_partnerorganization"."outstanding_dct_amount_more_than_9_months_usd", + "partners_partnerorganization"."highest_risk_rating_name", + "partners_partnerorganization"."highest_risk_rating_type", + "partners_partnerorganization"."psea_assessment_date", + "partners_partnerorganization"."sea_risk_rating_name", + "partners_partnerorganization"."lead_office_id", + "partners_partnerorganization"."lead_section_id", + "partners_partnerorganization"."organization_id", + + "organizations_organization"."id", + "organizations_organization"."created", + "organizations_organization"."modified", + "organizations_organization"."name", + "organizations_organization"."vendor_number", + "organizations_organization"."organization_type", + "organizations_organization"."cso_type", + "organizations_organization"."short_name", + "organizations_organization"."other", + "organizations_organization"."parent_id", + + "field_monitoring_settings_question"."id", + "field_monitoring_settings_question"."answer_type", + "field_monitoring_settings_question"."choices_size", + "field_monitoring_settings_question"."level", + "field_monitoring_settings_question"."text", + "field_monitoring_settings_question"."is_hact", + "field_monitoring_settings_question"."is_custom", + "field_monitoring_settings_question"."is_active", + "field_monitoring_settings_question"."category_id", + + "field_monitoring_settings_category"."id", + "field_monitoring_settings_category"."order", + "field_monitoring_settings_category"."name", + + "field_monitoring_data_collection_activityquestionoverallfinding"."id", + "field_monitoring_data_collection_activityquestionoverallfinding"."value", + "field_monitoring_data_collection_activityquestionoverallfinding"."activity_question_id", + + "field_monitoring_data_collection_startedchecklist"."id", + "field_monitoring_data_collection_startedchecklist"."information_source", + "field_monitoring_data_collection_startedchecklist"."author_id", + "field_monitoring_data_collection_startedchecklist"."method_id", + "field_monitoring_data_collection_startedchecklist"."monitoring_activity_id", + + "field_monitoring_settings_method"."id", + "field_monitoring_settings_method"."name", + "field_monitoring_settings_method"."use_information_source", + "field_monitoring_settings_method"."short_name" + + FROM "field_monitoring_data_collection_finding" + INNER JOIN "field_monitoring_data_collection_activityquestion" ON ("field_monitoring_data_collection_finding"."activity_question_id" = "field_monitoring_data_collection_activityquestion"."id") INNER JOIN "field_monitoring_planning_monitoringactivity" ON ("field_monitoring_data_collection_activityquestion"."monitoring_activity_id" = "field_monitoring_planning_monitoringactivity"."id") + LEFT OUTER JOIN "field_monitoring_settings_locationsite" ON ("field_monitoring_planning_monitoringactivity"."location_site_id" = "field_monitoring_settings_locationsite"."id") + LEFT OUTER JOIN "locations_location" ON ("field_monitoring_planning_monitoringactivity"."location_id" = "locations_location"."id") + INNER JOIN "field_monitoring_data_collection_startedchecklist" ON ("field_monitoring_data_collection_finding"."started_checklist_id" = "field_monitoring_data_collection_startedchecklist"."id") LEFT OUTER JOIN "partners_partnerorganization" ON ("field_monitoring_data_collection_activityquestion"."partner_id" = "partners_partnerorganization"."id") + LEFT OUTER JOIN "reports_result" ON ("field_monitoring_data_collection_activityquestion"."cp_output_id" = "reports_result"."id") LEFT OUTER JOIN "partners_intervention" ON ("field_monitoring_data_collection_activityquestion"."intervention_id" = "partners_intervention"."id") LEFT OUTER JOIN "organizations_organization" ON ("partners_partnerorganization"."organization_id" = "organizations_organization"."id") INNER JOIN "field_monitoring_settings_question" ON ("field_monitoring_data_collection_activityquestion"."question_id" = "field_monitoring_settings_question"."id") INNER JOIN "field_monitoring_settings_category" ON ("field_monitoring_settings_question"."category_id" = "field_monitoring_settings_category"."id") LEFT OUTER JOIN "field_monitoring_data_collection_activityquestionoverallfinding" ON ("field_monitoring_data_collection_activityquestion"."id" = "field_monitoring_data_collection_activityquestionoverallfinding"."activity_question_id") INNER JOIN "field_monitoring_settings_method" ON ("field_monitoring_data_collection_startedchecklist"."method_id" = "field_monitoring_settings_method"."id") + ORDER BY "field_monitoring_data_collection_finding"."id" ASC LIMIT 66 + + + SELECT '##COUNTRY##' AS __schema, + "field_monitoring_settings_question_methods"."id", + "field_monitoring_settings_question_methods"."question_id", + "field_monitoring_settings_question_methods"."method_id" + FROM "field_monitoring_settings_question_methods" + WHERE "field_monitoring_settings_question_methods"."question_id" IN (##LIST OF "field_monitoring_settings_question"."id" IN THE PAGE##); + + + SELECT '##COUNTRY##' AS __schema, + "field_monitoring_settings_option"."id", + "field_monitoring_settings_option"."label", + "field_monitoring_settings_option"."value", + "field_monitoring_settings_option"."question_id" + FROM "field_monitoring_settings_option" + WHERE "field_monitoring_settings_option"."question_id" IN (##LIST OF "field_monitoring_settings_question"."id" IN THE PAGE##); + + + SELECT "field_monitoring_data_collection_finding"."id" FROM "field_monitoring_data_collection_finding" INNER JOIN "field_monitoring_data_collection_activityquestion" ON ("field_monitoring_data_collection_finding"."activity_question_id" = "field_monitoring_data_collection_activityquestion"."id") INNER JOIN "field_monitoring_planning_monitoringactivity" ON ("field_monitoring_data_collection_activityquestion"."monitoring_activity_id" = "field_monitoring_planning_monitoringactivity"."id") LEFT OUTER JOIN "field_monitoring_settings_locationsite" ON ("field_monitoring_planning_monitoringactivity"."location_site_id" = "field_monitoring_settings_locationsite"."id") LEFT OUTER JOIN "locations_location" ON ("field_monitoring_planning_monitoringactivity"."location_id" = "locations_location"."id") + + + """ + """Loader for FM Questions""" TRANSACTION_BY_BATCH = True diff --git a/src/etools_datamart/apps/mart/data/models/intervention.py b/src/etools_datamart/apps/mart/data/models/intervention.py index 0e5e81711..cc96671ea 100644 --- a/src/etools_datamart/apps/mart/data/models/intervention.py +++ b/src/etools_datamart/apps/mart/data/models/intervention.py @@ -239,8 +239,9 @@ class InterventionLoader(NestedLocationLoaderMixin, EtoolsLoader): "users_country"."custom_dashboards" FROM "users_country" WHERE "users_country"."schema_name" = '##COUNTRY##' LIMIT 21 + -- Set country schema + SET search_path = public, ##COUNTRY##; -- TODO: Pick only the required fields - SET search_path = public, albania; SELECT '##COUNTRY##' AS __schema, "partners_intervention"."id", "partners_intervention"."created", @@ -858,6 +859,434 @@ class Options(InterventionAbstract.Options): class InterventionByLocationLoader(InterventionLoader): + """ + -- To select the country schema + SET search_path = public,##COUNTRY##; + + -- Count for paging + SELECT COUNT(*) AS "__count" FROM "partners_intervention" + + -- Paged retreival + -- TODO: Determine the minimal number of fields. + SELECT 'afghanistan' AS __schema, + "partners_intervention"."id", + "partners_intervention"."created", + "partners_intervention"."modified", + "partners_intervention"."document_type", + "partners_intervention"."number", + "partners_intervention"."title", + "partners_intervention"."status", + "partners_intervention"."start", + "partners_intervention"."end", + "partners_intervention"."submission_date", + "partners_intervention"."submission_date_prc", + "partners_intervention"."review_date_prc", + "partners_intervention"."prc_review_document", + "partners_intervention"."signed_by_unicef_date", + "partners_intervention"."signed_by_partner_date", + "partners_intervention"."population_focus", + "partners_intervention"."agreement_id", + "partners_intervention"."unicef_signatory_id", + "partners_intervention"."signed_pd_document", + "partners_intervention"."country_programme_id", + "partners_intervention"."contingency_pd", + "partners_intervention"."metadata", + "partners_intervention"."in_amendment", + "partners_intervention"."reference_number_year", + "partners_intervention"."activation_letter", + "partners_intervention"."termination_doc", + "partners_intervention"."cfei_number", + "partners_intervention"."budget_owner_id", + "partners_intervention"."context", + "partners_intervention"."date_sent_to_partner", + "partners_intervention"."equity_narrative", + "partners_intervention"."equity_rating", + "partners_intervention"."gender_narrative", + "partners_intervention"."gender_rating", + "partners_intervention"."hq_support_cost", + "partners_intervention"."implementation_strategy", + "partners_intervention"."ip_program_contribution", + "partners_intervention"."partner_accepted", + "partners_intervention"."sustainability_narrative", + "partners_intervention"."sustainability_rating", + "partners_intervention"."unicef_accepted", + "partners_intervention"."unicef_court", + "partners_intervention"."unicef_review_type", + "partners_intervention"."humanitarian_flag", + "partners_intervention"."capacity_development", + "partners_intervention"."other_info", + "partners_intervention"."other_partners_involved", + "partners_intervention"."technical_guidance", + "partners_intervention"."cash_transfer_modalities", + "partners_intervention"."cancel_justification", + "partners_intervention"."date_partnership_review_performed", + "partners_intervention"."accepted_on_behalf_of_partner", + "partners_intervention"."activation_protocol", + "partners_intervention"."confidential", + "partners_intervention"."has_activities_involving_children", + "partners_intervention"."has_data_processing_agreement", + "partners_intervention"."has_special_conditions_for_construction", + "partners_intervention"."final_review_approved", + "partners_intervention"."other_details", + "partners_intervention"."partner_authorized_officer_signatory_id", + + "partners_agreement"."id", + "partners_agreement"."created", + "partners_agreement"."modified", + "partners_agreement"."start", + "partners_agreement"."end", + "partners_agreement"."agreement_type", + "partners_agreement"."agreement_number", + "partners_agreement"."attached_agreement", + "partners_agreement"."signed_by_unicef_date", + "partners_agreement"."signed_by_partner_date", + "partners_agreement"."partner_id", + "partners_agreement"."signed_by_id", + "partners_agreement"."status", + "partners_agreement"."country_programme_id", + "partners_agreement"."reference_number_year", + "partners_agreement"."special_conditions_pca", + "partners_agreement"."terms_acknowledged_by_id", + "partners_agreement"."partner_manager_id", + + "partners_partnerorganization"."id", + "partners_partnerorganization"."description", + "partners_partnerorganization"."address", + "partners_partnerorganization"."email", + "partners_partnerorganization"."phone_number", + "partners_partnerorganization"."alternate_id", + "partners_partnerorganization"."alternate_name", + "partners_partnerorganization"."rating", + "partners_partnerorganization"."core_values_assessment_date", + "partners_partnerorganization"."vision_synced", + "partners_partnerorganization"."type_of_assessment", + "partners_partnerorganization"."last_assessment_date", + "partners_partnerorganization"."hidden", + "partners_partnerorganization"."deleted_flag", + "partners_partnerorganization"."total_ct_cp", + "partners_partnerorganization"."total_ct_cy", + "partners_partnerorganization"."blocked", + "partners_partnerorganization"."city", + "partners_partnerorganization"."country", + "partners_partnerorganization"."postal_code", + "partners_partnerorganization"."shared_with", + "partners_partnerorganization"."street_address", + "partners_partnerorganization"."hact_values", + "partners_partnerorganization"."created", + "partners_partnerorganization"."modified", + "partners_partnerorganization"."net_ct_cy", + "partners_partnerorganization"."reported_cy", + "partners_partnerorganization"."total_ct_ytd", + "partners_partnerorganization"."basis_for_risk_rating", + "partners_partnerorganization"."manually_blocked", + "partners_partnerorganization"."outstanding_dct_amount_6_to_9_months_usd", + "partners_partnerorganization"."outstanding_dct_amount_more_than_9_months_usd", + "partners_partnerorganization"."highest_risk_rating_name", + "partners_partnerorganization"."highest_risk_rating_type", + "partners_partnerorganization"."psea_assessment_date", + "partners_partnerorganization"."sea_risk_rating_name", + "partners_partnerorganization"."lead_office_id", + "partners_partnerorganization"."lead_section_id", + "partners_partnerorganization"."organization_id", + + "organizations_organization"."id", + "organizations_organization"."created", + "organizations_organization"."modified", + "organizations_organization"."name", + "organizations_organization"."vendor_number", + "organizations_organization"."organization_type", + "organizations_organization"."cso_type", + "organizations_organization"."short_name", + "organizations_organization"."other", + "organizations_organization"."parent_id", + + "auth_user"."id", + "auth_user"."password", + "auth_user"."last_login", + "auth_user"."is_superuser", + "auth_user"."username", + "auth_user"."first_name", + "auth_user"."last_name", + "auth_user"."email", + "auth_user"."is_staff", + "auth_user"."is_active", + "auth_user"."date_joined", + "auth_user"."middle_name", + "auth_user"."created", + "auth_user"."modified", + "auth_user"."preferences", + + "reports_countryprogramme"."id", + "reports_countryprogramme"."name", + "reports_countryprogramme"."wbs", + "reports_countryprogramme"."from_date", + "reports_countryprogramme"."to_date", + "reports_countryprogramme"."invalid", + + AO."id", + AO."password", + AO."last_login", + AO."is_superuser", + AO."username", + AO."first_name", + AO."last_name", + AO."email", + AO."is_staff", + AO."is_active", + AO."date_joined", + AO."middle_name", + AO."created", + AO."modified", + AO."preferences" + FROM "partners_intervention" + INNER JOIN "partners_agreement" ON ("partners_intervention"."agreement_id" = "partners_agreement"."id") + INNER JOIN "partners_partnerorganization" ON ("partners_agreement"."partner_id" = "partners_partnerorganization"."id") + INNER JOIN "organizations_organization" ON ("partners_partnerorganization"."organization_id" = "organizations_organization"."id") + LEFT OUTER JOIN "auth_user" ON ("partners_intervention"."unicef_signatory_id" = "auth_user"."id") + LEFT OUTER JOIN "reports_countryprogramme" ON ("partners_intervention"."country_programme_id" = "reports_countryprogramme"."id") + LEFT OUTER JOIN "auth_user" AO ON ("partners_intervention"."partner_authorized_officer_signatory_id" = AO."id") + ORDER BY "partners_intervention"."id" ASC + LIMIT ##PAGE_SIZE## OFFSET ##PAGE_OFFSET## + + + -- + SELECT "partners_interventionbudget"."id", + "partners_interventionbudget"."partner_contribution", + "partners_interventionbudget"."unicef_cash", + "partners_interventionbudget"."in_kind_amount", + "partners_interventionbudget"."partner_contribution_local", + "partners_interventionbudget"."unicef_cash_local", + "partners_interventionbudget"."in_kind_amount_local", + "partners_interventionbudget"."total", + "partners_interventionbudget"."intervention_id", + "partners_interventionbudget"."total_local", + "partners_interventionbudget"."currency" + FROM "partners_interventionbudget" + WHERE "partners_interventionbudget"."intervention_id" IN (##PARTNER_INTERVENTION_IDs_IN_THE_PAGE## ) + + + -- + SELECT "partners_interventionamendment"."id", + "partners_interventionamendment"."signed_date", + "partners_interventionamendment"."intervention_id", + "partners_interventionamendment"."types" + FROM "partners_interventionamendment" + WHERE "partners_interventionamendment"."intervention_id" IN (##PARTNER_INTERVENTION_IDs_IN_THE_PAGE##) + ORDER BY "partners_interventionamendment"."signed_date" ASC; + + -- + SELECT "funds_fundsreservationheader"."id", + "funds_fundsreservationheader"."fr_number", + "funds_fundsreservationheader"."intervention_id", + "funds_fundsreservationheader"."outstanding_amt_local" + FROM "funds_fundsreservationheader" + WHERE "funds_fundsreservationheader"."intervention_id" IN (##PARTNER_INTERVENTION_IDs_IN_THE_PAGE##); + + + -- + SELECT "partners_interventionattachment"."id", + "partners_interventionattachment"."intervention_id", + "partners_interventionattachment"."type_id" + FROM "partners_interventionattachment" + WHERE "partners_interventionattachment"."intervention_id" IN (##PARTNER_INTERVENTION_IDs_IN_THE_PAGE##); + + + -- + SELECT "partners_interventionplannedvisits"."id", + "partners_interventionplannedvisits"."intervention_id", + "partners_interventionplannedvisits"."programmatic_q1", + "partners_interventionplannedvisits"."programmatic_q2", + "partners_interventionplannedvisits"."programmatic_q3" + FROM "partners_interventionplannedvisits" + WHERE ("partners_interventionplannedvisits"."year" = ##YEAR## + AND "partners_interventionplannedvisits"."intervention_id" IN (##PARTNER_INTERVENTION_IDs_IN_THE_PAGE##)); + + + -- + SELECT "t2f_travelactivity"."id", + "t2f_travelactivity"."travel_type", + "t2f_travelactivity"."date", + "t2f_travelactivity"."partnership_id" + FROM "t2f_travelactivity" + INNER JOIN "t2f_travelactivity_travels" ON ("t2f_travelactivity"."id" = "t2f_travelactivity_travels"."travelactivity_id") + INNER JOIN "t2f_travel" ON ("t2f_travelactivity_travels"."travel_id" = "t2f_travel"."id") + WHERE ("t2f_travelactivity"."date" IS NOT NULL + AND "t2f_travelactivity"."travel_type" = 'Programmatic Visit' + AND "t2f_travel"."status" = 'completed' + AND "t2f_travelactivity"."partnership_id" IN (##PARTNERSHIP_IDs_IN_THE_PAGE##)) + ORDER BY "t2f_travelactivity"."date" DESC; + + + -- + SELECT '##COUNTRY##' AS __schema, + "partners_interventionresultlink"."id", + "partners_interventionresultlink"."cp_output_id", + "partners_interventionresultlink"."intervention_id", + "partners_interventionresultlink"."created", + "partners_interventionresultlink"."modified", + "partners_interventionresultlink"."code" + FROM "partners_interventionresultlink" + WHERE "partners_interventionresultlink"."intervention_id" IN (##PARTNER_INTERVENTION_IDs_IN_THE_PAGE##); + + + -- + SELECT '##COUNTRY##' AS __schema, + "reports_lowerresult"."id", + "reports_lowerresult"."name", + "reports_lowerresult"."code", + "reports_lowerresult"."result_link_id", + "reports_lowerresult"."created", + "reports_lowerresult"."modified", + "reports_lowerresult"."is_active" + FROM "reports_lowerresult" + WHERE "reports_lowerresult"."result_link_id" IN (##INTERVENTION__RESULT_LINK_IDs_IN_THE_PAGE##); + + + -- + SELECT '##COUNTRY##' AS __schema, + "reports_appliedindicator"."id", + "reports_appliedindicator"."context_code", + "reports_appliedindicator"."assumptions", + "reports_appliedindicator"."total", + "reports_appliedindicator"."indicator_id", + "reports_appliedindicator"."lower_result_id", + "reports_appliedindicator"."means_of_verification", + "reports_appliedindicator"."cluster_indicator_id", + "reports_appliedindicator"."cluster_indicator_title", + "reports_appliedindicator"."cluster_name", + "reports_appliedindicator"."created", + "reports_appliedindicator"."modified", + "reports_appliedindicator"."response_plan_name", + "reports_appliedindicator"."section_id", + "reports_appliedindicator"."is_active", + "reports_appliedindicator"."is_high_frequency", + "reports_appliedindicator"."baseline", + "reports_appliedindicator"."denominator_label", + "reports_appliedindicator"."label", + "reports_appliedindicator"."measurement_specifications", + "reports_appliedindicator"."numerator_label", + "reports_appliedindicator"."target" + FROM "reports_appliedindicator" + WHERE "reports_appliedindicator"."lower_result_id" IN (##REPORTS_LOWERRESULT_IDs_IN_THE_PAGE##); + + + -- + SELECT '##COUNTRY##' AS __schema, + "partners_intervention_sections"."id", + "partners_intervention_sections"."intervention_id", + "partners_intervention_sections"."section_id" + FROM "partners_intervention_sections" + WHERE "partners_intervention_sections"."intervention_id" IN (##PARTNER_INTERVENTION_IDs_IN_THE_PAGE##); + + + -- + SELECT '##COUNTRY##' AS __schema, + "partners_intervention_offices"."id", + "partners_intervention_offices"."intervention_id", + "partners_intervention_offices"."office_id" + FROM "partners_intervention_offices" + WHERE "partners_intervention_offices"."intervention_id" IN (##PARTNER_INTERVENTION_IDs_IN_THE_PAGE##) + ORDER BY "partners_intervention_offices"."id" ASC; + + + -- + SELECT '##COUNTRY##' AS __schema, + "partners_intervention_unicef_focal_points"."id", + "partners_intervention_unicef_focal_points"."intervention_id", + "partners_intervention_unicef_focal_points"."user_id" + FROM "partners_intervention_unicef_focal_points" + WHERE "partners_intervention_unicef_focal_points"."intervention_id" IN (##PARTNER_INTERVENTION_IDs_IN_THE_PAGE##); + + + -- auth_user for partners_intervention_unicef_focal_points + SELECT "auth_user"."id", + "auth_user"."username", + "auth_user"."first_name", + "auth_user"."last_name", + "auth_user"."email" + FROM "auth_user" WHERE "auth_user"."id" IN (##LIST OF partners_intervention_unicef_focal_points"."user_id IN THE PAGE##) + + + -- + SELECT "partners_intervention_partner_focal_points"."id", + "partners_intervention_partner_focal_points"."intervention_id", + "partners_intervention_partner_focal_points"."user_id" + FROM "partners_intervention_partner_focal_points" + WHERE "partners_intervention_partner_focal_points"."intervention_id" IN (##PARTNER_INTERVENTION_IDs_IN_THE_PAGE##); + + + -- auth_use for partners_intervention_partner_focal_points + SELECT "auth_user"."id", + "auth_user"."username", + "auth_user"."first_name", + "auth_user"."last_name", + "auth_user"."email" + FROM "auth_user" + WHERE "auth_user"."id" IN (##LIST OF "partners_intervention_partner_focal_points"."user_id" IN THE PAGE ##) + + + -- ???? + SELECT "users_userprofile"."id", + "users_userprofile"."phone_number", + "users_userprofile"."user_id" + FROM "users_userprofile" + WHERE "users_userprofile"."user_id" IN (?????) + + + -- + SELECT "partners_intervention_flat_locations"."id", + "partners_intervention_flat_locations"."intervention_id", + "partners_intervention_flat_locations"."location_id" + FROM "partners_intervention_flat_locations" + WHERE "partners_intervention_flat_locations"."intervention_id" IN (##PARTNER_INTERVENTION_IDs_IN_THE_PAGE##) + + + -- + SELECT "locations_location"."id", + "locations_location"."name", + "locations_location"."latitude", + "locations_location"."longitude", + "locations_location"."p_code", + "locations_location"."admin_level", + "locations_location"."admin_level_name" + FROM "locations_location" WHERE "locations_location"."id" IN (##LIST OF "partners_intervention_flat_locations"."location_id IN THE PAGE##) + + + -- + SELECT '##COUNTRY##' AS __schema, + "partners_interventionreview"."id", + "partners_interventionreview"."created", + "partners_interventionreview"."modified", + "partners_interventionreview"."review_type", + "partners_interventionreview"."overall_approval", + "partners_interventionreview"."amendment_id", + "partners_interventionreview"."intervention_id", + "partners_interventionreview"."actions_list", + "partners_interventionreview"."budget_is_aligned", + "partners_interventionreview"."ges_considered", + "partners_interventionreview"."meeting_date", + "partners_interventionreview"."overall_approver_id", + "partners_interventionreview"."overall_comment", + "partners_interventionreview"."partner_comparative_advantage", + "partners_interventionreview"."pd_is_guided", + "partners_interventionreview"."pd_is_relevant", + "partners_interventionreview"."relationship_is_represented", + "partners_interventionreview"."relationships_are_positive", + "partners_interventionreview"."supply_issues_considered", + "partners_interventionreview"."submitted_by_id", + "partners_interventionreview"."review_date", + "partners_interventionreview"."sent_back_comment" + FROM "partners_interventionreview" + WHERE "partners_interventionreview"."intervention_id" IN (##PARTNER_INTERVENTION_IDs_IN_THE_PAGE##) + + -- + SELECT "reports_result"."id", + "reports_result"."name", + "reports_result"."wbs" + FROM "reports_result" + WHERE "reports_result"."id" IN (????) + """ + def get_values(self, record): values = super().get_values(record) values["location"] = Location.objects.filter( From 6b9da875e10144c57e40e9686febafe57dc383b0 Mon Sep 17 00:00:00 2001 From: Hakan Date: Thu, 5 Dec 2024 15:55:30 +0300 Subject: [PATCH 06/15] document queries for engagement --- .../apps/mart/data/models/audit_engagement.py | 350 ++++++++++++++++++ 1 file changed, 350 insertions(+) diff --git a/src/etools_datamart/apps/mart/data/models/audit_engagement.py b/src/etools_datamart/apps/mart/data/models/audit_engagement.py index fdf8da475..45d07fc38 100644 --- a/src/etools_datamart/apps/mart/data/models/audit_engagement.py +++ b/src/etools_datamart/apps/mart/data/models/audit_engagement.py @@ -160,6 +160,356 @@ def get_status(self, record, values, **kwargs): class EngagementlLoader(EngagementMixin, EtoolsLoader): + """ + -- Set country schema + SET search_path = public, ##COUNTRY##; + + -- Count for paging; + SELECT COUNT(*) AS "__count" FROM "audit_engagement"; + + -- Audit + + SELECT '##COUNTRY##' AS __schema, + "audit_microassessment"."engagement_ptr_id", + "audit_microassessment"."questionnaire_version", + + "audit_engagement"."id", + "audit_engagement"."created", + "audit_engagement"."modified", + "audit_engagement"."status", + "audit_engagement"."partner_contacted_at", + "audit_engagement"."engagement_type", + "audit_engagement"."start_date", + "audit_engagement"."end_date", + "audit_engagement"."total_value", + "audit_engagement"."date_of_field_visit", + "audit_engagement"."date_of_draft_report_to_ip", + "audit_engagement"."date_of_comments_by_ip", + "audit_engagement"."date_of_draft_report_to_unicef", + "audit_engagement"."date_of_comments_by_unicef", + "audit_engagement"."date_of_report_submit", + "audit_engagement"."date_of_final_report", + "audit_engagement"."date_of_cancel", + "audit_engagement"."amount_refunded", + "audit_engagement"."additional_supporting_documentation_provided", + "audit_engagement"."justification_provided_and_accepted", + "audit_engagement"."write_off_required", + "audit_engagement"."cancel_comment", + "audit_engagement"."explanation_for_additional_information", + "audit_engagement"."partner_id", "audit_engagement"."joint_audit", + "audit_engagement"."agreement_id", "audit_engagement"."po_item_id", + "audit_engagement"."shared_ip_with", "audit_engagement"."exchange_rate", + "audit_engagement"."currency_of_report", + "audit_engagement"."reference_number", + "audit_engagement"."year_of_audit", + + "partners_partnerorganization"."id", + "partners_partnerorganization"."description", + "partners_partnerorganization"."address", + "partners_partnerorganization"."email", + "partners_partnerorganization"."phone_number", + "partners_partnerorganization"."alternate_id", + "partners_partnerorganization"."alternate_name", + "partners_partnerorganization"."rating", + "partners_partnerorganization"."core_values_assessment_date", + "partners_partnerorganization"."vision_synced", + "partners_partnerorganization"."type_of_assessment", + "partners_partnerorganization"."last_assessment_date", + "partners_partnerorganization"."hidden", + "partners_partnerorganization"."deleted_flag", + "partners_partnerorganization"."total_ct_cp", + "partners_partnerorganization"."total_ct_cy", + "partners_partnerorganization"."blocked", + "partners_partnerorganization"."city", + "partners_partnerorganization"."country", + "partners_partnerorganization"."postal_code", + "partners_partnerorganization"."shared_with", + "partners_partnerorganization"."street_address", + "partners_partnerorganization"."hact_values", + "partners_partnerorganization"."created", + "partners_partnerorganization"."modified", + "partners_partnerorganization"."net_ct_cy", + "partners_partnerorganization"."reported_cy", + "partners_partnerorganization"."total_ct_ytd", + "partners_partnerorganization"."basis_for_risk_rating", + "partners_partnerorganization"."manually_blocked", + "partners_partnerorganization"."outstanding_dct_amount_6_to_9_months_usd", + "partners_partnerorganization"."outstanding_dct_amount_more_than_9_months_usd", + "partners_partnerorganization"."highest_risk_rating_name", + "partners_partnerorganization"."highest_risk_rating_type", + "partners_partnerorganization"."psea_assessment_date", + "partners_partnerorganization"."sea_risk_rating_name", + "partners_partnerorganization"."lead_office_id", + "partners_partnerorganization"."lead_section_id", + "partners_partnerorganization"."organization_id", + + "purchase_order_purchaseorder"."id", + "purchase_order_purchaseorder"."created", + "purchase_order_purchaseorder"."modified", + "purchase_order_purchaseorder"."order_number", + "purchase_order_purchaseorder"."contract_start_date", + "purchase_order_purchaseorder"."contract_end_date", + "purchase_order_purchaseorder"."auditor_firm_id", + "purchase_order_auditorfirm"."id", + "purchase_order_auditorfirm"."created", + "purchase_order_auditorfirm"."modified", + "purchase_order_auditorfirm"."street_address", + "purchase_order_auditorfirm"."city", + "purchase_order_auditorfirm"."postal_code", + "purchase_order_auditorfirm"."country", + "purchase_order_auditorfirm"."email", + "purchase_order_auditorfirm"."phone_number", + "purchase_order_auditorfirm"."blocked", + "purchase_order_auditorfirm"."hidden", + "purchase_order_auditorfirm"."deleted_flag", + "purchase_order_auditorfirm"."vision_synced", + "purchase_order_auditorfirm"."unicef_users_allowed", + "purchase_order_auditorfirm"."organization_id", + + "organizations_organization"."id", + "organizations_organization"."created", + "organizations_organization"."modified", + "organizations_organization"."name", + "organizations_organization"."vendor_number", + "organizations_organization"."organization_type", + "organizations_organization"."cso_type", + "organizations_organization"."short_name", + "organizations_organization"."other", + "organizations_organization"."parent_id", + + "purchase_order_purchaseorderitem"."id", + "purchase_order_purchaseorderitem"."number", + "purchase_order_purchaseorderitem"."purchase_order_id" + + FROM "audit_microassessment" + INNER JOIN "audit_engagement" ON ("audit_microassessment"."engagement_ptr_id" = "audit_engagement"."id") + INNER JOIN "partners_partnerorganization" ON ("audit_engagement"."partner_id" = "partners_partnerorganization"."id") + INNER JOIN "purchase_order_purchaseorder" ON ("audit_engagement"."agreement_id" = "purchase_order_purchaseorder"."id") + INNER JOIN "purchase_order_auditorfirm" ON ("purchase_order_purchaseorder"."auditor_firm_id" = "purchase_order_auditorfirm"."id") + INNER JOIN "organizations_organization" ON ("purchase_order_auditorfirm"."organization_id" = "organizations_organization"."id") + LEFT OUTER JOIN "purchase_order_purchaseorderitem" ON ("audit_engagement"."po_item_id" = "purchase_order_purchaseorderitem"."id") + ORDER BY "audit_engagement"."id" ASC + LIMIT ##PAGE_SIZE## OFFSET ##PAGE_OFFSET##; + + -- Authorized officers for the page + SELECT ("audit_engagement_authorized_officers"."engagement_id") AS "_prefetch_related_val_engagement_id", + "auth_user"."id", + "auth_user"."password", + "auth_user"."last_login", + "auth_user"."is_superuser", + "auth_user"."username", + "auth_user"."first_name", + "auth_user"."last_name", + "auth_user"."email", + "auth_user"."is_staff", + "auth_user"."is_active", + "auth_user"."date_joined", + "auth_user"."middle_name", + "auth_user"."created", + "auth_user"."modified", + "auth_user"."preferences" + FROM "auth_user" + INNER JOIN "audit_engagement_authorized_officers" ON ("auth_user"."id" = "audit_engagement_authorized_officers"."user_id") + WHERE "audit_engagement_authorized_officers"."engagement_id" IN ( ##LIST OF ENGAGEMENT_IDs IN THE PAGE## ); + + -- Authorized staff members for the page + SELECT ("audit_engagement_staff_members"."engagement_id") AS "_prefetch_related_val_engagement_id", + "auth_user"."id", + "auth_user"."password", + "auth_user"."last_login", + "auth_user"."is_superuser", + "auth_user"."username", + "auth_user"."first_name", + "auth_user"."last_name", + "auth_user"."email", + "auth_user"."is_staff", + "auth_user"."is_active", + "auth_user"."date_joined", + "auth_user"."middle_name", + "auth_user"."created", + "auth_user"."modified", + "auth_user"."preferences" + FROM "auth_user" + INNER JOIN "audit_engagement_staff_members" ON ("auth_user"."id" = "audit_engagement_staff_members"."user_id") + WHERE "audit_engagement_staff_members"."engagement_id" IN IN ( ##LIST OF ENGAGEMENT_IDs IN THE PAGE## ); + + + -- Audit Engagement Sections for the page + SELECT '##COUNTRY##' AS __schema, + "audit_engagement_sections"."id", + "audit_engagement_sections"."engagement_id", + "audit_engagement_sections"."section_id" + FROM "audit_engagement_sections" + WHERE "audit_engagement_sections"."engagement_id" IN ( ##LIST OF ENGAGEMENT_IDs IN THE PAGE## ); + + + -- action_points_actionpoint for the page + SELECT '##COUNTRY##' AS __schema, "action_points_actionpoint"."id", + "action_points_actionpoint"."created", + "action_points_actionpoint"."modified", + "action_points_actionpoint"."status", + "action_points_actionpoint"."description", + "action_points_actionpoint"."due_date", + "action_points_actionpoint"."date_of_completion", + "action_points_actionpoint"."assigned_by_id", + "action_points_actionpoint"."assigned_to_id", + "action_points_actionpoint"."author_id", + "action_points_actionpoint"."cp_output_id", + "action_points_actionpoint"."engagement_id", + "action_points_actionpoint"."intervention_id", + "action_points_actionpoint"."location_id", + "action_points_actionpoint"."office_id", + "action_points_actionpoint"."partner_id", + "action_points_actionpoint"."section_id", + "action_points_actionpoint"."tpm_activity_id", + "action_points_actionpoint"."high_priority", + "action_points_actionpoint"."travel_activity_id", + "action_points_actionpoint"."category_id", + "action_points_actionpoint"."psea_assessment_id", + "action_points_actionpoint"."reference_number", + "action_points_actionpoint"."monitoring_activity_id" + FROM "action_points_actionpoint" + WHERE "action_points_actionpoint"."engagement_id" IN ( ##LIST OF ENGAGEMENT_IDs IN THE PAGE## ); + + + -- audit_engagement_active_pd for the page + SELECT '##COUNTRY##' AS __schema, + "audit_engagement_active_pd"."id", + "audit_engagement_active_pd"."engagement_id", + "audit_engagement_active_pd"."intervention_id" + FROM "audit_engagement_active_pd" + WHERE "audit_engagement_active_pd"."engagement_id" IN ( ##LIST OF ENGAGEMENT_IDs IN THE PAGE## ); + + + -- + SELECT '##COUNTRY##' AS __schema, "audit_risk"."id", + "audit_risk"."value", + "audit_risk"."extra", + "audit_risk"."blueprint_id", + "audit_risk"."engagement_id" + FROM "audit_risk" + INNER JOIN "audit_riskblueprint" ON ("audit_risk"."blueprint_id" = "audit_riskblueprint"."id") + INNER JOIN "audit_riskcategory" ON ("audit_riskblueprint"."category_id" = "audit_riskcategory"."id") + WHERE ("audit_riskcategory"."header" = 'Key Internal Controls Weaknesses' AND "audit_risk"."engagement_id" + IN (##LIST OF ENGAGEMENT_IDs IN THE PAGE##)) + + + -- + SELECT "organizations_organization"."id", + "organizations_organization"."created", + "organizations_organization"."modified", + "organizations_organization"."name", + "organizations_organization"."vendor_number", + "organizations_organization"."organization_type", + "organizations_organization"."cso_type", + "organizations_organization"."short_name", + "organizations_organization"."other", + "organizations_organization"."parent_id" + FROM "organizations_organization" WHERE "organizations_organization"."id" + IN (##LIST OF "organizations_organization"."id" in tje main recordset IN THE PAGE ## ); + + + -- + SELECT '##COUNTRY##' AS __schema, + "audit_engagement_sections"."id", + "audit_engagement_sections"."engagement_id", + "audit_engagement_sections"."section_id" + FROM "audit_engagement_sections" + WHERE "audit_engagement_sections"."engagement_id" IN ( ##LIST OF ENGAGEMENT_IDs IN THE PAGE## ); + + + -- + SELECT "django_content_type"."id", + "django_content_type"."app_label", + "django_content_type"."model" + FROM "django_content_type" + WHERE ("django_content_type"."app_label" = 'audit' AND "django_content_type"."model" = 'engagement'); + + + -- + SELECT "unicef_attachments_attachment"."file" + FROM "unicef_attachments_attachment" + WHERE ("unicef_attachments_attachment"."code" = 'audit_engagement' + AND "unicef_attachments_attachment"."content_type_id" = 216 + AND "unicef_attachments_attachment"."object_id" IN ( ##LIST OF ENGAGEMENT_IDs IN THE PAGE## ) + + -- + SELECT "unicef_attachments_attachment"."file" + FROM "unicef_attachments_attachment" + WHERE ("unicef_attachments_attachment"."code" = 'audit_report' + AND "unicef_attachments_attachment"."content_type_id" = 216 + AND "unicef_attachments_attachment"."object_id" IN ( ##LIST OF ENGAGEMENT_IDs IN THE PAGE## ) + + + -- + SELECT '##COUNTRY##' AS __schema, + "partners_intervention"."id", + "partners_intervention"."created", + "partners_intervention"."modified", + "partners_intervention"."document_type", + "partners_intervention"."number", + "partners_intervention"."title", + "partners_intervention"."status", + "partners_intervention"."start", + "partners_intervention"."end", + "partners_intervention"."submission_date", + "partners_intervention"."submission_date_prc", + "partners_intervention"."review_date_prc", + "partners_intervention"."prc_review_document", + "partners_intervention"."signed_by_unicef_date", + "partners_intervention"."signed_by_partner_date", + "partners_intervention"."population_focus", + "partners_intervention"."agreement_id", + "partners_intervention"."unicef_signatory_id", + "partners_intervention"."signed_pd_document", + "partners_intervention"."country_programme_id", + "partners_intervention"."contingency_pd", + "partners_intervention"."metadata", + "partners_intervention"."in_amendment", + "partners_intervention"."reference_number_year", + "partners_intervention"."activation_letter", + "partners_intervention"."termination_doc", + "partners_intervention"."cfei_number", + "partners_intervention"."budget_owner_id", + "partners_intervention"."context", + "partners_intervention"."date_sent_to_partner", + "partners_intervention"."equity_narrative", + "partners_intervention"."equity_rating", + "partners_intervention"."gender_narrative", + "partners_intervention"."gender_rating", + "partners_intervention"."hq_support_cost", + "partners_intervention"."implementation_strategy", + "partners_intervention"."ip_program_contribution", + "partners_intervention"."partner_accepted", + "partners_intervention"."sustainability_narrative", + "partners_intervention"."sustainability_rating", + "partners_intervention"."unicef_accepted", + "partners_intervention"."unicef_court", + "partners_intervention"."unicef_review_type", + "partners_intervention"."humanitarian_flag", + "partners_intervention"."capacity_development", + "partners_intervention"."other_info", + "partners_intervention"."other_partners_involved", + "partners_intervention"."technical_guidance", + "partners_intervention"."cash_transfer_modalities", + "partners_intervention"."cancel_justification", + "partners_intervention"."date_partnership_review_performed", + "partners_intervention"."accepted_on_behalf_of_partner", + "partners_intervention"."activation_protocol", + "partners_intervention"."confidential", + "partners_intervention"."has_activities_involving_children", + "partners_intervention"."has_data_processing_agreement", + "partners_intervention"."has_special_conditions_for_construction", + "partners_intervention"."final_review_approved", + "partners_intervention"."other_details", + "partners_intervention"."partner_authorized_officer_signatory_id" + FROM "partners_intervention" + WHERE ( "partners_intervention"."id" IN ( ##LIST OF "action_points_actionpoint"."intervention_id" in action_points_actionpoint for the page ## ) + OR partners_intervention"."id" IN ( ##LIST OF "audit_engagement_active_pd"."intervention_id" in audit_engagement_active_pd for the page ## ) + ); + + """ + def get_content_type(self, sub_type): mapping = { AuditAudit: "audit", From a273a905adc3d9272a4221f4ff2ffadb3a79e715 Mon Sep 17 00:00:00 2001 From: Hakan Date: Sun, 8 Dec 2024 17:32:03 +0300 Subject: [PATCH 07/15] add audit_microassessment, audit_financial_finding --- .../apps/mart/data/models/audit_audit.py | 4 +- .../data/models/audit_financial_finding.py | 49 ++++++ .../data/models/audit_micro_assessment.py | 161 ++++++++++++++++++ 3 files changed, 213 insertions(+), 1 deletion(-) diff --git a/src/etools_datamart/apps/mart/data/models/audit_audit.py b/src/etools_datamart/apps/mart/data/models/audit_audit.py index 376addb76..9abf6a982 100644 --- a/src/etools_datamart/apps/mart/data/models/audit_audit.py +++ b/src/etools_datamart/apps/mart/data/models/audit_audit.py @@ -25,8 +25,10 @@ class AuditLoader(EngagementMixin, EtoolsLoader): """ -- Set country schema SET search_path = public, ##COUNTRY##; + -- Count for paging; SELECT COUNT(*) AS "__count" FROM "audit_audit"; + -- Audit SELECT '##COUNTRY##' AS __schema, "audit_audit"."engagement_ptr_id", @@ -168,6 +170,7 @@ class AuditLoader(EngagementMixin, EtoolsLoader): FROM "audit_engagement_offices" WHERE "audit_engagement_sections"."engagement_id" in (##LIST_OF_ENAGAGEMENT_IDs_IN_THE_PAGE##); + --Audit Financial Findings: Summing can be left to (T)ransform stage SELECT "audit_financialfinding"."audit_id", SUM("audit_financialfinding"."amount") as amount_sum @@ -211,7 +214,6 @@ class AuditLoader(EngagementMixin, EtoolsLoader): WHERE "action_points_actionpoint"."engagement_id" in (##LIST_OF_ENAGAGEMENT_IDs_IN_THE_PAGE##) GROUP BY "action_points_actionpoint"."engagement_id", "categories_category"."description" ORDER BY "action_points_actionpoint"."engagement_id", "categories_category"."description" ASC - """ def process_country(self): diff --git a/src/etools_datamart/apps/mart/data/models/audit_financial_finding.py b/src/etools_datamart/apps/mart/data/models/audit_financial_finding.py index 8452a1e1d..023298d56 100644 --- a/src/etools_datamart/apps/mart/data/models/audit_financial_finding.py +++ b/src/etools_datamart/apps/mart/data/models/audit_financial_finding.py @@ -15,6 +15,55 @@ class AuditFinancialfindingLoader(EtoolsLoader): + """ + + -- To list contries to iterate through. + SELECT "users_country"."id", + "users_country"."schema_name", + "users_country"."name", + "users_country"."business_area_code", + "users_country"."initial_zoom", + "users_country"."latitude", + "users_country"."longitude", + "users_country"."country_short_code", + "users_country"."vision_sync_enabled", + "users_country"."vision_last_synced", + "users_country"."local_currency_id", + "users_country"."long_name", + "users_country"."iso3_code", + "users_country"."custom_dashboards" + FROM "users_country" + WHERE NOT ("users_country"."schema_name" IN ('public')) + ORDER BY "users_country"."name" ASC; + + -- + SET search_path = public, ##COUNTRY##; + + -- + SELECT '##COUNTRY##' AS __schema, + "audit_financialfinding"."id", + "audit_financialfinding"."title", + "audit_financialfinding"."local_amount", + "audit_financialfinding"."amount", + "audit_financialfinding"."description", + "audit_financialfinding"."recommendation", + "audit_financialfinding"."ip_comments", + "audit_financialfinding"."audit_id" + FROM "audit_financialfinding" + ORDER BY "audit_financialfinding"."id" ASC + LIMIT ##PAGE_SIZE## OFFSET ##PAGE_OFFSET##; + + + -- Also FROM DATAMART DB; + SELECT source_id as audit_id, + auditor_number as partner_vendor_number, + auditor as partner_name, + reference_number as audit_reference_number, + status as audit_status + FROM data_audit + WHERE source_id in ##LIST OF "audit_financialfinding"."audit_id" IN THE PAGE##; + """ + def process_country(self): country = self.context["country"] batch_size = settings.RESULTSET_BATCH_SIZE diff --git a/src/etools_datamart/apps/mart/data/models/audit_micro_assessment.py b/src/etools_datamart/apps/mart/data/models/audit_micro_assessment.py index a5c291442..dc8aabced 100644 --- a/src/etools_datamart/apps/mart/data/models/audit_micro_assessment.py +++ b/src/etools_datamart/apps/mart/data/models/audit_micro_assessment.py @@ -21,6 +21,167 @@ class MicroAssessmentLoader(EngagementMixin, EtoolsLoader): + """ + -- + SET search_path = public, ##COUNTRY##; + + -- + SELECT COUNT(*) AS "__count" + FROM "audit_microassessment"; + + -- + SELECT '##COUNTRY##' AS __schema, + "audit_microassessment"."engagement_ptr_id", + "audit_microassessment"."questionnaire_version", + + "audit_engagement"."id", + "audit_engagement"."created", + "audit_engagement"."modified", + "audit_engagement"."status", + "audit_engagement"."partner_contacted_at", + "audit_engagement"."engagement_type", + "audit_engagement"."start_date", + "audit_engagement"."end_date", + "audit_engagement"."total_value", + "audit_engagement"."date_of_field_visit", + "audit_engagement"."date_of_draft_report_to_ip", + "audit_engagement"."date_of_comments_by_ip", + "audit_engagement"."date_of_draft_report_to_unicef", + "audit_engagement"."date_of_comments_by_unicef", + "audit_engagement"."date_of_report_submit", + "audit_engagement"."date_of_final_report", + "audit_engagement"."date_of_cancel", + "audit_engagement"."amount_refunded", + "audit_engagement"."additional_supporting_documentation_provided", + "audit_engagement"."justification_provided_and_accepted", + "audit_engagement"."write_off_required", + "audit_engagement"."cancel_comment", + "audit_engagement"."explanation_for_additional_information", + "audit_engagement"."partner_id", + "audit_engagement"."joint_audit", + "audit_engagement"."agreement_id", + "audit_engagement"."po_item_id", + "audit_engagement"."shared_ip_with", + "audit_engagement"."exchange_rate", + "audit_engagement"."currency_of_report", + "audit_engagement"."reference_number", + "audit_engagement"."year_of_audit" + FROM "audit_microassessment" + INNER JOIN "audit_engagement" ON ("audit_microassessment"."engagement_ptr_id" = "audit_engagement"."id") + ORDER BY "audit_microassessment"."engagement_ptr_id" ASC + LIMIT ##PAGE_SIZE## OFFSET ##PAGE_OFFSET##; + + + -- Partner organization records for audit_engagement records + SELECT '##COUNTRY##' AS __schema, + "partners_partnerorganization"."id", + "partners_partnerorganization"."description", + "partners_partnerorganization"."address", + "partners_partnerorganization"."email", + "partners_partnerorganization"."phone_number", + "partners_partnerorganization"."alternate_id", + "partners_partnerorganization"."alternate_name", + "partners_partnerorganization"."rating", + "partners_partnerorganization"."core_values_assessment_date", + "partners_partnerorganization"."vision_synced", + "partners_partnerorganization"."type_of_assessment", + "partners_partnerorganization"."last_assessment_date", + "partners_partnerorganization"."hidden", + "partners_partnerorganization"."deleted_flag", + "partners_partnerorganization"."total_ct_cp", + "partners_partnerorganization"."total_ct_cy", + "partners_partnerorganization"."blocked", + "partners_partnerorganization"."city", + "partners_partnerorganization"."country", + "partners_partnerorganization"."postal_code", + "partners_partnerorganization"."shared_with", + "partners_partnerorganization"."street_address", + "partners_partnerorganization"."hact_values", + "partners_partnerorganization"."created", + "partners_partnerorganization"."modified", + "partners_partnerorganization"."net_ct_cy", + "partners_partnerorganization"."reported_cy", + "partners_partnerorganization"."total_ct_ytd", + "partners_partnerorganization"."basis_for_risk_rating", + "partners_partnerorganization"."manually_blocked", + "partners_partnerorganization"."outstanding_dct_amount_6_to_9_months_usd", + "partners_partnerorganization"."outstanding_dct_amount_more_than_9_months_usd", + "partners_partnerorganization"."highest_risk_rating_name", + "partners_partnerorganization"."highest_risk_rating_type", + "partners_partnerorganization"."psea_assessment_date", + "partners_partnerorganization"."sea_risk_rating_name", + "partners_partnerorganization"."lead_office_id", + "partners_partnerorganization"."lead_section_id", + "partners_partnerorganization"."organization_id" + + "organizations_organization"."created", + "organizations_organization"."modified", + "organizations_organization"."name", + "organizations_organization"."vendor_number", + "organizations_organization"."organization_type", + "organizations_organization"."cso_type", + "organizations_organization"."short_name", + "organizations_organization"."other", + "organizations_organization"."parent_id" + FROM "partners_partnerorganization" + INNER JOIN "organizations_organization" ON ("partners_partnerorganization"."organization_id"="organizations_organization"."id") + WHERE "partners_partnerorganization"."id" IN (##LIST OF "audit_engagement"."partner_id" IN THE PAGE## ) + + -- + SELECT "purchase_order_purchaseorder"."id", + "purchase_order_purchaseorder"."created", + "purchase_order_purchaseorder"."modified", + "purchase_order_purchaseorder"."order_number", + "purchase_order_purchaseorder"."contract_start_date", + "purchase_order_purchaseorder"."contract_end_date", + "purchase_order_purchaseorder"."auditor_firm_id", + + "purchase_order_auditorfirm"."created", + "purchase_order_auditorfirm"."modified", + "purchase_order_auditorfirm"."street_address", + "purchase_order_auditorfirm"."city", + "purchase_order_auditorfirm"."postal_code", + "purchase_order_auditorfirm"."country", + "purchase_order_auditorfirm"."email", + "purchase_order_auditorfirm"."phone_number", + "purchase_order_auditorfirm"."blocked", + "purchase_order_auditorfirm"."hidden", + "purchase_order_auditorfirm"."deleted_flag", + "purchase_order_auditorfirm"."vision_synced", + "purchase_order_auditorfirm"."unicef_users_allowed", + "purchase_order_auditorfirm"."organization_id" + FROM "purchase_order_purchaseorder" + INNER JOIN "purchase_order_auditorfirm" ON ("purchase_order_purchaseorder"."auditor_firm_id"="purchase_order_auditorfirm"."id") + WHERE "purchase_order_purchaseorder"."id" IN (## LIST OF "audit_engagement"."agreement_id"## IN THE PAGE##); + + + SELECT 'afghanistan' AS __schema, + "audit_risk"."id", + "audit_risk"."value", + "audit_risk"."extra", + "audit_risk"."blueprint_id", + "audit_risk"."engagement_id" + FROM "audit_risk" + INNER JOIN "audit_riskblueprint" ON ("audit_risk"."blueprint_id" = "audit_riskblueprint"."id") + INNER JOIN "audit_riskcategory" ON ("audit_riskblueprint"."category_id" = "audit_riskcategory"."id") WHERE ("audit_riskcategory"."code" = 'ma_global_assessment' + AND "audit_risk"."engagement_id" IN (## LIST OF "audit_microassessment"."engagement_ptr_id" in the PAGE##))); + + + SELECT '##COUNTRY##' AS __schema, + "audit_riskblueprint"."id", + "audit_riskblueprint"."order", + "audit_riskblueprint"."weight", + "audit_riskblueprint"."is_key", + "audit_riskblueprint"."header", + "audit_riskblueprint"."description", + "audit_riskblueprint"."category_id" + FROM "audit_riskblueprint" + WHERE "audit_riskblueprint"."id" IN( ##LIST OF "audit_risk"."blueprint_id" IN THE PAGE##) + + + + """ + def process_country(self): batch_size = settings.RESULTSET_BATCH_SIZE logger.debug(f"Batch size:{batch_size}") From 0944fed69b5fe75719f382893c25191dbe7b0da8 Mon Sep 17 00:00:00 2001 From: Hakan Date: Mon, 9 Dec 2024 16:40:47 +0300 Subject: [PATCH 08/15] add queries for audit_result and audit_special --- .../apps/mart/data/models/audit_result.py | 125 ++++++++++++ .../apps/mart/data/models/audit_special.py | 179 ++++++++++++++++++ 2 files changed, 304 insertions(+) diff --git a/src/etools_datamart/apps/mart/data/models/audit_result.py b/src/etools_datamart/apps/mart/data/models/audit_result.py index 6f6fc5fa5..3973a562b 100644 --- a/src/etools_datamart/apps/mart/data/models/audit_result.py +++ b/src/etools_datamart/apps/mart/data/models/audit_result.py @@ -12,6 +12,131 @@ class AuditResultLoader(EtoolsLoader): + """ + -- + SET search_path = public, ##COUNTRY##; + + -- + SELECT COUNT(*) AS "__count" + FROM "audit_microassessment"; + + -- + SELECT '##COUNTRY##' AS __schema, + "audit_audit"."id", + "audit_audit"."engagement_ptr_id", + "audit_audit"."audited_expenditure", + "audit_audit"."financial_findings", + "audit_audit"."audit_opinion", + "audit_audit"."audited_expenditure_local", + "audit_audit"."financial_findings_local", + + "audit_engagement"."id", + "audit_engagement"."created", + "audit_engagement"."modified", + "audit_engagement"."status", + "audit_engagement"."partner_contacted_at", + "audit_engagement"."engagement_type", + "audit_engagement"."start_date", + "audit_engagement"."end_date", + "audit_engagement"."total_value", + "audit_engagement"."date_of_field_visit", + "audit_engagement"."date_of_draft_report_to_ip", + "audit_engagement"."date_of_comments_by_ip", + "audit_engagement"."date_of_draft_report_to_unicef", + "audit_engagement"."date_of_comments_by_unicef", + "audit_engagement"."date_of_report_submit", + "audit_engagement"."date_of_final_report", + "audit_engagement"."date_of_cancel", + "audit_engagement"."amount_refunded", + "audit_engagement"."additional_supporting_documentation_provided", + "audit_engagement"."justification_provided_and_accepted", + "audit_engagement"."write_off_required", + "audit_engagement"."cancel_comment", + "audit_engagement"."explanation_for_additional_information", + "audit_engagement"."partner_id", + "audit_engagement"."joint_audit", + "audit_engagement"."agreement_id", + "audit_engagement"."po_item_id", + "audit_engagement"."shared_ip_with", + "audit_engagement"."exchange_rate", + "audit_engagement"."currency_of_report", + "audit_engagement"."reference_number", + "audit_engagement"."year_of_audit", + + "partners_partnerorganization"."id", + "partners_partnerorganization"."description", + "partners_partnerorganization"."address", + "partners_partnerorganization"."email", + "partners_partnerorganization"."phone_number", + "partners_partnerorganization"."alternate_id", + "partners_partnerorganization"."alternate_name", + "partners_partnerorganization"."rating", + "partners_partnerorganization"."core_values_assessment_date", + "partners_partnerorganization"."vision_synced", + "partners_partnerorganization"."type_of_assessment", + "partners_partnerorganization"."last_assessment_date", + "partners_partnerorganization"."hidden", + "partners_partnerorganization"."deleted_flag", + "partners_partnerorganization"."total_ct_cp", + "partners_partnerorganization"."total_ct_cy", + "partners_partnerorganization"."blocked", + "partners_partnerorganization"."city", + "partners_partnerorganization"."country", + "partners_partnerorganization"."postal_code", + "partners_partnerorganization"."shared_with", + "partners_partnerorganization"."street_address", + "partners_partnerorganization"."hact_values", + "partners_partnerorganization"."created", + "partners_partnerorganization"."modified", + "partners_partnerorganization"."net_ct_cy", + "partners_partnerorganization"."reported_cy", + "partners_partnerorganization"."total_ct_ytd", + "partners_partnerorganization"."basis_for_risk_rating", + "partners_partnerorganization"."manually_blocked", + "partners_partnerorganization"."outstanding_dct_amount_6_to_9_months_usd", + "partners_partnerorganization"."outstanding_dct_amount_more_than_9_months_usd", + "partners_partnerorganization"."highest_risk_rating_name", + "partners_partnerorganization"."highest_risk_rating_type", + "partners_partnerorganization"."psea_assessment_date", + "partners_partnerorganization"."sea_risk_rating_name", + "partners_partnerorganization"."lead_office_id", + "partners_partnerorganization"."lead_section_id", + "partners_partnerorganization"."organization_id", + + "organizations_organization"."id", + "organizations_organization"."created", + "organizations_organization"."modified", + "organizations_organization"."name", + "organizations_organization"."vendor_number", + "organizations_organization"."organization_type", + "organizations_organization"."cso_type", + "organizations_organization"."short_name", + "organizations_organization"."other", + "organizations_organization"."parent_id" + FROM "audit_audit" + INNER JOIN "audit_engagement" ON ("audit_audit"."engagement_ptr_id" = "audit_engagement"."id") + INNER JOIN "partners_partnerorganization" ON ("audit_engagement"."partner_id" = "partners_partnerorganization"."id") + INNER JOIN "organizations_organization" ON ("partners_partnerorganization"."organization_id" = "organizations_organization"."id") + ORDER BY "audit_audit"."engagement_ptr_id" ASC + LIMIT ##PAGE_SIZE## OFFSET ##PAGE_OFFSET##; + + -- + SELECT * + FROM "audit_risk" + WHERE ("audit_risk"."engagement_id" IN (##LIST OF "audit_audit"."id" IN THE PAGE##) + AND "audit_risk"."value" = 4); + + -- + SELECT * + FROM "audit_financialfinding" + WHERE "audit_financialfinding"."audit_id" IN (##LIST OF "audit_audit"."id" IN THE PAGE##); + + -- + SELECT * + FROM "audit_keyinternalcontrol" + WHERE "audit_keyinternalcontrol"."audit_id" IN (##LIST OF "audit_audit"."id" IN THE PAGE##); + """ + def get_mart_values(self, record: AuditAudit = None): ret = super().get_mart_values(None) ret["source_id"] = record.engagement_ptr_id diff --git a/src/etools_datamart/apps/mart/data/models/audit_special.py b/src/etools_datamart/apps/mart/data/models/audit_special.py index e0cd3fe4d..091b4b7ee 100644 --- a/src/etools_datamart/apps/mart/data/models/audit_special.py +++ b/src/etools_datamart/apps/mart/data/models/audit_special.py @@ -21,6 +21,185 @@ class AuditSpecialLoader(EngagementMixin, EtoolsLoader): + """ + -- + SET search_path = public, ##COUNTRY##; + + -- + SELECT COUNT(*) AS "__count" + FROM "audit_specialaudit"; + + + SELECT '##COUNTRY##' AS __schema, + "audit_specialaudit"."engagement_ptr_id", + + "audit_engagement"."id", + "audit_engagement"."created", + "audit_engagement"."modified", + "audit_engagement"."status", + "audit_engagement"."partner_contacted_at", + "audit_engagement"."engagement_type", + "audit_engagement"."start_date", + "audit_engagement"."end_date", + "audit_engagement"."total_value", + "audit_engagement"."date_of_field_visit", + "audit_engagement"."date_of_draft_report_to_ip", + "audit_engagement"."date_of_comments_by_ip", + "audit_engagement"."date_of_draft_report_to_unicef", + "audit_engagement"."date_of_comments_by_unicef", + "audit_engagement"."date_of_report_submit", + "audit_engagement"."date_of_final_report", + "audit_engagement"."date_of_cancel", + "audit_engagement"."amount_refunded", + "audit_engagement"."additional_supporting_documentation_provided", + "audit_engagement"."justification_provided_and_accepted", + "audit_engagement"."write_off_required", + "audit_engagement"."cancel_comment", + "audit_engagement"."explanation_for_additional_information", + "audit_engagement"."partner_id", + "audit_engagement"."joint_audit", + "audit_engagement"."agreement_id", + "audit_engagement"."po_item_id", + "audit_engagement"."shared_ip_with", + "audit_engagement"."exchange_rate", + "audit_engagement"."currency_of_report", + "audit_engagement"."reference_number", + "audit_engagement"."year_of_audit", + + "purchase_order_purchaseorder"."id", + "purchase_order_purchaseorder"."created", + "purchase_order_purchaseorder"."modified", + "purchase_order_purchaseorder"."order_number", + "purchase_order_purchaseorder"."contract_start_date", + "purchase_order_purchaseorder"."contract_end_date", + "purchase_order_purchaseorder"."auditor_firm_id", + "purchase_order_auditorfirm"."id", + "purchase_order_auditorfirm"."created", + "purchase_order_auditorfirm"."modified", + "purchase_order_auditorfirm"."street_address", + "purchase_order_auditorfirm"."city", + "purchase_order_auditorfirm"."postal_code", + "purchase_order_auditorfirm"."country", + "purchase_order_auditorfirm"."email", + "purchase_order_auditorfirm"."phone_number", + "purchase_order_auditorfirm"."blocked", + "purchase_order_auditorfirm"."hidden", + "purchase_order_auditorfirm"."deleted_flag", + "purchase_order_auditorfirm"."vision_synced", + "purchase_order_auditorfirm"."unicef_users_allowed", + "purchase_order_auditorfirm"."organization_id", + + "organizations_organization"."id", + "organizations_organization"."created", + "organizations_organization"."modified", + "organizations_organization"."name", + "organizations_organization"."vendor_number", + "organizations_organization"."organization_type", + "organizations_organization"."cso_type", + "organizations_organization"."short_name", + "organizations_organization"."other", + "organizations_organization"."parent_id" + FROM "audit_specialaudit" + INNER JOIN "audit_engagement" ON ("audit_specialaudit"."engagement_ptr_id" = "audit_engagement"."id") + INNER JOIN "purchase_order_purchaseorder" ON ("audit_engagement"."agreement_id" = "purchase_order_purchaseorder"."id") + INNER JOIN "purchase_order_auditorfirm" ON ("purchase_order_purchaseorder"."auditor_firm_id" = "purchase_order_auditorfirm"."id") + INNER JOIN "organizations_organization" ON ("purchase_order_auditorfirm"."organization_id" = "organizations_organization"."id") + ORDER BY "audit_specialaudit"."engagement_ptr_id" ASC + LIMIT ##PAGE_SIZE## OFFSET ##PAGE_OFFSET##; + + -- + SELECT '##COUNTRY##' AS __schema, + "partners_partnerorganization"."id", + "partners_partnerorganization"."description", + "partners_partnerorganization"."address", + "partners_partnerorganization"."email", + "partners_partnerorganization"."phone_number", + "partners_partnerorganization"."alternate_id", + "partners_partnerorganization"."alternate_name", + "partners_partnerorganization"."rating", + "partners_partnerorganization"."core_values_assessment_date", + "partners_partnerorganization"."vision_synced", + "partners_partnerorganization"."type_of_assessment", + "partners_partnerorganization"."last_assessment_date", + "partners_partnerorganization"."hidden", + "partners_partnerorganization"."deleted_flag", + "partners_partnerorganization"."total_ct_cp", + "partners_partnerorganization"."total_ct_cy", + "partners_partnerorganization"."blocked", + "partners_partnerorganization"."city", + "partners_partnerorganization"."country", + "partners_partnerorganization"."postal_code", + "partners_partnerorganization"."shared_with", + "partners_partnerorganization"."street_address", + "partners_partnerorganization"."hact_values", + "partners_partnerorganization"."created", + "partners_partnerorganization"."modified", + "partners_partnerorganization"."net_ct_cy", + "partners_partnerorganization"."reported_cy", + "partners_partnerorganization"."total_ct_ytd", + "partners_partnerorganization"."basis_for_risk_rating", + "partners_partnerorganization"."manually_blocked", + "partners_partnerorganization"."outstanding_dct_amount_6_to_9_months_usd", + "partners_partnerorganization"."outstanding_dct_amount_more_than_9_months_usd", + "partners_partnerorganization"."highest_risk_rating_name", + "partners_partnerorganization"."highest_risk_rating_type", + "partners_partnerorganization"."psea_assessment_date", + "partners_partnerorganization"."sea_risk_rating_name", + "partners_partnerorganization"."lead_office_id", + "partners_partnerorganization"."lead_section_id", + "partners_partnerorganization"."organization_id" + FROM "partners_partnerorganization" + WHERE "partners_partnerorganization"."id IN ("## audit_engagement"."partner_id" IN THE PAGE##)"; + + -- + SELECT '##COUNTRY##' AS __schema, + "audit_engagement_sections"."id", + "audit_engagement_sections"."engagement_id", + "audit_engagement_sections"."section_id" + FROM "audit_engagement_sections" + WHERE "audit_engagement_sections"."engagement_id" IN (##"audit_engagement"."id" IN THE PAGE##); + + -- + SELECT '##COUNTRY##' AS __schema, + "audit_engagement_offices"."id", + "audit_engagement_offices"."engagement_id", + "audit_engagement_offices"."office_id" + FROM "audit_engagement_offices" + WHERE "audit_engagement_offices"."engagement_id" IN (##"audit_engagement"."id" IN THE PAGE##); + + -- + SELECT * FROM "audit_specialauditrecommendation" + WHERE "audit_specialauditrecommendation"."audit_id" IN (##"audit_engagement"."id" IN THE PAGE##); + + -- + SELECT "action_points_actionpoint"."engagement_id","action_points_actionpoint"."status", + COUNT("action_points_actionpoint"."status") AS "count" + FROM "action_points_actionpoint" + WHERE "action_points_actionpoint"."engagement_id" IN (##"audit_engagement"."id" IN THE PAGE##) + GROUP BY "action_points_actionpoint"."engagement_id","action_points_actionpoint"."status" + ORDER BY "action_points_actionpoint"."engagement_id","action_points_actionpoint"."status" ASC; + + -- + SELECT "action_points_actionpoint"."engagement_id","action_points_actionpoint"."high_priority", + COUNT("action_points_actionpoint"."high_priority") AS "count" + FROM "action_points_actionpoint" + WHERE "action_points_actionpoint"."engagement_id" IN (##"audit_engagement"."id" IN THE PAGE##) + GROUP BY "action_points_actionpoint"."engagement_id", "action_points_actionpoint"."high_priority" + ORDER BY "action_points_actionpoint"."engagement_id", "action_points_actionpoint"."high_priority" ASC; + + -- + SELECT "action_points_actionpoint"."engagement_id","categories_category"."description", + COUNT("categories_category"."description") AS "count" + FROM "action_points_actionpoint" + LEFT OUTER JOIN "categories_category" ON ("action_points_actionpoint"."category_id" = "categories_category"."id") + WHERE "action_points_actionpoint"."engagement_id" IN (##"audit_engagement"."id" IN THE PAGE##) + GROUP BY "action_points_actionpoint"."engagement_id","categories_category"."description" + ORDER BY "action_points_actionpoint"."engagement_id","categories_category"."description" ASC; + + -- Alternatively, entire action_points_actionpoint table can be loaded and aggregation can + -- be performed on Datamart by Analytics. + """ + def process_country(self): batch_size = settings.RESULTSET_BATCH_SIZE logger.debug(f"Batch size:{batch_size}") From d896d6031b1e0a987819aac35d38c956c0c4b053 Mon Sep 17 00:00:00 2001 From: Hakan Date: Tue, 10 Dec 2024 17:06:11 +0300 Subject: [PATCH 09/15] add queries for FAMIndicatorLoder --- .../apps/mart/data/models/fam.py | 136 ++++++++++++++++++ 1 file changed, 136 insertions(+) diff --git a/src/etools_datamart/apps/mart/data/models/fam.py b/src/etools_datamart/apps/mart/data/models/fam.py index f479cdff6..595039315 100644 --- a/src/etools_datamart/apps/mart/data/models/fam.py +++ b/src/etools_datamart/apps/mart/data/models/fam.py @@ -17,6 +17,142 @@ class FAMIndicatorLoader(EtoolsLoader): + """ + -- + SET search_path = public, ##COUNTRY##; + + -- + SELECT COUNT(*) AS "__count" + FROM "audit_spotcheck" + INNER JOIN "audit_engagement" ON ("audit_spotcheck"."engagement_ptr_id" = "audit_engagement"."id") + WHERE (EXTRACT(MONTH FROM "audit_engagement"."start_date") = ##CURRENT_MONTH## + AND "audit_engagement"."start_date" BETWEEN '##YEAR##-01-01'::date AND '##YEAR##-12-31'::date + AND "audit_engagement"."status" = 'partner_contacted'); + + -- + SELECT COUNT(*) AS "__count" + FROM "audit_spotcheck" + INNER JOIN "audit_engagement" ON ("audit_spotcheck"."engagement_ptr_id" = "audit_engagement"."id") + WHERE (EXTRACT(MONTH FROM "audit_engagement"."start_date") = ##CURRENT_MONTH## + AND "audit_engagement"."start_date" BETWEEN '##YEAR##-01-01'::date AND '##YEAR##-12-31'::date + AND "audit_engagement"."status" = 'report_submitted'); + + -- + SELECT COUNT(*) AS "__count" + FROM "audit_spotcheck" + INNER JOIN "audit_engagement" ON ("audit_spotcheck"."engagement_ptr_id" = "audit_engagement"."id") + WHERE (EXTRACT(MONTH FROM "audit_engagement"."start_date") = ##CURRENT_MONTH## + AND "audit_engagement"."start_date" BETWEEN '##YEAR##-01-01'::date AND '##YEAR##-12-31'::date + AND "audit_engagement"."status" = 'final'); + + -- + SELECT COUNT(*) AS "__count" + FROM "audit_spoteck" + INNER JOIN "audit_engagement" ON ("audit_spotcheck"."engagement_ptr_id" = "audit_engagement"."id") + WHERE (EXTRACT(MONTH FROM "audit_engagement"."start_date") = ##CURRENT_MONTH## + AND "audit_engagement"."start_date" BETWEEN '##YEAR##-01-01'::date AND '##YEAR##-12-31'::date + AND "audit_engagement"."status" = 'cancelled'); + + -- + SELECT COUNT(*) AS "__count" + FROM "audit_audit" + INNER JOIN "audit_engagement" ON ("audit_audit"."engagement_ptr_id" = "audit_engagement"."id") + WHERE (EXTRACT(MONTH FROM "audit_engagement"."start_date") = ##CURRENT_MONTH## + AND "audit_engagement"."start_date" BETWEEN '##YEAR##-01-01'::date AND '##YEAR##-12-31'::date + AND "audit_engagement"."status" = 'partner_contacted'); + + -- + SELECT COUNT(*) AS "__count" + FROM "audit_audit" + INNER JOIN "audit_engagement" ON ("audit_audit"."engagement_ptr_id" = "audit_engagement"."id") + WHERE (EXTRACT(MONTH FROM "audit_engagement"."start_date") = ##CURRENT_MONTH## + AND "audit_engagement"."start_date" BETWEEN '##YEAR##-01-01'::date AND '##YEAR##-12-31'::date + AND "audit_engagement"."status" = 'report_submitted'); + + -- + SELECT COUNT(*) AS "__count" + FROM "audit_audit" + INNER JOIN "audit_engagement" ON ("audit_audit"."engagement_ptr_id" = "audit_engagement"."id") + WHERE (EXTRACT(MONTH FROM "audit_engagement"."start_date") = ##CURRENT_MONTH## + AND "audit_engagement"."start_date" BETWEEN '##YEAR##-01-01'::date AND '##YEAR##-12-31'::date + AND "audit_engagement"."status" = 'final'); + + -- + SELECT COUNT(*) AS "__count" + FROM "audit_audit" + INNER JOIN "audit_engagement" ON ("audit_audit"."engagement_ptr_id" = "audit_engagement"."id") + WHERE (EXTRACT(MONTH FROM "audit_engagement"."start_date") = ##CURRENT_MONTH## + AND "audit_engagement"."start_date" BETWEEN '##YEAR##-01-01'::date AND '##YEAR##-12-31'::date + AND "audit_engagement"."status" = 'cancelled'); + + + -- + SELECT COUNT(*) AS "__count" + FROM "audit_specialaudit" + INNER JOIN "audit_engagement" ON ("audit_specialaudit"."engagement_ptr_id" = "audit_engagement"."id") + WHERE (EXTRACT(MONTH FROM "audit_engagement"."start_date") = ##CURRENT_MONTH## + AND "audit_engagement"."start_date" BETWEEN '##YEAR##-01-01'::date AND '##YEAR##-12-31'::date + AND "audit_engagement"."status" = 'partner_contacted'); + + -- + SELECT COUNT(*) AS "__count" + FROM "audit_specialaudit" + INNER JOIN "audit_engagement" ON ("audit_specialaudit"."engagement_ptr_id" = "audit_engagement"."id") + WHERE (EXTRACT(MONTH FROM "audit_engagement"."start_date") = ##CURRENT_MONTH## + AND "audit_engagement"."start_date" BETWEEN '##YEAR##-01-01'::date AND '##YEAR##-12-31'::date + AND "audit_engagement"."status" = 'report_submitted'); + + -- + SELECT COUNT(*) AS "__count" + FROM "audit_specialaudit" + INNER JOIN "audit_engagement" ON ("audit_specialaudit"."engagement_ptr_id" = "audit_engagement"."id") + WHERE (EXTRACT(MONTH FROM "audit_engagement"."start_date") = ##CURRENT_MONTH## + AND "audit_engagement"."start_date" BETWEEN '##YEAR##-01-01'::date AND '##YEAR##-12-31'::date + AND "audit_engagement"."status" = 'final'); + + -- + SELECT COUNT(*) AS "__count" + FROM "audit_specialaudit" + INNER JOIN "audit_engagement" ON ("audit_specialaudit"."engagement_ptr_id" = "audit_engagement"."id") + WHERE (EXTRACT(MONTH FROM "audit_engagement"."start_date") = ##CURRENT_MONTH## + AND "audit_engagement"."start_date" BETWEEN '##YEAR##-01-01'::date AND '##YEAR##-12-31'::date + AND "audit_engagement"."status" = 'cancelled'); + + + -- + SELECT COUNT(*) AS "__count" + FROM "audit_microassessment" + INNER JOIN "audit_engagement" ON ("audit_microassessment"."engagement_ptr_id" = "audit_engagement"."id") + WHERE (EXTRACT(MONTH FROM "audit_engagement"."start_date") = ##CURRENT_MONTH## + AND "audit_engagement"."start_date" BETWEEN '##YEAR##-01-01'::date AND '##YEAR##-12-31'::date + AND "audit_engagement"."status" = 'partner_contacted') + + -- + SELECT COUNT(*) AS "__count" + FROM "audit_microassessment" + INNER JOIN "audit_engagement" ON ("audit_microassessment"."engagement_ptr_id" = "audit_engagement"."id") + WHERE (EXTRACT(MONTH FROM "audit_engagement"."start_date") = ##CURRENT_MONTH## + AND "audit_engagement"."start_date" BETWEEN '##YEAR##-01-01'::date AND '##YEAR##-12-31'::date + AND "audit_engagement"."status" = 'report_submitted') + + -- + SELECT COUNT(*) AS "__count" + FROM "audit_microassessment" + INNER JOIN "audit_engagement" ON ("audit_microassessment"."engagement_ptr_id" = "audit_engagement"."id") + WHERE (EXTRACT(MONTH FROM "audit_engagement"."start_date") = ##CURRENT_MONTH## + AND "audit_engagement"."start_date" BETWEEN '##YEAR##-01-01'::date AND '##YEAR##-12-31'::date + AND "audit_engagement"."status" = 'final') + + -- + SELECT COUNT(*) AS "__count" + FROM "audit_microassessment" + INNER JOIN "audit_engagement" ON ("audit_microassessment"."engagement_ptr_id" = "audit_engagement"."id") + WHERE (EXTRACT(MONTH FROM "audit_engagement"."start_date") = ##CURRENT_MONTH## + AND "audit_engagement"."start_date" BETWEEN '##YEAR##-01-01'::date AND '##YEAR##-12-31'::date + AND "audit_engagement"."status" = 'cancelled') + + """ + PARTNER_CONTACTED = "partner_contacted" REPORT_SUBMITTED = "report_submitted" FINAL = "final" From e82b72d4daaac59499e369a0dfefe76a4c5b51e3 Mon Sep 17 00:00:00 2001 From: Hakan Date: Tue, 10 Dec 2024 17:53:37 +0300 Subject: [PATCH 10/15] add queries for LocationsiteLoader --- .../apps/mart/data/models/fm_settings.py | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/src/etools_datamart/apps/mart/data/models/fm_settings.py b/src/etools_datamart/apps/mart/data/models/fm_settings.py index ff8954b57..78fa6f779 100644 --- a/src/etools_datamart/apps/mart/data/models/fm_settings.py +++ b/src/etools_datamart/apps/mart/data/models/fm_settings.py @@ -7,6 +7,51 @@ class LocationsiteLoader(EtoolsLoader): + """ + -- + SET search_path = public,##COUNTRY##; + + -- + SELECT COUNT(*) AS "__count" + FROM "field_monitoring_settings_locationsite"; + + -- field_monitoring_settings_locationsite entries for the page + SELECT '##COUNTRY##' AS __schema, + "field_monitoring_settings_locationsite"."id", + "field_monitoring_settings_locationsite"."created", + "field_monitoring_settings_locationsite"."modified", + "field_monitoring_settings_locationsite"."name", + "field_monitoring_settings_locationsite"."p_code", + "field_monitoring_settings_locationsite"."point", + "field_monitoring_settings_locationsite"."is_active", + "field_monitoring_settings_locationsite"."parent_id" + FROM "field_monitoring_settings_locationsite" + ORDER BY "field_monitoring_settings_locationsite"."id" ASC + LIMIT ##PAGE_SIZE## OFFSET ##PAGE_OFFSET##; + + -- Location entries for the page + SELECT '##COUNTRY##' AS __schema, + "locations_location"."id", + "locations_location"."name", + "locations_location"."latitude", + "locations_location"."longitude", + "locations_location"."p_code", + "locations_location"."point", + "locations_location"."geom", + "locations_location"."level", + "locations_location"."lft", + "locations_location"."parent_id", + "locations_location"."rght", + "locations_location"."tree_id", + "locations_location"."created", + "locations_location"."modified", + "locations_location"."is_active", + "locations_location"."admin_level", + "locations_location"."admin_level_name" + FROM "locations_location" + WHERE "locations_location"."id" IN (## LIST OF "field_monitoring_settings_locationsite"."parent_id" IN THE PAGE##) ; + """ + def get_parent(self, record: FieldMonitoringSettingsLocationsite, values: dict, **kwargs): from etools_datamart.apps.mart.data.models import Location From f52e2689a3f94c3c1df643cbbff8f8e2085bb828 Mon Sep 17 00:00:00 2001 From: Hakan Date: Wed, 11 Dec 2024 15:43:33 +0300 Subject: [PATCH 11/15] document quersies for fund related and hact related loaders --- .../data/models/fund_reservation_header.py | 98 +++++++++++++++ .../apps/mart/data/models/funds_grant.py | 31 +++++ .../mart/data/models/funds_reservation.py | 119 ++++++++++++++++++ .../apps/mart/data/models/hact.py | 28 +++++ .../apps/mart/data/models/hact_detail.py | 78 ++++++++++++ 5 files changed, 354 insertions(+) diff --git a/src/etools_datamart/apps/mart/data/models/fund_reservation_header.py b/src/etools_datamart/apps/mart/data/models/fund_reservation_header.py index ea4e0a308..64ba820fc 100644 --- a/src/etools_datamart/apps/mart/data/models/fund_reservation_header.py +++ b/src/etools_datamart/apps/mart/data/models/fund_reservation_header.py @@ -8,6 +8,104 @@ class FundsReservationHeader(EtoolsDataMartModel): + """ + -- + SET search_path = public,##COUNTRY##; + + -- Count + SELECT COUNT(*) AS "__count" FROM "funds_fundsreservationheader"; + + -- + SELECT '##COUNTRY##' AS __schema, + "funds_fundsreservationheader"."id", + "funds_fundsreservationheader"."vendor_code", + "funds_fundsreservationheader"."fr_number", + "funds_fundsreservationheader"."document_date", + "funds_fundsreservationheader"."fr_type", + "funds_fundsreservationheader"."currency", + "funds_fundsreservationheader"."document_text", + "funds_fundsreservationheader"."start_date", + "funds_fundsreservationheader"."end_date", + "funds_fundsreservationheader"."actual_amt", + "funds_fundsreservationheader"."intervention_id", + "funds_fundsreservationheader"."intervention_amt", + "funds_fundsreservationheader"."outstanding_amt", + "funds_fundsreservationheader"."total_amt", + "funds_fundsreservationheader"."created", + "funds_fundsreservationheader"."modified", + "funds_fundsreservationheader"."actual_amt_local", + "funds_fundsreservationheader"."outstanding_amt_local", + "funds_fundsreservationheader"."total_amt_local", + "funds_fundsreservationheader"."multi_curr_flag", + "funds_fundsreservationheader"."completed_flag", + "funds_fundsreservationheader"."delegated", + + "partners_intervention"."id", + "partners_intervention"."created", + "partners_intervention"."modified", + "partners_intervention"."document_type", + "partners_intervention"."number", + "partners_intervention"."title", + "partners_intervention"."status", + "partners_intervention"."start", + "partners_intervention"."end", + "partners_intervention"."submission_date", + "partners_intervention"."submission_date_prc", + "partners_intervention"."review_date_prc", + "partners_intervention"."prc_review_document", + "partners_intervention"."signed_by_unicef_date", + "partners_intervention"."signed_by_partner_date", + "partners_intervention"."population_focus", + "partners_intervention"."agreement_id", + "partners_intervention"."unicef_signatory_id", + "partners_intervention"."signed_pd_document", + "partners_intervention"."country_programme_id", + "partners_intervention"."contingency_pd", + "partners_intervention"."metadata", + "partners_intervention"."in_amendment", + "partners_intervention"."reference_number_year", + "partners_intervention"."activation_letter", + "partners_intervention"."termination_doc", + "partners_intervention"."cfei_number", + "partners_intervention"."budget_owner_id", + "partners_intervention"."context", + "partners_intervention"."date_sent_to_partner", + "partners_intervention"."equity_narrative", + "partners_intervention"."equity_rating", + "partners_intervention"."gender_narrative", + "partners_intervention"."gender_rating", + "partners_intervention"."hq_support_cost", + "partners_intervention"."implementation_strategy", + "partners_intervention"."ip_program_contribution", + "partners_intervention"."partner_accepted", + "partners_intervention"."sustainability_narrative", + "partners_intervention"."sustainability_rating", + "partners_intervention"."unicef_accepted", + "partners_intervention"."unicef_court", + "partners_intervention"."unicef_review_type", + "partners_intervention"."humanitarian_flag", + "partners_intervention"."capacity_development", + "partners_intervention"."other_info", + "partners_intervention"."other_partners_involved", + "partners_intervention"."technical_guidance", + "partners_intervention"."cash_transfer_modalities", + "partners_intervention"."cancel_justification", + "partners_intervention"."date_partnership_review_performed", + "partners_intervention"."accepted_on_behalf_of_partner", + "partners_intervention"."activation_protocol", + "partners_intervention"."confidential", + "partners_intervention"."has_activities_involving_children", + "partners_intervention"."has_data_processing_agreement", + "partners_intervention"."has_special_conditions_for_construction", + "partners_intervention"."final_review_approved", + "partners_intervention"."other_details", + "partners_intervention"."partner_authorized_officer_signatory_id" + FROM "funds_fundsreservationheader" + LEFT OUTER JOIN "partners_intervention" ON ("funds_fundsreservationheader"."intervention_id" = "partners_intervention"."id") + ORDER BY "funds_fundsreservationheader"."id" ASC + LIMIT ##PAGE_SIZE## OFFSET ##PAGE_OFFSET##; + """ + vendor_code = models.CharField(max_length=20) fr_number = models.CharField(max_length=20) document_date = models.DateField(blank=True, null=True) diff --git a/src/etools_datamart/apps/mart/data/models/funds_grant.py b/src/etools_datamart/apps/mart/data/models/funds_grant.py index 6e2e7ccc9..a1a0a29e4 100644 --- a/src/etools_datamart/apps/mart/data/models/funds_grant.py +++ b/src/etools_datamart/apps/mart/data/models/funds_grant.py @@ -3,6 +3,37 @@ from etools_datamart.apps.mart.data.models.base import EtoolsDataMartModel from etools_datamart.apps.sources.etools.models import FundsGrant +""" +-- +SET search_path = public,##COUNTRY##; + +-- +SELECT COUNT(*) AS "__count" +FROM "funds_grant"; + +-- +SELECT '##COUNTRY##' AS __schema, + "funds_grant"."id", + "funds_grant"."name", + "funds_grant"."donor_id", + "funds_grant"."expiry", + "funds_grant"."description", + "funds_grant"."created", + "funds_grant"."modified" +FROM "funds_grant" +ORDER BY "funds_grant"."id" ASC +LIMIT ##PAGE_SIZE## OFFSET ##PAGE_OFFSET##; + +-- +SELECT '##COUNTRY##' AS __schema, + "funds_donor"."id", + "funds_donor"."name", + "funds_donor"."created", + "funds_donor"."modified" + FROM "funds_donor" +WHERE "funds_donor"."id" IN (## LIST OF "funds_grant"."donor_id" IN THE PAGE ##); +""" + class Grant(EtoolsDataMartModel): name = models.CharField(max_length=128, blank=True, null=True) diff --git a/src/etools_datamart/apps/mart/data/models/funds_reservation.py b/src/etools_datamart/apps/mart/data/models/funds_reservation.py index 63eabb4ca..85230847e 100644 --- a/src/etools_datamart/apps/mart/data/models/funds_reservation.py +++ b/src/etools_datamart/apps/mart/data/models/funds_reservation.py @@ -8,6 +8,125 @@ class FundsReservationLoader(EtoolsLoader): + """ + -- + SET search_path = public,##COUNTRY##; + + -- + SELECT COUNT(*) AS "__count" + FROM "funds_fundsreservationitem"; + + + SELECT '##COUNTRY##' AS __schema, + "funds_fundsreservationitem"."id", + "funds_fundsreservationitem"."fr_ref_number", + "funds_fundsreservationitem"."line_item", + "funds_fundsreservationitem"."wbs", + "funds_fundsreservationitem"."grant_number", + "funds_fundsreservationitem"."fund", + "funds_fundsreservationitem"."overall_amount", + "funds_fundsreservationitem"."overall_amount_dc", + "funds_fundsreservationitem"."due_date", + "funds_fundsreservationitem"."line_item_text", + "funds_fundsreservationitem"."fund_reservation_id", + "funds_fundsreservationitem"."created", + "funds_fundsreservationitem"."modified", + "funds_fundsreservationitem"."donor", + "funds_fundsreservationitem"."donor_code", + + "funds_fundsreservationheader"."id", + "funds_fundsreservationheader"."vendor_code", + "funds_fundsreservationheader"."fr_number", + "funds_fundsreservationheader"."document_date", + "funds_fundsreservationheader"."fr_type", + "funds_fundsreservationheader"."currency", + "funds_fundsreservationheader"."document_text", + "funds_fundsreservationheader"."start_date", + "funds_fundsreservationheader"."end_date", + "funds_fundsreservationheader"."actual_amt", + "funds_fundsreservationheader"."intervention_id", + "funds_fundsreservationheader"."intervention_amt", + "funds_fundsreservationheader"."outstanding_amt", + "funds_fundsreservationheader"."total_amt", + "funds_fundsreservationheader"."created", + "funds_fundsreservationheader"."modified", + "funds_fundsreservationheader"."actual_amt_local", + "funds_fundsreservationheader"."outstanding_amt_local", + "funds_fundsreservationheader"."total_amt_local", + "funds_fundsreservationheader"."multi_curr_flag", + "funds_fundsreservationheader"."completed_flag", + "funds_fundsreservationheader"."delegated" + FROM "funds_fundsreservationitem" + INNER JOIN "funds_fundsreservationheader" ON ("funds_fundsreservationitem"."fund_reservation_id" = "funds_fundsreservationheader"."id") + ORDER BY "funds_fundsreservationitem"."id" ASC + LIMIT ##PAGE_SIZE## OFFSET ##PAGE_OFFSET##; + + -- + SELECT '##COUNTRY##' AS __schema, + "partners_intervention"."id", + "partners_intervention"."created", + "partners_intervention"."modified", + "partners_intervention"."document_type", + "partners_intervention"."number", + "partners_intervention"."title", + "partners_intervention"."status", + "partners_intervention"."start", + "partners_intervention"."end", + "partners_intervention"."submission_date", + "partners_intervention"."submission_date_prc", + "partners_intervention"."review_date_prc", + "partners_intervention"."prc_review_document", + "partners_intervention"."signed_by_unicef_date", + "partners_intervention"."signed_by_partner_date", + "partners_intervention"."population_focus", + "partners_intervention"."agreement_id", + "partners_intervention"."unicef_signatory_id", + "partners_intervention"."signed_pd_document", + "partners_intervention"."country_programme_id", + "partners_intervention"."contingency_pd", + "partners_intervention"."metadata", + "partners_intervention"."in_amendment", + "partners_intervention"."reference_number_year", + "partners_intervention"."activation_letter", + "partners_intervention"."termination_doc", + "partners_intervention"."cfei_number", + "partners_intervention"."budget_owner_id", + "partners_intervention"."context", + "partners_intervention"."date_sent_to_partner", + "partners_intervention"."equity_narrative", + "partners_intervention"."equity_rating", + "partners_intervention"."gender_narrative", + "partners_intervention"."gender_rating", + "partners_intervention"."hq_support_cost", + "partners_intervention"."implementation_strategy", + "partners_intervention"."ip_program_contribution", + "partners_intervention"."partner_accepted", + "partners_intervention"."sustainability_narrative", + "partners_intervention"."sustainability_rating", + "partners_intervention"."unicef_accepted", + "partners_intervention"."unicef_court", + "partners_intervention"."unicef_review_type", + "partners_intervention"."humanitarian_flag", + "partners_intervention"."capacity_development", + "partners_intervention"."other_info", + "partners_intervention"."other_partners_involved", + "partners_intervention"."technical_guidance", + "partners_intervention"."cash_transfer_modalities", + "partners_intervention"."cancel_justification", + "partners_intervention"."date_partnership_review_performed", + "partners_intervention"."accepted_on_behalf_of_partner", + "partners_intervention"."activation_protocol", + "partners_intervention"."confidential", + "partners_intervention"."has_activities_involving_children", + "partners_intervention"."has_data_processing_agreement", + "partners_intervention"."has_special_conditions_for_construction", + "partners_intervention"."final_review_approved", + "partners_intervention"."other_details", + "partners_intervention"."partner_authorized_officer_signatory_id" + FROM "partners_intervention" + WHERE "partners_intervention"."id" IN ( ## LIST OF "funds_fundsreservationheader"."intervention_id" IN THE PAGE##); + """ + def get_intervention(self, record, values, **kwargs): if record.fund_reservation.intervention: try: diff --git a/src/etools_datamart/apps/mart/data/models/hact.py b/src/etools_datamart/apps/mart/data/models/hact.py index 52c2570f7..e52e8636c 100644 --- a/src/etools_datamart/apps/mart/data/models/hact.py +++ b/src/etools_datamart/apps/mart/data/models/hact.py @@ -8,6 +8,34 @@ class HACTLoader(EtoolsLoader): + """ + -- + SET search_path = public, ##COUNTRY##; + + -- + -- + --FOR EACH ##YEAR## IN (2018, 2019. 2020, 2021,... ) + --Perform following; + SELECT '##COUNTRY##' AS __schema, + "hact_aggregatehact"."id", + "hact_aggregatehact"."created", + "hact_aggregatehact"."modified", + "hact_aggregatehact"."year", + "hact_aggregatehact"."partner_values" + FROM "hact_aggregatehact" + WHERE "hact_aggregatehact"."year" =##YEAR##) + LIMIT ##PAGE_SIZE## OFFSET ##PAGE_OFFSET##; + + --NOTE: + --When available JSON properties are to be retrieved; + --"hact_aggregatehact"."partner_values"["assurance_activities"]["micro_assessment"], + --"hact_aggregatehact"."partner_values"["assurance_activities"]["programmatic_visits"]["completed"], + --"hact_aggregatehact"."partner_values"["assurance_activities"]["spot_checks"]["follow_up"], + --"hact_aggregatehact"."partner_values"["assurance_activities"]["spot_checks"]["completed"], + --"hact_aggregatehact"."partner_values"["assurance_activities"]["scheduled_audit"], + --"hact_aggregatehact"."partner_values"["assurance_activities"]["special_audit"] + """ + def get_queryset(self): return self.config.source.objects.filter(year=self.context["year"]) # return HactAggregatehact.objects.filter(year=self.context['year']) diff --git a/src/etools_datamart/apps/mart/data/models/hact_detail.py b/src/etools_datamart/apps/mart/data/models/hact_detail.py index c64b6c153..38c7b84fe 100644 --- a/src/etools_datamart/apps/mart/data/models/hact_detail.py +++ b/src/etools_datamart/apps/mart/data/models/hact_detail.py @@ -57,6 +57,84 @@ def get_item(d, target, default: object = "N/A", sep="|"): class HACTDetailLoader(EtoolsLoader): + """ + --Loader for HACTHistory (HACTDetailLoader) + + -- + SET search_path = public, ##COUNTRY##; + + -- + SELECT COUNT(*) AS "__count" + FROM "hact_hacthistory"; + + -- + SELECT '##COUNTRY##' AS __schema, + "hact_hacthistory"."id", + "hact_hacthistory"."created", + "hact_hacthistory"."modified", + "hact_hacthistory"."year", + "hact_hacthistory"."partner_values", + "hact_hacthistory"."partner_id", + + "partners_partnerorganization"."id", + "partners_partnerorganization"."description", + "partners_partnerorganization"."address", + "partners_partnerorganization"."email", + "partners_partnerorganization"."phone_number", + "partners_partnerorganization"."alternate_id", + "partners_partnerorganization"."alternate_name", + "partners_partnerorganization"."rating", + "partners_partnerorganization"."core_values_assessment_date", + "partners_partnerorganization"."vision_synced", + "partners_partnerorganization"."type_of_assessment", + "partners_partnerorganization"."last_assessment_date", + "partners_partnerorganization"."hidden", + "partners_partnerorganization"."deleted_flag", + "partners_partnerorganization"."total_ct_cp", + "partners_partnerorganization"."total_ct_cy", + "partners_partnerorganization"."blocked", + "partners_partnerorganization"."city", + "partners_partnerorganization"."country", + "partners_partnerorganization"."postal_code", + "partners_partnerorganization"."shared_with", + "partners_partnerorganization"."street_address", + "partners_partnerorganization"."hact_values", + "partners_partnerorganization"."created", + "partners_partnerorganization"."modified", + "partners_partnerorganization"."net_ct_cy", + "partners_partnerorganization"."reported_cy", + "partners_partnerorganization"."total_ct_ytd", + "partners_partnerorganization"."basis_for_risk_rating", + "partners_partnerorganization"."manually_blocked", + "partners_partnerorganization"."outstanding_dct_amount_6_to_9_months_usd", + "partners_partnerorganization"."outstanding_dct_amount_more_than_9_months_usd", + "partners_partnerorganization"."highest_risk_rating_name", + "partners_partnerorganization"."highest_risk_rating_type", + "partners_partnerorganization"."psea_assessment_date", + "partners_partnerorganization"."sea_risk_rating_name", + "partners_partnerorganization"."lead_office_id", + "partners_partnerorganization"."lead_section_id", + "partners_partnerorganization"."organization_id" + FROM "hact_hacthistory" + INNER JOIN "partners_partnerorganization" ON ("hact_hacthistory"."partner_id" = "partners_partnerorganization"."id") + ORDER BY "hact_hacthistory"."id" ASC + LIMIT ##PAGE_SIZE## OFFSET ##PAGE_OFFSET##; + + -- + SELECT "organizations_organization"."id", + "organizations_organization"."created", + "organizations_organization"."modified", + "organizations_organization"."name", + "organizations_organization"."vendor_number", + "organizations_organization"."organization_type", + "organizations_organization"."cso_type", + "organizations_organization"."short_name", + "organizations_organization"."other", + "organizations_organization"."parent_id" + FROM "organizations_organization" + WHERE "organizations_organization"."id" IN (## LIST OF "partners_partnerorganization"."organization_id" IN THE PAGE ##); + """ + def get_pv_completed_year(self, record, values, field_name): ret = 0 for i in range(1, 5): From 56cfae5cb52d9eed73e46510abca9b69add9ac9f Mon Sep 17 00:00:00 2001 From: Hakan Date: Thu, 12 Dec 2024 16:31:20 +0300 Subject: [PATCH 12/15] add queries for InterventionActivity and InterventionCountryProgramme --- .../mart/data/models/intervention_activity.py | 189 ++++++++++++++++++ .../models/intervention_country_programme.py | 90 +++++++++ 2 files changed, 279 insertions(+) diff --git a/src/etools_datamart/apps/mart/data/models/intervention_activity.py b/src/etools_datamart/apps/mart/data/models/intervention_activity.py index 25a21c20a..fc63251f8 100644 --- a/src/etools_datamart/apps/mart/data/models/intervention_activity.py +++ b/src/etools_datamart/apps/mart/data/models/intervention_activity.py @@ -10,6 +10,195 @@ class InterventionActivityLoader(EtoolsLoader): pass + """ + -- + SET search_path = public, ##COUNTRY##; + + -- + SELECT COUNT(*) AS "__count" + FROM "reports_interventionactivityitem"; + + -- + -- Note: Only very few of number of fields of ORM generated query result set is used. + -- Most of the fields can be dropped. + SELECT '##COUNTRY##' AS __schema, + "reports_interventionactivityitem"."id", + "reports_interventionactivityitem"."created", + "reports_interventionactivityitem"."modified", + "reports_interventionactivityitem"."name", + "reports_interventionactivityitem"."unicef_cash", + "reports_interventionactivityitem"."cso_cash", + "reports_interventionactivityitem"."activity_id", + "reports_interventionactivityitem"."no_units", + "reports_interventionactivityitem"."unit", + "reports_interventionactivityitem"."unit_price", + "reports_interventionactivityitem"."code", + + "reports_interventionactivity"."id", + "reports_interventionactivity"."created", + "reports_interventionactivity"."modified", + "reports_interventionactivity"."name", -- directly mapped to .activity + "reports_interventionactivity"."context_details", -- directly mapped to .activity_details + "reports_interventionactivity"."unicef_cash", -- directly mapped to .activity_unicef_cash + "reports_interventionactivity"."cso_cash", -- directly mapped to .activity_cso_cash + "reports_interventionactivity"."result_id", + "reports_interventionactivity"."code", -- directly mapped to .activity_code + "reports_interventionactivity"."is_active", + + "reports_lowerresult"."id", + "reports_lowerresult"."name", -- directly mapped to .ll_name + "reports_lowerresult"."code", -- directly mapped to .ll_code + "reports_lowerresult"."result_link_id", + "reports_lowerresult"."created", + "reports_lowerresult"."modified", + "reports_lowerresult"."is_active", + + "partners_interventionresultlink"."id", + "partners_interventionresultlink"."cp_output_id", + "partners_interventionresultlink"."intervention_id", + "partners_interventionresultlink"."created", + "partners_interventionresultlink"."modified", + "partners_interventionresultlink"."code", + + "partners_intervention"."id", + "partners_intervention"."created", + "partners_intervention"."modified", + "partners_intervention"."document_type", + "partners_intervention"."number", -- directly mapped to .pd_number + "partners_intervention"."title", -- directly mapped to .pd_title + "partners_intervention"."status", + "partners_intervention"."start", + "partners_intervention"."end", + "partners_intervention"."submission_date", + "partners_intervention"."submission_date_prc", + "partners_intervention"."review_date_prc", + "partners_intervention"."prc_review_document", + "partners_intervention"."signed_by_unicef_date", + "partners_intervention"."signed_by_partner_date", + "partners_intervention"."population_focus", + "partners_intervention"."agreement_id", + "partners_intervention"."unicef_signatory_id", + "partners_intervention"."signed_pd_document", + "partners_intervention"."country_programme_id", + "partners_intervention"."contingency_pd", + "partners_intervention"."metadata", + "partners_intervention"."in_amendment", + "partners_intervention"."reference_number_year", + "partners_intervention"."activation_letter", + "partners_intervention"."termination_doc", + "partners_intervention"."cfei_number", + "partners_intervention"."budget_owner_id", + "partners_intervention"."context", + "partners_intervention"."date_sent_to_partner", + "partners_intervention"."equity_narrative", + "partners_intervention"."equity_rating", + "partners_intervention"."gender_narrative", + "partners_intervention"."gender_rating", + "partners_intervention"."hq_support_cost", + "partners_intervention"."implementation_strategy", + "partners_intervention"."ip_program_contribution", + "partners_intervention"."partner_accepted", + "partners_intervention"."sustainability_narrative", + "partners_intervention"."sustainability_rating", + "partners_intervention"."unicef_accepted", + "partners_intervention"."unicef_court", + "partners_intervention"."unicef_review_type", + "partners_intervention"."humanitarian_flag", + "partners_intervention"."capacity_development", + "partners_intervention"."other_info", + "partners_intervention"."other_partners_involved", + "partners_intervention"."technical_guidance", + "partners_intervention"."cash_transfer_modalities", + "partners_intervention"."cancel_justification", + "partners_intervention"."date_partnership_review_performed", + "partners_intervention"."accepted_on_behalf_of_partner", + "partners_intervention"."activation_protocol", + "partners_intervention"."confidential", + "partners_intervention"."has_activities_involving_children", + "partners_intervention"."has_data_processing_agreement", + "partners_intervention"."has_special_conditions_for_construction", + "partners_intervention"."final_review_approved", + "partners_intervention"."other_details", + "partners_intervention"."partner_authorized_officer_signatory_id", + + "partners_agreement"."id", + "partners_agreement"."created", + "partners_agreement"."modified", + "partners_agreement"."start", + "partners_agreement"."end", + "partners_agreement"."agreement_type", + "partners_agreement"."agreement_number", + "partners_agreement"."attached_agreement", + "partners_agreement"."signed_by_unicef_date", + "partners_agreement"."signed_by_partner_date", + "partners_agreement"."partner_id", + "partners_agreement"."signed_by_id", + "partners_agreement"."status", + "partners_agreement"."country_programme_id", + "partners_agreement"."reference_number_year", + "partners_agreement"."special_conditions_pca", + "partners_agreement"."terms_acknowledged_by_id", + "partners_agreement"."partner_manager_id", + + "partners_partnerorganization"."id", + "partners_partnerorganization"."description", + "partners_partnerorganization"."address", + "partners_partnerorganization"."email", + "partners_partnerorganization"."phone_number", + "partners_partnerorganization"."alternate_id", + "partners_partnerorganization"."alternate_name", + "partners_partnerorganization"."rating", + "partners_partnerorganization"."core_values_assessment_date", + "partners_partnerorganization"."vision_synced", + "partners_partnerorganization"."type_of_assessment", + "partners_partnerorganization"."last_assessment_date", + "partners_partnerorganization"."hidden", + "partners_partnerorganization"."deleted_flag", + "partners_partnerorganization"."total_ct_cp", + "partners_partnerorganization"."total_ct_cy", + "partners_partnerorganization"."blocked", + "partners_partnerorganization"."city", + "partners_partnerorganization"."country", + "partners_partnerorganization"."postal_code", + "partners_partnerorganization"."shared_with", + "partners_partnerorganization"."street_address", + "partners_partnerorganization"."hact_values", + "partners_partnerorganization"."created", + "partners_partnerorganization"."modified", + "partners_partnerorganization"."net_ct_cy", + "partners_partnerorganization"."reported_cy", + "partners_partnerorganization"."total_ct_ytd", + "partners_partnerorganization"."basis_for_risk_rating", + "partners_partnerorganization"."manually_blocked", + "partners_partnerorganization"."outstanding_dct_amount_6_to_9_months_usd", + "partners_partnerorganization"."outstanding_dct_amount_more_than_9_months_usd", + "partners_partnerorganization"."highest_risk_rating_name", + "partners_partnerorganization"."highest_risk_rating_type", + "partners_partnerorganization"."psea_assessment_date", + "partners_partnerorganization"."sea_risk_rating_name", + "partners_partnerorganization"."lead_office_id", + "partners_partnerorganization"."lead_section_id", + "partners_partnerorganization"."organization_id", + + "organizations_organization"."id", + "organizations_organization"."created", + "organizations_organization"."modified", + "organizations_organization"."name", -- directly mapped to .partner + "organizations_organization"."vendor_number", -- directly mapped to .partner_vendor_number + "organizations_organization"."organization_type", -- directly mapped to .partner_type + "organizations_organization"."cso_type", -- directly mapped to .partner_cso_type + "organizations_organization"."short_name", + "organizations_organization"."other", + "organizations_organization"."parent_id" + FROM "reports_interventionactivityitem" + INNER JOIN "reports_interventionactivity" ON ("reports_interventionactivityitem"."activity_id" = "reports_interventionactivity"."id") + INNER JOIN "reports_lowerresult" ON ("reports_interventionactivity"."result_id" = "reports_lowerresult"."id") + INNER JOIN "partners_interventionresultlink" ON ("reports_lowerresult"."result_link_id" = "partners_interventionresultlink"."id") + INNER JOIN "partners_intervention" ON ("partners_interventionresultlink"."intervention_id" = "partners_intervention"."id") INNER JOIN "partners_agreement" ON ("partners_intervention"."agreement_id" = "partners_agreement"."id") INNER JOIN "partners_partnerorganization" ON ("partners_agreement"."partner_id" = "partners_partnerorganization"."id") INNER JOIN "organizations_organization" ON ("partners_partnerorganization"."organization_id" = "organizations_organization"."id") + ORDER BY "reports_interventionactivityitem"."id" ASC + LIMIT ##PAGE_SIZE## OFFSET ##PAGE_OFFSET##; + """ + class InterventionActivity(InterventionSimpleAbstract, EtoolsDataMartModel): name = models.CharField(max_length=150, null=True, blank=True) diff --git a/src/etools_datamart/apps/mart/data/models/intervention_country_programme.py b/src/etools_datamart/apps/mart/data/models/intervention_country_programme.py index a46717a5d..248cc43ce 100644 --- a/src/etools_datamart/apps/mart/data/models/intervention_country_programme.py +++ b/src/etools_datamart/apps/mart/data/models/intervention_country_programme.py @@ -8,6 +8,96 @@ class InterventionCountryProgrammeLoader(EtoolsLoader): + """ + -- + SET search_path = public,##COUNTRY##; + + -- + SELECT COUNT(*) AS "__count" + FROM "partners_intervention_country_programmes"; + + -- + -- Note: Only very few of number of fields of ORM generated query result set is used. + -- Most of the fields can be dropped. + + SELECT '##COUNTRY##' AS __schema, + "partners_intervention_country_programmes"."id", + "partners_intervention_country_programmes"."intervention_id", + "partners_intervention_country_programmes"."countryprogramme_id", + + "partners_intervention"."created", + "partners_intervention"."modified", + "partners_intervention"."document_type", + "partners_intervention"."number", + "partners_intervention"."title", + "partners_intervention"."status", + "partners_intervention"."start", + "partners_intervention"."end", + "partners_intervention"."submission_date", + "partners_intervention"."submission_date_prc", + "partners_intervention"."review_date_prc", + "partners_intervention"."prc_review_document", + "partners_intervention"."signed_by_unicef_date", + "partners_intervention"."signed_by_partner_date", + "partners_intervention"."population_focus", + "partners_intervention"."agreement_id", + "partners_intervention"."unicef_signatory_id", + "partners_intervention"."signed_pd_document", + "partners_intervention"."country_programme_id", + "partners_intervention"."contingency_pd", + "partners_intervention"."metadata", + "partners_intervention"."in_amendment", + "partners_intervention"."reference_number_year", + "partners_intervention"."activation_letter", + "partners_intervention"."termination_doc", + "partners_intervention"."cfei_number", + "partners_intervention"."budget_owner_id", + "partners_intervention"."context", + "partners_intervention"."date_sent_to_partner", + "partners_intervention"."equity_narrative", + "partners_intervention"."equity_rating", + "partners_intervention"."gender_narrative", + "partners_intervention"."gender_rating", + "partners_intervention"."hq_support_cost", + "partners_intervention"."implementation_strategy", + "partners_intervention"."ip_program_contribution", + "partners_intervention"."partner_accepted", + "partners_intervention"."sustainability_narrative", + "partners_intervention"."sustainability_rating", + "partners_intervention"."unicef_accepted", + "partners_intervention"."unicef_court", + "partners_intervention"."unicef_review_type", + "partners_intervention"."humanitarian_flag", + "partners_intervention"."capacity_development", + "partners_intervention"."other_info", + "partners_intervention"."other_partners_involved", + "partners_intervention"."technical_guidance", + "partners_intervention"."cash_transfer_modalities", "partners_intervention"."cancel_justification", "partners_intervention"."date_partnership_review_performed", "partners_intervention"."accepted_on_behalf_of_partner", "partners_intervention"."activation_protocol", "partners_intervention"."confidential", "partners_intervention"."has_activities_involving_children", "partners_intervention"."has_data_processing_agreement", "partners_intervention"."has_special_conditions_for_construction", "partners_intervention"."final_review_approved", "partners_intervention"."other_details", "partners_intervention"."partner_authorized_officer_signatory_id", + + "partners_agreement"."id", "partners_agreement"."created", "partners_agreement"."modified", "partners_agreement"."start", "partners_agreement"."end", "partners_agreement"."agreement_type", "partners_agreement"."agreement_number", "partners_agreement"."attached_agreement", "partners_agreement"."signed_by_unicef_date", "partners_agreement"."signed_by_partner_date", "partners_agreement"."partner_id", "partners_agreement"."signed_by_id", "partners_agreement"."status", "partners_agreement"."country_programme_id", "partners_agreement"."reference_number_year", "partners_agreement"."special_conditions_pca", "partners_agreement"."terms_acknowledged_by_id", "partners_agreement"."partner_manager_id", + + "partners_partnerorganization"."id", "partners_partnerorganization"."description", "partners_partnerorganization"."address", "partners_partnerorganization"."email", "partners_partnerorganization"."phone_number", "partners_partnerorganization"."alternate_id", "partners_partnerorganization"."alternate_name", "partners_partnerorganization"."rating", "partners_partnerorganization"."core_values_assessment_date", "partners_partnerorganization"."vision_synced", "partners_partnerorganization"."type_of_assessment", "partners_partnerorganization"."last_assessment_date", "partners_partnerorganization"."hidden", "partners_partnerorganization"."deleted_flag", "partners_partnerorganization"."total_ct_cp", "partners_partnerorganization"."total_ct_cy", "partners_partnerorganization"."blocked", "partners_partnerorganization"."city", "partners_partnerorganization"."country", "partners_partnerorganization"."postal_code", "partners_partnerorganization"."shared_with", "partners_partnerorganization"."street_address", "partners_partnerorganization"."hact_values", "partners_partnerorganization"."created", "partners_partnerorganization"."modified", "partners_partnerorganization"."net_ct_cy", "partners_partnerorganization"."reported_cy", "partners_partnerorganization"."total_ct_ytd", "partners_partnerorganization"."basis_for_risk_rating", "partners_partnerorganization"."manually_blocked", "partners_partnerorganization"."outstanding_dct_amount_6_to_9_months_usd", "partners_partnerorganization"."outstanding_dct_amount_more_than_9_months_usd", "partners_partnerorganization"."highest_risk_rating_name", "partners_partnerorganization"."highest_risk_rating_type", "partners_partnerorganization"."psea_assessment_date", "partners_partnerorganization"."sea_risk_rating_name", "partners_partnerorganization"."lead_office_id", "partners_partnerorganization"."lead_section_id", "partners_partnerorganization"."organization_id", + + "organizations_organization"."id", "organizations_organization"."created", "organizations_organization"."modified", "organizations_organization"."name", "organizations_organization"."vendor_number", "organizations_organization"."organization_type", "organizations_organization"."cso_type", "organizations_organization"."short_name", "organizations_organization"."other", "organizations_organization"."parent_id", + + "reports_countryprogramme"."id", + "reports_countryprogramme"."name", --directly mapped to .country_programme + "reports_countryprogramme"."wbs", + "reports_countryprogramme"."from_date", + "reports_countryprogramme"."to_date", + "reports_countryprogramme"."invalid" + + FROM "partners_intervention_country_programmes" + INNER JOIN "partners_intervention" ON ("partners_intervention_country_programmes"."intervention_id" = "partners_intervention"."id") + INNER JOIN "partners_agreement" ON ("partners_intervention"."agreement_id" = "partners_agreement"."id") + NNER JOIN "partners_partnerorganization" ON ("partners_agreement"."partner_id" = "partners_partnerorganization"."id") + INNER JOIN "organizations_organization" ON ("partners_partnerorganization"."organization_id" = "organizations_organization"."id") + INNER JOIN "reports_countryprogramme" ON ("partners_intervention_country_programmes"."countryprogramme_id" = "reports_countryprogramme"."id") + ORDER BY "partners_intervention_country_programmes"."id" ASC + LIMIT ##PAGE_SIZE## OFFSET ##PAGE_OFFSET##; + + """ + def get_queryset(self): return PartnersInterventionCountryProgrammes.objects.select_related( "countryprogramme", From ddef31d1893b54aa4ce9af4b359b27cfd6270138 Mon Sep 17 00:00:00 2001 From: Hakan Date: Mon, 16 Dec 2024 16:37:51 +0300 Subject: [PATCH 13/15] document query for InterventionEPDLoader --- .../apps/mart/data/models/intervention_epd.py | 152 ++++++++++++++++++ 1 file changed, 152 insertions(+) diff --git a/src/etools_datamart/apps/mart/data/models/intervention_epd.py b/src/etools_datamart/apps/mart/data/models/intervention_epd.py index 99bd8bc04..898f863dd 100644 --- a/src/etools_datamart/apps/mart/data/models/intervention_epd.py +++ b/src/etools_datamart/apps/mart/data/models/intervention_epd.py @@ -38,6 +38,158 @@ class Options: class InterventionEPDLoader(EtoolsLoader): pass + """ + -- + SET search_path = public,##COUNTRY##; + + -- + SELECT COUNT(*) AS "__count" + FROM "partners_intervention"; + + -- + SELECT 'afghanistan' AS __schema, + "partners_intervention"."id", + "partners_intervention"."created", + "partners_intervention"."modified", + "partners_intervention"."document_type", + "partners_intervention"."number", + "partners_intervention"."title", + "partners_intervention"."status", + "partners_intervention"."start", + "partners_intervention"."end", + "partners_intervention"."submission_date", + "partners_intervention"."submission_date_prc", + "partners_intervention"."review_date_prc", + "partners_intervention"."prc_review_document", + "partners_intervention"."signed_by_unicef_date", + "partners_intervention"."signed_by_partner_date", + "partners_intervention"."population_focus", + "partners_intervention"."agreement_id", + "partners_intervention"."unicef_signatory_id", + "partners_intervention"."signed_pd_document", + "partners_intervention"."country_programme_id", + "partners_intervention"."contingency_pd", + "partners_intervention"."metadata", + "partners_intervention"."in_amendment", + "partners_intervention"."reference_number_year", + "partners_intervention"."activation_letter", + "partners_intervention"."termination_doc", + "partners_intervention"."cfei_number", + "partners_intervention"."budget_owner_id", + "partners_intervention"."context", -- directly mapped + "partners_intervention"."date_sent_to_partner", -- directly mapped + "partners_intervention"."equity_narrative", -- directly mapped + "partners_intervention"."equity_rating", -- directly mapped + "partners_intervention"."gender_narrative", -- directly mapped + "partners_intervention"."gender_rating", -- directly mapped + "partners_intervention"."hq_support_cost", -- directly mapped + "partners_intervention"."implementation_strategy", -- directly mapped + "partners_intervention"."ip_program_contribution", -- directly mapped + "partners_intervention"."partner_accepted", -- directly mapped + "partners_intervention"."sustainability_narrative", -- directly mapped + "partners_intervention"."sustainability_rating", -- directly mapped + "partners_intervention"."unicef_accepted", -- directly mapped + "partners_intervention"."unicef_court", -- directly mapped + "partners_intervention"."unicef_review_type", -- directly mapped + "partners_intervention"."humanitarian_flag", -- directly mapped + "partners_intervention"."capacity_development", -- directly mapped + "partners_intervention"."other_info", -- directly mapped + "partners_intervention"."other_partners_involved", -- directly mapped + "partners_intervention"."technical_guidance", -- directly mapped + "partners_intervention"."cash_transfer_modalities", -- directly mapped + "partners_intervention"."cancel_justification", -- directly mapped + "partners_intervention"."date_partnership_review_performed", -- directly mapped + "partners_intervention"."accepted_on_behalf_of_partner", -- directly mapped + "partners_intervention"."activation_protocol", -- directly mapped + "partners_intervention"."confidential", -- directly mapped + "partners_intervention"."has_activities_involving_children", + "partners_intervention"."has_data_processing_agreement", + "partners_intervention"."has_special_conditions_for_construction", + "partners_intervention"."final_review_approved", + "partners_intervention"."other_details", + "partners_intervention"."partner_authorized_officer_signatory_id", + + "partners_agreement"."id", + "partners_agreement"."created", + "partners_agreement"."modified", + "partners_agreement"."start", + "partners_agreement"."end", + "partners_agreement"."agreement_type", + "partners_agreement"."agreement_number", + "partners_agreement"."attached_agreement", + "partners_agreement"."signed_by_unicef_date", + "partners_agreement"."signed_by_partner_date", + "partners_agreement"."partner_id", + "partners_agreement"."signed_by_id", + "partners_agreement"."status", + "partners_agreement"."country_programme_id", + "partners_agreement"."reference_number_year", + "partners_agreement"."special_conditions_pca", + "partners_agreement"."terms_acknowledged_by_id", + "partners_agreement"."partner_manager_id", + + "partners_partnerorganization"."id", + "partners_partnerorganization"."description", + "partners_partnerorganization"."address", + "partners_partnerorganization"."email", + "partners_partnerorganization"."phone_number", + "partners_partnerorganization"."alternate_id", + "partners_partnerorganization"."alternate_name", + "partners_partnerorganization"."rating", + "partners_partnerorganization"."core_values_assessment_date", + "partners_partnerorganization"."vision_synced", + "partners_partnerorganization"."type_of_assessment", + "partners_partnerorganization"."last_assessment_date", + "partners_partnerorganization"."hidden", + "partners_partnerorganization"."deleted_flag", + "partners_partnerorganization"."total_ct_cp", + "partners_partnerorganization"."total_ct_cy", + "partners_partnerorganization"."blocked", + "partners_partnerorganization"."city", + "partners_partnerorganization"."country", + "partners_partnerorganization"."postal_code", + "partners_partnerorganization"."shared_with", + "partners_partnerorganization"."street_address", + "partners_partnerorganization"."hact_values", + "partners_partnerorganization"."created", + "partners_partnerorganization"."modified", + "partners_partnerorganization"."net_ct_cy", + "partners_partnerorganization"."reported_cy", + "partners_partnerorganization"."total_ct_ytd", + "partners_partnerorganization"."basis_for_risk_rating", + "partners_partnerorganization"."manually_blocked", + "partners_partnerorganization"."outstanding_dct_amount_6_to_9_months_usd", + "partners_partnerorganization"."outstanding_dct_amount_more_than_9_months_usd", + "partners_partnerorganization"."highest_risk_rating_name", + "partners_partnerorganization"."highest_risk_rating_type", + "partners_partnerorganization"."psea_assessment_date", + "partners_partnerorganization"."sea_risk_rating_name", + "partners_partnerorganization"."lead_office_id", + "partners_partnerorganization"."lead_section_id", + "partners_partnerorganization"."organization_id" , + + "organizations_organization"."id", + "organizations_organization"."created", + "organizations_organization"."modified", + "organizations_organization"."name", + "organizations_organization"."vendor_number", + "organizations_organization"."organization_type", + "organizations_organization"."cso_type", + "organizations_organization"."short_name", + "organizations_organization"."other", + "organizations_organization"."parent_id", + + "auth_user"."id", + "auth_user"."username" -- directly mapped to .budget_owner + + FROM "partners_intervention", + INNER JOIN "partners_agreement" ON ("partners_intervention"."agreement_id" = "partners_intervention"."agreement_id") + INNER JOIN "partners_partnerorganization" ON ("partners_partnerorganization"."id" = "partners_agreement"."partner_id") + INNER JOIN "organizations_organization" ON ("organizations_organization"."id" = "partners_partnerorganization"."organization_id") + INNER JOIN "auth_user" ON ( "auth_user"."id" = "partners_intervention"."budget_owner_id" ) + ORDER BY "partners_intervention"."id" ASC + LIMIT ##PAGE_SIZE## OFFSET ##PAGE_OFFSET##; + """ class InterventionEPD(InterventionSimpleAbstract, EtoolsDataMartModel): From cf90162690f8aa65bb4b2747a3b195d25e90d2f6 Mon Sep 17 00:00:00 2001 From: Hakan Date: Wed, 18 Dec 2024 11:02:14 +0300 Subject: [PATCH 14/15] document queries for interventionmanagementbudget --- .../models/intervention_management_budget.py | 179 ++++++++++++++++++ 1 file changed, 179 insertions(+) diff --git a/src/etools_datamart/apps/mart/data/models/intervention_management_budget.py b/src/etools_datamart/apps/mart/data/models/intervention_management_budget.py index 9caeb1a6d..6fa79ed95 100644 --- a/src/etools_datamart/apps/mart/data/models/intervention_management_budget.py +++ b/src/etools_datamart/apps/mart/data/models/intervention_management_budget.py @@ -15,6 +15,185 @@ class InterventionManagementBudgetLoader(EtoolsLoader): pass + """ + -- + SET search_path = public,##COUNTRY##; + + -- + SELECT COUNT(*) AS "__count" + FROM "partners_interventionmanagementbudgetitem"; + + -- + SELECT '##COUNTRY##' AS __schema, + "partners_interventionmanagementbudgetitem"."id", + "partners_interventionmanagementbudgetitem"."name", + "partners_interventionmanagementbudgetitem"."kind", + "partners_interventionmanagementbudgetitem"."unicef_cash", -- directly mapped to .unicef_cash + "partners_interventionmanagementbudgetitem"."cso_cash", -- directly mapped to .cso_cash + "partners_interventionmanagementbudgetitem"."budget_id", + "partners_interventionmanagementbudgetitem"."no_units", -- directly mapped to .no_unit + "partners_interventionmanagementbudgetitem"."unit", -- directly mapped to .unit + "partners_interventionmanagementbudgetitem"."unit_price", -- directly mapped to .unit_price + + "partners_interventionmanagementbudget"."id", + "partners_interventionmanagementbudget"."created", -- directly mapped to .budget_created + "partners_interventionmanagementbudget"."modified", -- directly mapped to .budget_modified + "partners_interventionmanagementbudget"."act1_unicef", -- directly mapped to .act1_unicef + "partners_interventionmanagementbudget"."act1_partner", -- directly mapped to .act1_partner + "partners_interventionmanagementbudget"."act2_unicef", -- directly mapped to .act2_unicef + "partners_interventionmanagementbudget"."act2_partner", -- directly mapped to .act2_partner + "partners_interventionmanagementbudget"."act3_unicef", -- directly mapped to .act3_unicef + "partners_interventionmanagementbudget"."act3_partner", -- directly mapped to .act3_partner + "partners_interventionmanagementbudget"."intervention_id", + + "partners_intervention"."id", + "partners_intervention"."created", + "partners_intervention"."modified", + "partners_intervention"."document_type", + "partners_intervention"."number", -- directly mapped to .pd_number + "partners_intervention"."title", -- directly mapped to .pd_title + "partners_intervention"."status", + "partners_intervention"."start", + "partners_intervention"."end", + "partners_intervention"."submission_date", + "partners_intervention"."submission_date_prc", + "partners_intervention"."review_date_prc", + "partners_intervention"."prc_review_document", + "partners_intervention"."signed_by_unicef_date", + "partners_intervention"."signed_by_partner_date", + "partners_intervention"."population_focus", + "partners_intervention"."agreement_id", + "partners_intervention"."unicef_signatory_id", + "partners_intervention"."signed_pd_document", + "partners_intervention"."country_programme_id", + "partners_intervention"."contingency_pd", + "partners_intervention"."metadata", + "partners_intervention"."in_amendment", + "partners_intervention"."reference_number_year", + "partners_intervention"."activation_letter", + "partners_intervention"."termination_doc", + "partners_intervention"."cfei_number", + "partners_intervention"."budget_owner_id", + "partners_intervention"."context", + "partners_intervention"."date_sent_to_partner", + "partners_intervention"."equity_narrative", + "partners_intervention"."equity_rating", + "partners_intervention"."gender_narrative", + "partners_intervention"."gender_rating", + "partners_intervention"."hq_support_cost", + "partners_intervention"."implementation_strategy", + "partners_intervention"."ip_program_contribution", + "partners_intervention"."partner_accepted", + "partners_intervention"."sustainability_narrative", + "partners_intervention"."sustainability_rating", + "partners_intervention"."unicef_accepted", + "partners_intervention"."unicef_court", + "partners_intervention"."unicef_review_type", + "partners_intervention"."humanitarian_flag", + "partners_intervention"."capacity_development", + "partners_intervention"."other_info", + "partners_intervention"."other_partners_involved", + "partners_intervention"."technical_guidance", + "partners_intervention"."cash_transfer_modalities", + "partners_intervention"."cancel_justification", + "partners_intervention"."date_partnership_review_performed", + "partners_intervention"."accepted_on_behalf_of_partner", + "partners_intervention"."activation_protocol", + "partners_intervention"."confidential", + "partners_intervention"."has_activities_involving_children", + "partners_intervention"."has_data_processing_agreement", + "partners_intervention"."has_special_conditions_for_construction", + "partners_intervention"."final_review_approved", + "partners_intervention"."other_details", + "partners_intervention"."partner_authorized_officer_signatory_id" + FROM "partners_interventionmanagementbudgetitem" + INNER JOIN "partners_interventionmanagementbudget" ON ("partners_interventionmanagementbudgetitem"."budget_id" = "partners_interventionmanagementbudget"."id") + INNER JOIN "partners_intervention" ON ("partners_interventionmanagementbudget"."intervention_id" = "partners_intervention"."id") + ORDER BY "partners_interventionmanagementbudgetitem"."id" ASC + LIMIT ##PAGE_SIZE## OFFSET ##PAGE_OFFSET##; + + + -- + SELECT 'argentina' AS __schema, + "partners_agreement"."id", + "partners_agreement"."created", + "partners_agreement"."modified", + "partners_agreement"."start", + "partners_agreement"."end", + "partners_agreement"."agreement_type", + "partners_agreement"."agreement_number", + "partners_agreement"."attached_agreement", + "partners_agreement"."signed_by_unicef_date", + "partners_agreement"."signed_by_partner_date", + "partners_agreement"."partner_id", + "partners_agreement"."signed_by_id", + "partners_agreement"."status", + "partners_agreement"."country_programme_id", + "partners_agreement"."reference_number_year", + "partners_agreement"."special_conditions_pca", + "partners_agreement"."terms_acknowledged_by_id", + "partners_agreement"."partner_manager_id" + FROM "partners_agreement" WHERE "partners_agreement"."id" IN (##List of "partners_intervention"."agreement_id" in the page ##); + + -- + SELECT 'argentina' AS __schema, + "partners_partnerorganization"."id", + "partners_partnerorganization"."description", + "partners_partnerorganization"."address", + "partners_partnerorganization"."email", + "partners_partnerorganization"."phone_number", + "partners_partnerorganization"."alternate_id", + "partners_partnerorganization"."alternate_name", + "partners_partnerorganization"."rating", + "partners_partnerorganization"."core_values_assessment_date", + "partners_partnerorganization"."vision_synced", + "partners_partnerorganization"."type_of_assessment", + "partners_partnerorganization"."last_assessment_date", + "partners_partnerorganization"."hidden", + "partners_partnerorganization"."deleted_flag", + "partners_partnerorganization"."total_ct_cp", + "partners_partnerorganization"."total_ct_cy", + "partners_partnerorganization"."blocked", + "partners_partnerorganization"."city", + "partners_partnerorganization"."country", + "partners_partnerorganization"."postal_code", + "partners_partnerorganization"."shared_with", + "partners_partnerorganization"."street_address", + "partners_partnerorganization"."hact_values", + "partners_partnerorganization"."created", + "partners_partnerorganization"."modified", + "partners_partnerorganization"."net_ct_cy", + "partners_partnerorganization"."reported_cy", + "partners_partnerorganization"."total_ct_ytd", + "partners_partnerorganization"."basis_for_risk_rating", + "partners_partnerorganization"."manually_blocked", + "partners_partnerorganization"."outstanding_dct_amount_6_to_9_months_usd", + "partners_partnerorganization"."outstanding_dct_amount_more_than_9_months_usd", + "partners_partnerorganization"."highest_risk_rating_name", + "partners_partnerorganization"."highest_risk_rating_type", + "partners_partnerorganization"."psea_assessment_date", + "partners_partnerorganization"."sea_risk_rating_name", + "partners_partnerorganization"."lead_office_id", + "partners_partnerorganization"."lead_section_id", + "partners_partnerorganization"."organization_id" + FROM "partners_partnerorganization" + WHERE "partners_partnerorganization"."id" IN (## LIST of "partners_agreement"."partner_id" in the page ##); + + -- + SELECT "organizations_organization"."id", + "organizations_organization"."created", + "organizations_organization"."modified", + "organizations_organization"."name", -- directly mapped to .partner + "organizations_organization"."vendor_number", -- directly mapped to .partner_vendor_number + "organizations_organization"."organization_type", -- directly mapped to .partner_type + "organizations_organization"."cso_type", -- directly mapped to .partner_cso_type + "organizations_organization"."short_name", + "organizations_organization"."other", + "organizations_organization"."parent_id" + FROM "organizations_organization" + WHERE "organizations_organization"."id" IN (## LIST of "partners_partnerorganization"."organization_id" in the page ##); + """ + class InterventionManagementBudget(InterventionSimpleAbstract, EtoolsDataMartModel): # management budget fields From 6c5b5cf02b6fadcb6cd8e8fb7b02d1032a0de0d3 Mon Sep 17 00:00:00 2001 From: Hakan Date: Mon, 23 Dec 2024 16:30:40 +0300 Subject: [PATCH 15/15] add abd update queries for intervention related loaders --- .../models/intervention_country_programme.py | 97 ++++++++-- .../apps/mart/data/models/intervention_epd.py | 54 +++--- .../models/intervention_management_budget.py | 2 +- .../models/intervention_planned_visits.py | 160 ++++++++++++++++ .../mart/data/models/intervention_review.py | 175 ++++++++++++++++++ 5 files changed, 449 insertions(+), 39 deletions(-) diff --git a/src/etools_datamart/apps/mart/data/models/intervention_country_programme.py b/src/etools_datamart/apps/mart/data/models/intervention_country_programme.py index 248cc43ce..31be11e7a 100644 --- a/src/etools_datamart/apps/mart/data/models/intervention_country_programme.py +++ b/src/etools_datamart/apps/mart/data/models/intervention_country_programme.py @@ -21,15 +21,15 @@ class InterventionCountryProgrammeLoader(EtoolsLoader): -- Most of the fields can be dropped. SELECT '##COUNTRY##' AS __schema, - "partners_intervention_country_programmes"."id", + "partners_intervention_country_programmes"."id", -- directly mapped to .source_id "partners_intervention_country_programmes"."intervention_id", "partners_intervention_country_programmes"."countryprogramme_id", "partners_intervention"."created", "partners_intervention"."modified", "partners_intervention"."document_type", - "partners_intervention"."number", - "partners_intervention"."title", + "partners_intervention"."number", -- to .pd_number + "partners_intervention"."title", -- to .pd_title "partners_intervention"."status", "partners_intervention"."start", "partners_intervention"."end", @@ -72,16 +72,91 @@ class InterventionCountryProgrammeLoader(EtoolsLoader): "partners_intervention"."other_info", "partners_intervention"."other_partners_involved", "partners_intervention"."technical_guidance", - "partners_intervention"."cash_transfer_modalities", "partners_intervention"."cancel_justification", "partners_intervention"."date_partnership_review_performed", "partners_intervention"."accepted_on_behalf_of_partner", "partners_intervention"."activation_protocol", "partners_intervention"."confidential", "partners_intervention"."has_activities_involving_children", "partners_intervention"."has_data_processing_agreement", "partners_intervention"."has_special_conditions_for_construction", "partners_intervention"."final_review_approved", "partners_intervention"."other_details", "partners_intervention"."partner_authorized_officer_signatory_id", - - "partners_agreement"."id", "partners_agreement"."created", "partners_agreement"."modified", "partners_agreement"."start", "partners_agreement"."end", "partners_agreement"."agreement_type", "partners_agreement"."agreement_number", "partners_agreement"."attached_agreement", "partners_agreement"."signed_by_unicef_date", "partners_agreement"."signed_by_partner_date", "partners_agreement"."partner_id", "partners_agreement"."signed_by_id", "partners_agreement"."status", "partners_agreement"."country_programme_id", "partners_agreement"."reference_number_year", "partners_agreement"."special_conditions_pca", "partners_agreement"."terms_acknowledged_by_id", "partners_agreement"."partner_manager_id", - - "partners_partnerorganization"."id", "partners_partnerorganization"."description", "partners_partnerorganization"."address", "partners_partnerorganization"."email", "partners_partnerorganization"."phone_number", "partners_partnerorganization"."alternate_id", "partners_partnerorganization"."alternate_name", "partners_partnerorganization"."rating", "partners_partnerorganization"."core_values_assessment_date", "partners_partnerorganization"."vision_synced", "partners_partnerorganization"."type_of_assessment", "partners_partnerorganization"."last_assessment_date", "partners_partnerorganization"."hidden", "partners_partnerorganization"."deleted_flag", "partners_partnerorganization"."total_ct_cp", "partners_partnerorganization"."total_ct_cy", "partners_partnerorganization"."blocked", "partners_partnerorganization"."city", "partners_partnerorganization"."country", "partners_partnerorganization"."postal_code", "partners_partnerorganization"."shared_with", "partners_partnerorganization"."street_address", "partners_partnerorganization"."hact_values", "partners_partnerorganization"."created", "partners_partnerorganization"."modified", "partners_partnerorganization"."net_ct_cy", "partners_partnerorganization"."reported_cy", "partners_partnerorganization"."total_ct_ytd", "partners_partnerorganization"."basis_for_risk_rating", "partners_partnerorganization"."manually_blocked", "partners_partnerorganization"."outstanding_dct_amount_6_to_9_months_usd", "partners_partnerorganization"."outstanding_dct_amount_more_than_9_months_usd", "partners_partnerorganization"."highest_risk_rating_name", "partners_partnerorganization"."highest_risk_rating_type", "partners_partnerorganization"."psea_assessment_date", "partners_partnerorganization"."sea_risk_rating_name", "partners_partnerorganization"."lead_office_id", "partners_partnerorganization"."lead_section_id", "partners_partnerorganization"."organization_id", - - "organizations_organization"."id", "organizations_organization"."created", "organizations_organization"."modified", "organizations_organization"."name", "organizations_organization"."vendor_number", "organizations_organization"."organization_type", "organizations_organization"."cso_type", "organizations_organization"."short_name", "organizations_organization"."other", "organizations_organization"."parent_id", + "partners_intervention"."cash_transfer_modalities" + "partners_intervention"."cancel_justification", + "partners_intervention"."date_partnership_review_performed", + "partners_intervention"."accepted_on_behalf_of_partner", + "partners_intervention"."activation_protocol", + "partners_intervention"."confidential", + "partners_intervention"."has_activities_involving_children", + "partners_intervention"."has_data_processing_agreement", + "partners_intervention"."has_special_conditions_for_construction", + "partners_intervention"."final_review_approved", + "partners_intervention"."other_details", + "partners_intervention"."partner_authorized_officer_signatory_id", + + "partners_agreement"."id", + "partners_agreement"."created", + "partners_agreement"."modified", + "partners_agreement"."start", + "partners_agreement"."end", + "partners_agreement"."agreement_type", + "partners_agreement"."agreement_number", + "partners_agreement"."attached_agreement", + "partners_agreement"."signed_by_unicef_date", + "partners_agreement"."signed_by_partner_date", + "partners_agreement"."partner_id", + "partners_agreement"."signed_by_id", + "partners_agreement"."status", + "partners_agreement"."country_programme_id", + "partners_agreement"."reference_number_year", + "partners_agreement"."special_conditions_pca", + "partners_agreement"."terms_acknowledged_by_id", + "partners_agreement"."partner_manager_id", + + "partners_partnerorganization"."id", + "partners_partnerorganization"."description", + "partners_partnerorganization"."address", + "partners_partnerorganization"."email", + "partners_partnerorganization"."phone_number", + "partners_partnerorganization"."alternate_id", + "partners_partnerorganization"."alternate_name", + "partners_partnerorganization"."rating", + "partners_partnerorganization"."core_values_assessment_date", + "partners_partnerorganization"."vision_synced", + "partners_partnerorganization"."type_of_assessment", + "partners_partnerorganization"."last_assessment_date", + "partners_partnerorganization"."hidden", + "partners_partnerorganization"."deleted_flag", + "partners_partnerorganization"."total_ct_cp", + "partners_partnerorganization"."total_ct_cy", + "partners_partnerorganization"."blocked", + "partners_partnerorganization"."city", + "partners_partnerorganization"."country", + "partners_partnerorganization"."postal_code", + "partners_partnerorganization"."shared_with", + "partners_partnerorganization"."street_address", + "partners_partnerorganization"."hact_values", + "partners_partnerorganization"."created", + "partners_partnerorganization"."modified", + "partners_partnerorganization"."net_ct_cy", + "partners_partnerorganization"."reported_cy", + "partners_partnerorganization"."total_ct_ytd", + "partners_partnerorganization"."basis_for_risk_rating", + "partners_partnerorganization"."manually_blocked", + "partners_partnerorganization"."outstanding_dct_amount_6_to_9_months_usd", + "partners_partnerorganization"."outstanding_dct_amount_more_than_9_months_usd", + "partners_partnerorganization"."highest_risk_rating_name", + "partners_partnerorganization"."highest_risk_rating_type", + "partners_partnerorganization"."psea_assessment_date", + "partners_partnerorganization"."sea_risk_rating_name", + "partners_partnerorganization"."lead_office_id", + "partners_partnerorganization"."lead_section_id", + "partners_partnerorganization"."organization_id", + + "organizations_organization"."id", + "organizations_organization"."created", + "organizations_organization"."modified", + "organizations_organization"."name", -- directly mapped to .partner + "organizations_organization"."vendor_number", -- directly mapped to .partner_vendor_number= + "organizations_organization"."organization_type", -- directly mapped to .partner_type + "organizations_organization"."cso_type", -- directly mapped to .partner_cso_type + "organizations_organization"."short_name", + "organizations_organization"."other", + "organizations_organization"."parent_id", "reports_countryprogramme"."id", - "reports_countryprogramme"."name", --directly mapped to .country_programme + "reports_countryprogramme"."name", --directly mapped to .country_programme "reports_countryprogramme"."wbs", "reports_countryprogramme"."from_date", "reports_countryprogramme"."to_date", diff --git a/src/etools_datamart/apps/mart/data/models/intervention_epd.py b/src/etools_datamart/apps/mart/data/models/intervention_epd.py index 898f863dd..05024ded6 100644 --- a/src/etools_datamart/apps/mart/data/models/intervention_epd.py +++ b/src/etools_datamart/apps/mart/data/models/intervention_epd.py @@ -48,7 +48,7 @@ class InterventionEPDLoader(EtoolsLoader): -- SELECT 'afghanistan' AS __schema, - "partners_intervention"."id", + "partners_intervention"."id", -- directly mapped to .source_id "partners_intervention"."created", "partners_intervention"."modified", "partners_intervention"."document_type", @@ -76,32 +76,32 @@ class InterventionEPDLoader(EtoolsLoader): "partners_intervention"."termination_doc", "partners_intervention"."cfei_number", "partners_intervention"."budget_owner_id", - "partners_intervention"."context", -- directly mapped - "partners_intervention"."date_sent_to_partner", -- directly mapped - "partners_intervention"."equity_narrative", -- directly mapped - "partners_intervention"."equity_rating", -- directly mapped - "partners_intervention"."gender_narrative", -- directly mapped - "partners_intervention"."gender_rating", -- directly mapped - "partners_intervention"."hq_support_cost", -- directly mapped - "partners_intervention"."implementation_strategy", -- directly mapped - "partners_intervention"."ip_program_contribution", -- directly mapped - "partners_intervention"."partner_accepted", -- directly mapped - "partners_intervention"."sustainability_narrative", -- directly mapped - "partners_intervention"."sustainability_rating", -- directly mapped - "partners_intervention"."unicef_accepted", -- directly mapped - "partners_intervention"."unicef_court", -- directly mapped - "partners_intervention"."unicef_review_type", -- directly mapped - "partners_intervention"."humanitarian_flag", -- directly mapped - "partners_intervention"."capacity_development", -- directly mapped - "partners_intervention"."other_info", -- directly mapped - "partners_intervention"."other_partners_involved", -- directly mapped - "partners_intervention"."technical_guidance", -- directly mapped - "partners_intervention"."cash_transfer_modalities", -- directly mapped - "partners_intervention"."cancel_justification", -- directly mapped - "partners_intervention"."date_partnership_review_performed", -- directly mapped - "partners_intervention"."accepted_on_behalf_of_partner", -- directly mapped - "partners_intervention"."activation_protocol", -- directly mapped - "partners_intervention"."confidential", -- directly mapped + "partners_intervention"."context", -- directly mapped to .date_sent_to_partner + "partners_intervention"."date_sent_to_partner", -- directly mapped to .equity_narrative + "partners_intervention"."equity_narrative", -- directly mapped to .equity_narrative + "partners_intervention"."equity_rating", -- directly mapped to .equity_ratting + "partners_intervention"."gender_narrative", -- directly mapped to .gender_narrative + "partners_intervention"."gender_rating", -- directly mapped to .gender_rating + "partners_intervention"."hq_support_cost", -- directly mapped to .hq_support_cost + "partners_intervention"."implementation_strategy", -- directly mapped to .implementation_strategy + "partners_intervention"."ip_program_contribution", -- directly mapped to .ip_program_contribution + "partners_intervention"."partner_accepted", -- directly mapped to .partner_accepted + "partners_intervention"."sustainability_narrative", -- directly mapped to .sustainability_narrative + "partners_intervention"."sustainability_rating", -- directly mapped to .sustainability_rating + "partners_intervention"."unicef_accepted", -- directly mapped to .unicef_accepted + "partners_intervention"."unicef_court", -- directly mapped to .unicef_court + "partners_intervention"."unicef_review_type", -- directly mapped to .humanitarian_flag + "partners_intervention"."humanitarian_flag", -- directly mapped to .capacity_development + "partners_intervention"."capacity_development", -- directly mapped to .other_info + "partners_intervention"."other_info", -- directly mapped to .other_partners_involved + "partners_intervention"."other_partners_involved", -- directly mapped to .technical_guidance + "partners_intervention"."technical_guidance", -- directly mapped to .cash_transfer_modalities + "partners_intervention"."cash_transfer_modalities", -- directly mapped to .cancel_justification + "partners_intervention"."cancel_justification", -- directly mapped to .date_partnership_review_performed + "partners_intervention"."date_partnership_review_performed", -- directly mapped to .accepted_on_behalf_of_partner + "partners_intervention"."accepted_on_behalf_of_partner", -- directly mapped to .accepted_on_behalf_of_partner + "partners_intervention"."activation_protocol", -- directly mapped to .activation_protocol + "partners_intervention"."confidential", -- directly mapped to .confidential "partners_intervention"."has_activities_involving_children", "partners_intervention"."has_data_processing_agreement", "partners_intervention"."has_special_conditions_for_construction", diff --git a/src/etools_datamart/apps/mart/data/models/intervention_management_budget.py b/src/etools_datamart/apps/mart/data/models/intervention_management_budget.py index 6fa79ed95..cd187aa9d 100644 --- a/src/etools_datamart/apps/mart/data/models/intervention_management_budget.py +++ b/src/etools_datamart/apps/mart/data/models/intervention_management_budget.py @@ -25,7 +25,7 @@ class InterventionManagementBudgetLoader(EtoolsLoader): -- SELECT '##COUNTRY##' AS __schema, - "partners_interventionmanagementbudgetitem"."id", + "partners_interventionmanagementbudgetitem"."id", -- directly mapped to source_id "partners_interventionmanagementbudgetitem"."name", "partners_interventionmanagementbudgetitem"."kind", "partners_interventionmanagementbudgetitem"."unicef_cash", -- directly mapped to .unicef_cash diff --git a/src/etools_datamart/apps/mart/data/models/intervention_planned_visits.py b/src/etools_datamart/apps/mart/data/models/intervention_planned_visits.py index 941b650e4..e4a87ab28 100644 --- a/src/etools_datamart/apps/mart/data/models/intervention_planned_visits.py +++ b/src/etools_datamart/apps/mart/data/models/intervention_planned_visits.py @@ -6,6 +6,166 @@ class InterventionPlannedVisits(EtoolsDataMartModel): + """ + -- + SET search_path = public,##COUNTRY## + -- + SELECT COUNT(*) AS "__count" + FROM "partners_interventionplannedvisits"; + + -- TODO: Pick only the required fields + -- + SELECT '##COUNTRY##' AS __schema, + "partners_interventionplannedvisits"."id", + "partners_interventionplannedvisits"."year", -- directly mapped to programmatic_year + "partners_interventionplannedvisits"."programmatic_q4", -- directly mapped to programmatic_q4 + "partners_interventionplannedvisits"."intervention_id", + "partners_interventionplannedvisits"."created", + "partners_interventionplannedvisits"."modified", + "partners_interventionplannedvisits"."programmatic_q1", -- directly mapped to programmatic_q1 + "partners_interventionplannedvisits"."programmatic_q2", -- directly mapped to programmatic_q2 + "partners_interventionplannedvisits"."programmatic_q3", -- directly mapped to programmatic_q3 + + '##COUNTRY##' AS __schema, + "partners_intervention"."id", + "partners_intervention"."created", + "partners_intervention"."modified", + "partners_intervention"."document_type", + "partners_intervention"."number", + "partners_intervention"."title", + "partners_intervention"."status", -- directly mapped to pd_status + "partners_intervention"."start", + "partners_intervention"."end", + "partners_intervention"."submission_date", + "partners_intervention"."submission_date_prc", + "partners_intervention"."review_date_prc", + "partners_intervention"."prc_review_document", + "partners_intervention"."signed_by_unicef_date", + "partners_intervention"."signed_by_partner_date", + "partners_intervention"."population_focus", + "partners_intervention"."agreement_id", + "partners_intervention"."unicef_signatory_id", + "partners_intervention"."signed_pd_document", + "partners_intervention"."country_programme_id", + "partners_intervention"."contingency_pd", + "partners_intervention"."metadata", + "partners_intervention"."in_amendment", + "partners_intervention"."reference_number_year", + "partners_intervention"."activation_letter", + "partners_intervention"."termination_doc", + "partners_intervention"."cfei_number", + "partners_intervention"."budget_owner_id", + "partners_intervention"."context", + "partners_intervention"."date_sent_to_partner", + "partners_intervention"."equity_narrative", + "partners_intervention"."equity_rating", + "partners_intervention"."gender_narrative", + "partners_intervention"."gender_rating", + "partners_intervention"."hq_support_cost", + "partners_intervention"."implementation_strategy", + "partners_intervention"."ip_program_contribution", + "partners_intervention"."partner_accepted", + "partners_intervention"."sustainability_narrative", + "partners_intervention"."sustainability_rating", + "partners_intervention"."unicef_accepted", + "partners_intervention"."unicef_court", + "partners_intervention"."unicef_review_type", + "partners_intervention"."humanitarian_flag", + "partners_intervention"."capacity_development", + "partners_intervention"."other_info", + "partners_intervention"."other_partners_involved", + "partners_intervention"."technical_guidance", + "partners_intervention"."cash_transfer_modalities", + "partners_intervention"."cancel_justification", + "partners_intervention"."date_partnership_review_performed", + "partners_intervention"."accepted_on_behalf_of_partner", + "partners_intervention"."activation_protocol", + "partners_intervention"."confidential", + "partners_intervention"."has_activities_involving_children", + "partners_intervention"."has_data_processing_agreement", + "partners_intervention"."has_special_conditions_for_construction", + "partners_intervention"."final_review_approved", + "partners_intervention"."other_details", + "partners_intervention"."partner_authorized_officer_signatory_id", + + "partners_agreement"."id", + "partners_agreement"."created", + "partners_agreement"."modified", + "partners_agreement"."start", + "partners_agreement"."end", + "partners_agreement"."agreement_type", + "partners_agreement"."agreement_number", + "partners_agreement"."attached_agreement", + "partners_agreement"."signed_by_unicef_date", + "partners_agreement"."signed_by_partner_date", + "partners_agreement"."partner_id", + "partners_agreement"."signed_by_id", + "partners_agreement"."status", + "partners_agreement"."country_programme_id", + "partners_agreement"."reference_number_year", + "partners_agreement"."special_conditions_pca", + "partners_agreement"."terms_acknowledged_by_id", + "partners_agreement"."partner_manager_id", + + "partners_partnerorganization"."id", + "partners_partnerorganization"."description", + "partners_partnerorganization"."address", + "partners_partnerorganization"."email", + "partners_partnerorganization"."phone_number", + "partners_partnerorganization"."alternate_id", + "partners_partnerorganization"."alternate_name", + "partners_partnerorganization"."rating", + "partners_partnerorganization"."core_values_assessment_date", + "partners_partnerorganization"."vision_synced", + "partners_partnerorganization"."type_of_assessment", + "partners_partnerorganization"."last_assessment_date", + "partners_partnerorganization"."hidden", + "partners_partnerorganization"."deleted_flag", + "partners_partnerorganization"."total_ct_cp", + "partners_partnerorganization"."total_ct_cy", + "partners_partnerorganization"."blocked", + "partners_partnerorganization"."city", + "partners_partnerorganization"."country", + "partners_partnerorganization"."postal_code", + "partners_partnerorganization"."shared_with", + "partners_partnerorganization"."street_address", + "partners_partnerorganization"."hact_values", + "partners_partnerorganization"."created", + "partners_partnerorganization"."modified", + "partners_partnerorganization"."net_ct_cy", + "partners_partnerorganization"."reported_cy", + "partners_partnerorganization"."total_ct_ytd", + "partners_partnerorganization"."basis_for_risk_rating", + "partners_partnerorganization"."manually_blocked", + "partners_partnerorganization"."outstanding_dct_amount_6_to_9_months_usd", + "partners_partnerorganization"."outstanding_dct_amount_more_than_9_months_usd", + "partners_partnerorganization"."highest_risk_rating_name", + "partners_partnerorganization"."highest_risk_rating_type", + "partners_partnerorganization"."psea_assessment_date", + "partners_partnerorganization"."sea_risk_rating_name", + "partners_partnerorganization"."lead_office_id", + "partners_partnerorganization"."lead_section_id", + "partners_partnerorganization"."organization_id", + + "organizations_organization"."id", + "organizations_organization"."created", + "organizations_organization"."modified", + "organizations_organization"."name", -- directly mapped to partner_name + "organizations_organization"."vendor_number", -- directly mapped to partner_vendor_number + "organizations_organization"."organization_type", + "organizations_organization"."cso_type", + "organizations_organization"."short_name", + "organizations_organization"."other", + "organizations_organization"."parent_id" + FROM "partners_interventionplannedvisits" + INNER JOIN "partners_intervention" ON ("partners_interventionplannedvisits"."intervention_id" = "partners_intervention"."id") + INNER JOIN "partners_agreement" ON ("partners_intervention"."agreement_id" = "partners_agreement"."id") + INNER JOIN "partners_partnerorganization" ON ("partners_agreement"."partner_id" = "partners_partnerorganization"."id") + INNER JOIN "organizations_organization" ON ("partners_partnerorganization"."organization_id" = "organizations_organization"."id") + ORDER BY "partners_interventionplannedvisits"."id" ASC + LIMIT ##PAGE_SIZE## OFFSET ##PAGE_OFFSET##; + """ + created = models.DateTimeField(blank=True, null=True) modified = models.DateTimeField(blank=True, null=True) diff --git a/src/etools_datamart/apps/mart/data/models/intervention_review.py b/src/etools_datamart/apps/mart/data/models/intervention_review.py index 89e5af83d..72fb9fad0 100644 --- a/src/etools_datamart/apps/mart/data/models/intervention_review.py +++ b/src/etools_datamart/apps/mart/data/models/intervention_review.py @@ -10,6 +10,181 @@ class InterventionReviewLoader(EtoolsLoader): + """ + SET search_path = public, ##COUNTRY##; + + -- + SELECT COUNT(*) AS "__count" + FROM "partners_interventionreview"; + + -- TODO: Pick only the required fields + -- + SELECT '##COUNTRY##' AS __schema, + "partners_interventionreview"."id", -- to source_id + "partners_interventionreview"."created", -- to review_created + "partners_interventionreview"."modified", -- to review_modified + "partners_interventionreview"."review_type", + "partners_interventionreview"."overall_approval", + "partners_interventionreview"."amendment_id", + "partners_interventionreview"."intervention_id", + "partners_interventionreview"."actions_list", + "partners_interventionreview"."budget_is_aligned", + "partners_interventionreview"."ges_considered", + "partners_interventionreview"."meeting_date", + "partners_interventionreview"."overall_approver_id", -- to overall_approver = get approver and set "{0.last_name} {0.first_name} ({0.email})".format(record.overall_approver) to overall_approver + "partners_interventionreview"."overall_comment", + "partners_interventionreview"."partner_comparative_advantage", -- to partner_comparative_advantage + "partners_interventionreview"."pd_is_guided", -- to pd_is_guided + "partners_interventionreview"."pd_is_relevant", -- to pd_is_relevant + "partners_interventionreview"."relationship_is_represented", -- to relationship_is_represented + "partners_interventionreview"."relationships_are_positive", -- to relationships_are_positive + "partners_interventionreview"."supply_issues_considered", + "partners_interventionreview"."submitted_by_id", -- to overall_approver = get submitted_by and set "{0.last_name} {0.first_name} ({0.email})".format(record.submitted_by) + "partners_interventionreview"."review_date", -- to review_date + "partners_interventionreview"."sent_back_comment", -- to sent_back_comment + + 'syria' AS __schema, "partners_intervention"."id", + "partners_intervention"."created", + "partners_intervention"."modified", + "partners_intervention"."document_type", + "partners_intervention"."number", -- to pd_number + "partners_intervention"."title", -- to title + "partners_intervention"."status", + "partners_intervention"."start", + "partners_intervention"."end", + "partners_intervention"."submission_date", + "partners_intervention"."submission_date_prc", + "partners_intervention"."review_date_prc", + "partners_intervention"."prc_review_document", + "partners_intervention"."signed_by_unicef_date", + "partners_intervention"."signed_by_partner_date", + "partners_intervention"."population_focus", + "partners_intervention"."agreement_id", + "partners_intervention"."unicef_signatory_id", + "partners_intervention"."signed_pd_document", + "partners_intervention"."country_programme_id", + "partners_intervention"."contingency_pd", + "partners_intervention"."metadata", + "partners_intervention"."in_amendment", + "partners_intervention"."reference_number_year", + "partners_intervention"."activation_letter", + "partners_intervention"."termination_doc", + "partners_intervention"."cfei_number", + "partners_intervention"."budget_owner_id", + "partners_intervention"."context", + "partners_intervention"."date_sent_to_partner", + "partners_intervention"."equity_narrative", + "partners_intervention"."equity_rating", + "partners_intervention"."gender_narrative", + "partners_intervention"."gender_rating", + "partners_intervention"."hq_support_cost", + "partners_intervention"."implementation_strategy", + "partners_intervention"."ip_program_contribution", + "partners_intervention"."partner_accepted", + "partners_intervention"."sustainability_narrative", + "partners_intervention"."sustainability_rating", + "partners_intervention"."unicef_accepted", + "partners_intervention"."unicef_court", + "partners_intervention"."unicef_review_type", + "partners_intervention"."humanitarian_flag", + "partners_intervention"."capacity_development", + "partners_intervention"."other_info", + "partners_intervention"."other_partners_involved", + "partners_intervention"."technical_guidance", + "partners_intervention"."cash_transfer_modalities", + "partners_intervention"."cancel_justification", + "partners_intervention"."date_partnership_review_performed", + "partners_intervention"."accepted_on_behalf_of_partner", + "partners_intervention"."activation_protocol", + "partners_intervention"."confidential", + "partners_intervention"."has_activities_involving_children", + "partners_intervention"."has_data_processing_agreement", + "partners_intervention"."has_special_conditions_for_construction", + "partners_intervention"."final_review_approved", + "partners_intervention"."other_details", + "partners_intervention"."partner_authorized_officer_signatory_id", + + "partners_agreement"."id", + "partners_agreement"."created", + "partners_agreement"."modified", + "partners_agreement"."start", + "partners_agreement"."end", + "partners_agreement"."agreement_type", + "partners_agreement"."agreement_number", + "partners_agreement"."attached_agreement", + "partners_agreement"."signed_by_unicef_date", + "partners_agreement"."signed_by_partner_date", + "partners_agreement"."partner_id", + "partners_agreement"."signed_by_id", + "partners_agreement"."status", + "partners_agreement"."country_programme_id", + "partners_agreement"."reference_number_year", + "partners_agreement"."special_conditions_pca", + "partners_agreement"."terms_acknowledged_by_id", + "partners_agreement"."partner_manager_id", + + "partners_partnerorganization"."id", + "partners_partnerorganization"."description", + "partners_partnerorganization"."address", + "partners_partnerorganization"."email", + "partners_partnerorganization"."phone_number", + "partners_partnerorganization"."alternate_id", + "partners_partnerorganization"."alternate_name", + "partners_partnerorganization"."rating", + "partners_partnerorganization"."core_values_assessment_date", + "partners_partnerorganization"."vision_synced", + "partners_partnerorganization"."type_of_assessment", + "partners_partnerorganization"."last_assessment_date", + "partners_partnerorganization"."hidden", + "partners_partnerorganization"."deleted_flag", + "partners_partnerorganization"."total_ct_cp", + "partners_partnerorganization"."total_ct_cy", + "partners_partnerorganization"."blocked", + "partners_partnerorganization"."city", + "partners_partnerorganization"."country", + "partners_partnerorganization"."postal_code", + "partners_partnerorganization"."shared_with", + "partners_partnerorganization"."street_address", + "partners_partnerorganization"."hact_values", + "partners_partnerorganization"."created", + "partners_partnerorganization"."modified", + "partners_partnerorganization"."net_ct_cy", + "partners_partnerorganization"."reported_cy", + "partners_partnerorganization"."total_ct_ytd", + "partners_partnerorganization"."basis_for_risk_rating", + "partners_partnerorganization"."manually_blocked", + "partners_partnerorganization"."outstanding_dct_amount_6_to_9_months_usd", + "partners_partnerorganization"."outstanding_dct_amount_more_than_9_months_usd", + "partners_partnerorganization"."highest_risk_rating_name", + "partners_partnerorganization"."highest_risk_rating_type", + "partners_partnerorganization"."psea_assessment_date", + "partners_partnerorganization"."sea_risk_rating_name", + "partners_partnerorganization"."lead_office_id", + "partners_partnerorganization"."lead_section_id", + "partners_partnerorganization"."organization_id", + + "organizations_organization"."id", + "organizations_organization"."created", + "organizations_organization"."modified", + "organizations_organization"."name", -- to partner + "organizations_organization"."vendor_number", -- to partner_vendor_number + "organizations_organization"."organization_type", -- to partner_type + "organizations_organization"."cso_type", -- to partner_cso_type + "organizations_organization"."short_name", + "organizations_organization"."other", + "organizations_organization"."parent_id" + + FROM "partners_interventionreview" + INNER JOIN "partners_intervention" ON ("partners_interventionreview"."intervention_id" = "partners_intervention"."id") + INNER JOIN "partners_agreement" ON ("partners_intervention"."agreement_id" = "partners_agreement"."id") + INNER JOIN "partners_partnerorganization" ON ("partners_agreement"."partner_id" = "partners_partnerorganization"."id") + INNER JOIN "organizations_organization" ON ("partners_partnerorganization"."organization_id" = "organizations_organization"."id") + ORDER BY "partners_interventionreview"."id" ASC + LIMIT ##PAGE_SIZE## OFFSET ##PAGE_OFFSET##; + + + """ + def get_overall_approver(self, record: PartnersInterventionreview, values: dict, **kwargs): if record.overall_approver: return "{0.last_name} {0.first_name} ({0.email})".format(record.overall_approver)