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

fix: Fix Status Filters for Compliance Reports #1603

Merged
Merged
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
"""Rename Reassessed

Revision ID: e883ad1f0f60
Revises: 9329e38396e1
Create Date: 2025-01-03 23:31:19.098618

"""

import sqlalchemy as sa
from alembic import op
from alembic_postgresql_enum import TableReference

# revision identifiers, used by Alembic.
revision = "e883ad1f0f60"
down_revision = "9329e38396e1"
branch_labels = None
depends_on = None


def upgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.sync_enum_values(
"public",
"compliancereportstatusenum",
[
"Draft",
"Submitted",
"Recommended_by_analyst",
"Recommended_by_manager",
"Assessed",
"Reassessed",
],
[
TableReference(
table_schema="public",
table_name="compliance_report_status",
column_name="status",
)
],
enum_values_to_rename=[("ReAssessed", "Reassessed")],
)
# ### end Alembic commands ###


def downgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.sync_enum_values(
"public",
"compliancereportstatusenum",
[
"Draft",
"Submitted",
"Recommended_by_analyst",
"Recommended_by_manager",
"Assessed",
"ReAssessed",
],
[
TableReference(
table_schema="public",
table_name="compliance_report_status",
column_name="status",
)
],
enum_values_to_rename=[("Reassessed", "ReAssessed")],
)
# ### end Alembic commands ###
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class ComplianceReportStatusEnum(enum.Enum):
Recommended_by_analyst = "Recommended by analyst"
Recommended_by_manager = "Recommended by manager"
Assessed = "Assessed"
ReAssessed = "ReAssessed"
Reassessed = "Reassessed"


class ComplianceReportStatus(BaseModel, EffectiveDates):
Expand Down
26 changes: 13 additions & 13 deletions backend/lcfs/web/api/compliance_report/repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,14 @@ def apply_filters(self, pagination, conditions):
filter_option = filter.type
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)
field = get_field_for_filter(ComplianceReportStatus, filter.field)
if isinstance(filter_value, list):
filter_value = [
ComplianceReportStatusEnum(value) for value in filter_value
]
filter_type = "set"
else:
filter_value = ComplianceReportStatusEnum(filter_value)
elif filter.field == "organization":
field = get_field_for_filter(Organization, "name")
elif filter.field == "type":
Expand Down Expand Up @@ -359,12 +360,11 @@ async def get_reports_paginated(
.group_by(ComplianceReport.compliance_report_group_uuid)
)

if not organization_id:
subquery = subquery.join(
ComplianceReportStatus,
ComplianceReport.current_status_id
== ComplianceReportStatus.compliance_report_status_id,
)
subquery = subquery.join(
ComplianceReportStatus,
ComplianceReport.current_status_id
== ComplianceReportStatus.compliance_report_status_id,
)

subquery = subquery.subquery()
# Join the main ComplianceReport table with the subquery to get the latest version per group
Expand Down
2 changes: 1 addition & 1 deletion backend/lcfs/web/api/compliance_report/update_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ async def handle_status_change(
ComplianceReportStatusEnum.Recommended_by_analyst: self.handle_recommended_by_analyst_status,
ComplianceReportStatusEnum.Recommended_by_manager: self.handle_recommended_by_manager_status,
ComplianceReportStatusEnum.Assessed: self.handle_assessed_status,
ComplianceReportStatusEnum.ReAssessed: self.handle_reassessed_status,
ComplianceReportStatusEnum.Reassessed: self.handle_reassessed_status,
}

handler = status_handlers.get(new_status)
Expand Down
2 changes: 1 addition & 1 deletion backend/lcfs/web/api/notification/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ class NotificationRequestSchema(BaseSchema):
NotificationTypeEnum.IDIR_COMPLIANCE_MANAGER__COMPLIANCE_REPORT__DIRECTOR_ASSESSMENT,
NotificationTypeEnum.BCEID__COMPLIANCE_REPORT__DIRECTOR_ASSESSMENT,
],
ComplianceReportStatusEnum.ReAssessed: [
ComplianceReportStatusEnum.Reassessed: [
NotificationTypeEnum.IDIR_ANALYST__COMPLIANCE_REPORT__DIRECTOR_DECISION,
NotificationTypeEnum.IDIR_COMPLIANCE_MANAGER__COMPLIANCE_REPORT__DIRECTOR_ASSESSMENT,
NotificationTypeEnum.BCEID__COMPLIANCE_REPORT__DIRECTOR_ASSESSMENT,
Expand Down
Loading