diff --git a/domain/sap10_calculator/tables/table_32.py b/domain/sap10_calculator/tables/table_32.py index da22b5ce..6eee48df 100644 --- a/domain/sap10_calculator/tables/table_32.py +++ b/domain/sap10_calculator/tables/table_32.py @@ -107,6 +107,12 @@ API_FUEL_TO_TABLE_32: Final[dict[int, int]] = { 10: 30, 11: 42, 12: 43, 13: 44, 14: 11, 15: 12, 16: 22, 17: 9, 18: 75, 19: 76, 20: 51, 21: 52, 22: 53, 23: 55, 24: 54, 25: 41, 26: 1, 27: 2, 28: 4, 29: 30, 30: 42, 31: 43, 32: 44, 33: 11, + # SAP Table 12 code 39 = "electricity, any tariff" (epc_codes.csv main_fuel + # 39 = "electricity, unspecified tariff"; spec footnote (j): defines an + # electric system, cost/CO2/PE = standard electricity). Resolve to standard + # electricity (30) so it classifies as electric and prices at the standard + # rate — otherwise it now raises UnpricedFuelCode (was: mis-rated non-electric). + 39: 30, } # Gov-API `main_fuel_type` enum codes whose value COLLIDES with a diff --git a/tests/domain/billing/test_sap_fuel.py b/tests/domain/billing/test_sap_fuel.py index 98bc5c23..dda833a5 100644 --- a/tests/domain/billing/test_sap_fuel.py +++ b/tests/domain/billing/test_sap_fuel.py @@ -43,6 +43,7 @@ def test_table_32_codes_map_to_their_billing_fuel(code: int, fuel: Fuel) -> None (0, Fuel.ELECTRICITY), # API "electricity" -> Table 32 code 30 (25, Fuel.HEAT_NETWORK), # API community heat -> Table 32 code 41 (14, Fuel.COAL), # API house coal -> Table 32 code 11 + (39, Fuel.ELECTRICITY), # "electricity, any tariff" -> Table 32 code 30 ], ) def test_raw_api_fuel_codes_normalize_before_mapping(api_code: int, fuel: Fuel) -> None: diff --git a/tests/domain/sap10_calculator/test_table_32.py b/tests/domain/sap10_calculator/test_table_32.py index 59e2c93c..e8fb4ab2 100644 --- a/tests/domain/sap10_calculator/test_table_32.py +++ b/tests/domain/sap10_calculator/test_table_32.py @@ -339,3 +339,19 @@ def test_additional_standing_charges_zero_for_oil_only() -> None: # Assert assert standing == 0.0 + + +def test_electricity_any_tariff_code_39_resolves_to_standard_electricity() -> None: + # SAP Table 12 code 39 = "electricity, any tariff" (epc_codes.csv main_fuel 39 + # = "electricity, unspecified tariff"; spec footnote (j): defines an electric + # system, cost = standard tariff). It must classify as electric and price at + # the standard-electricity rate — without the mapping it raises UnpricedFuelCode + # and is_electric_fuel_code(39) is False (mis-rated as non-electric). + from domain.sap10_calculator.tables.table_32 import ( + is_electric_fuel_code, + to_table_32_code, + ) + + assert to_table_32_code(39) == 30 + assert is_electric_fuel_code(39) is True + assert unit_price_p_per_kwh(39) == unit_price_p_per_kwh(30)