Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LCFS-1540: Filtering by Submitted Status on Compliance Reports results in 500 #1596

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 23 additions & 6 deletions backend/lcfs/web/api/compliance_report/repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,20 @@ def __init__(
self.db = db
self.fuel_supply_repo = fuel_supply_repo

def _convert_status_to_enum(self, value: str) -> ComplianceReportStatusEnum:
"""Helper to convert status string to enum value"""
enum_value_map = {
enum_val.value.lower(): enum_val for enum_val in ComplianceReportStatusEnum
}

# Handle both string and enum inputs
if isinstance(value, ComplianceReportStatusEnum):
return value

# Convert display value to enum name format
normalized_value = value.replace(" ", "_").lower()
return enum_value_map.get(normalized_value)

def apply_filters(self, pagination, conditions):
for filter in pagination.filters:
filter_value = filter.filter
Expand All @@ -74,12 +88,15 @@ def apply_filters(self, pagination, conditions):
filter_type = filter.filter_type
if filter.field == "status":
field = get_field_for_filter(ComplianceReportStatus, "status")
normalized_value = filter_value.lower()
enum_value_map = {
enum_val.value.lower(): enum_val
for enum_val in ComplianceReportStatusEnum
}
filter_value = enum_value_map.get(normalized_value)
if isinstance(filter_value, str):
enum_value = self._convert_status_to_enum(filter_value)
filter_value = enum_value.name if enum_value else filter_value
elif isinstance(filter_value, list):
filter_value = [
val.name if isinstance(val, ComplianceReportStatusEnum)
else (self._convert_status_to_enum(val).name if self._convert_status_to_enum(val) else val)
for val in filter_value
]
elif filter.field == "organization":
field = get_field_for_filter(Organization, "name")
elif filter.field == "type":
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/utils/grid/cellRenderers.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ export const ReportsStatusRenderer = (props) => {
'Recommended by analyst',
'Recommended by manager',
'Assessed',
'RecoReassessedrded'
'ReAssessed'
]
const statusColorArr = ['info', 'info', 'info', 'info', 'success', 'success']
const statusIndex = statusArr.indexOf(props.data.currentStatus.status)
Expand Down
Loading