Skip to content

Commit 62a8483

Browse files
committed
chore: do not validate allocations when methodology is N/A
1 parent 41931a9 commit 62a8483

File tree

1 file changed

+23
-9
lines changed

1 file changed

+23
-9
lines changed

bc_obps/reporting/service/report_validation/validators/report_emission_allocation_validator.py

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,34 @@
88

99

1010
def validate(report_version: ReportVersion) -> dict[str, ReportValidationError]:
11+
"""
12+
Validates emission allocation data for all facility reports associated with a given report version.
13+
14+
For each facility report, checks that the sum of allocated emission quantities for each product category
15+
matches the reported emission total, unless the allocation methodology is "Not applicable".
16+
Returns a dictionary of errors keyed by facility and emission category if mismatches are found.
17+
18+
Args:
19+
report_version (ReportVersion): The report version to validate.
20+
21+
Returns:
22+
dict[str, ReportValidationError]: A dictionary of validation errors, keyed by facility and category.
23+
"""
1124

1225
facility_reports = FacilityReport.objects.filter(report_version=report_version)
1326

1427
errors = {}
1528

1629
for fr in facility_reports:
1730
emission_data = ReportEmissionAllocationService.get_emission_allocation_data(report_version.id, fr.facility_id)
18-
for category in emission_data.report_product_emission_allocations:
19-
total_allocated = sum(product.allocated_quantity for product in category.products)
20-
if total_allocated != category.emission_total:
21-
errors[
22-
f"facility_{fr.facility_id}_category_{category.emission_category_id}_allocation_mismatch"
23-
] = ReportValidationError(
24-
Severity.ERROR,
25-
f"Allocated emissions for {fr.facility_name} in '{category.emission_category_name}' category do not match reported emissions.",
26-
)
31+
if emission_data.allocation_methodology != "Not applicable":
32+
for category in emission_data.report_product_emission_allocations:
33+
total_allocated = sum(product.allocated_quantity for product in category.products)
34+
if total_allocated != category.emission_total:
35+
errors[
36+
f"facility_{fr.facility_id}_category_{category.emission_category_id}_allocation_mismatch"
37+
] = ReportValidationError(
38+
Severity.ERROR,
39+
f"Allocated emissions for {fr.facility_name} in '{category.emission_category_name}' category do not match reported emissions.",
40+
)
2741
return errors

0 commit comments

Comments
 (0)