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 ea4e0a30..64ba820f 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 6e2e7ccc..a1a0a29e 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 63eabb4c..85230847 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 52c2570f..e52e8636 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 c64b6c15..38c7b84f 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):