From f220aee16793e862ec4f81cdd75ba0b0343e2796 Mon Sep 17 00:00:00 2001 From: michaelglenister Date: Mon, 14 Oct 2024 13:27:25 +0200 Subject: [PATCH] Use all item codes Use all codes, not only those from the latest schema version --- municipal_finance/update/capital_facts_v2.py | 9 +-------- municipal_finance/update/cash_flow_v2.py | 9 +-------- .../update/financial_position_facts_v2.py | 10 +--------- municipal_finance/update/income_expenditure_v2.py | 9 +-------- 4 files changed, 4 insertions(+), 33 deletions(-) diff --git a/municipal_finance/update/capital_facts_v2.py b/municipal_finance/update/capital_facts_v2.py index e9bb8334b..614393d16 100644 --- a/municipal_finance/update/capital_facts_v2.py +++ b/municipal_finance/update/capital_facts_v2.py @@ -48,13 +48,6 @@ class CapitalFactsV2Updater(Updater): "functions": GovernmentFunctionsV2, "capital_types": CapitalTypeV2, } - schema_version = references_cls["items"].objects.aggregate(version=Max("version"))[ - "version" - ] - ref_items = references_cls["items"].objects.filter(version=schema_version) - item_map = {} - for item in ref_items: - item_map[str(item)] = item def build_unique_query(self, rows): return build_unique_query_params_with_period(rows) @@ -67,7 +60,7 @@ def row_to_obj(self, row): financial_period, ) = period_code_details(row.period_code) amount = int(row.amount) if row.amount else None - item = self.item_map[row.item_code] + item = self.references["items"][row.item_code] amount_type = self.references["amount_types"][amount_type_code] function = self.references["functions"][row.function_code] capital_type = self.references["capital_types"][row.capital_type_code] diff --git a/municipal_finance/update/cash_flow_v2.py b/municipal_finance/update/cash_flow_v2.py index db544be16..1465a2e8a 100644 --- a/municipal_finance/update/cash_flow_v2.py +++ b/municipal_finance/update/cash_flow_v2.py @@ -48,13 +48,6 @@ class CashFlowFactsV2Updater(Updater): "amount_types": AmountTypeV2, "items": CflowItemsV2, } - schema_version = references_cls["items"].objects.aggregate(version=Max("version"))[ - "version" - ] - ref_items = references_cls["items"].objects.filter(version=schema_version) - item_map = {} - for item in ref_items: - item_map[str(item)] = item def build_unique_query(self, rows): return build_unique_query_params_with_period(rows) @@ -67,7 +60,7 @@ def row_to_obj(self, row: CashFlowFactRow): financial_period, ) = period_code_details(row.period_code) amount = int(row.amount) if row.amount else None - item = self.item_map[row.item_code] + item = self.references["items"][row.item_code] amount_type = self.references["amount_types"][amount_type_code] return CflowFactsV2( demarcation_code=row.demarcation_code, diff --git a/municipal_finance/update/financial_position_facts_v2.py b/municipal_finance/update/financial_position_facts_v2.py index 0cabce7cf..91787db13 100644 --- a/municipal_finance/update/financial_position_facts_v2.py +++ b/municipal_finance/update/financial_position_facts_v2.py @@ -42,14 +42,6 @@ class FinancialPositionFactsUpdater(Updater): "items": FinancialPositionItemsV2, "amount_types": AmountTypeV2, } - schema_version = references_cls["items"].objects.aggregate(version=Max("version"))[ - "version" - ] - ref_items = references_cls["items"].objects.filter(version=schema_version) - - item_map = {} - for item in ref_items: - item_map[str(item)] = item def build_unique_query(self, rows): return build_unique_query_params_with_period(rows) @@ -62,7 +54,7 @@ def row_to_obj(self, row): financial_period, ) = period_code_details(row.period_code) amount = int(row.amount) if row.amount else None - item = self.item_map[row.item_code] + item = self.references["items"][row.item_code] amount_type = self.references["amount_types"][amount_type_code] return self.facts_cls( demarcation_code=row.demarcation_code, diff --git a/municipal_finance/update/income_expenditure_v2.py b/municipal_finance/update/income_expenditure_v2.py index b715005c5..1e619eb08 100644 --- a/municipal_finance/update/income_expenditure_v2.py +++ b/municipal_finance/update/income_expenditure_v2.py @@ -50,13 +50,6 @@ class IncomeExpenditureFactsV2Updater(Updater): "items": IncexpItemsV2, "functions": GovernmentFunctionsV2, } - schema_version = references_cls["items"].objects.aggregate(version=Max("version"))[ - "version" - ] - ref_items = references_cls["items"].objects.filter(version=schema_version) - item_map = {} - for item in ref_items: - item_map[str(item)] = item def build_unique_query(self, rows): return build_unique_query_params_with_period(rows) @@ -69,7 +62,7 @@ def row_to_obj(self, row: IncomeExpenditureFactRow): financial_period, ) = period_code_details(row.period_code) amount = int(row.amount) if row.amount else None - item = self.item_map[row.item_code] + item = self.references["items"][row.item_code] function = self.references["functions"][row.function_code] amount_type = self.references["amount_types"][amount_type_code] return IncexpFactsV2(