diff --git a/backend/lcfs/db/migrations/versions/2025-01-03-23-31_e883ad1f0f60.py b/backend/lcfs/db/migrations/versions/2025-01-03-23-31_e883ad1f0f60.py new file mode 100644 index 000000000..eab360311 --- /dev/null +++ b/backend/lcfs/db/migrations/versions/2025-01-03-23-31_e883ad1f0f60.py @@ -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 ### diff --git a/backend/lcfs/db/models/compliance/ComplianceReportStatus.py b/backend/lcfs/db/models/compliance/ComplianceReportStatus.py index ee366c8a1..ffd0b5c00 100644 --- a/backend/lcfs/db/models/compliance/ComplianceReportStatus.py +++ b/backend/lcfs/db/models/compliance/ComplianceReportStatus.py @@ -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): diff --git a/backend/lcfs/web/api/compliance_report/repo.py b/backend/lcfs/web/api/compliance_report/repo.py index ff7abcfcb..a0bf833a9 100644 --- a/backend/lcfs/web/api/compliance_report/repo.py +++ b/backend/lcfs/web/api/compliance_report/repo.py @@ -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": @@ -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 diff --git a/backend/lcfs/web/api/compliance_report/update_service.py b/backend/lcfs/web/api/compliance_report/update_service.py index d58c51cff..47b73ff8a 100644 --- a/backend/lcfs/web/api/compliance_report/update_service.py +++ b/backend/lcfs/web/api/compliance_report/update_service.py @@ -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) diff --git a/backend/lcfs/web/api/notification/schema.py b/backend/lcfs/web/api/notification/schema.py index 31f0f7270..d351e8840 100644 --- a/backend/lcfs/web/api/notification/schema.py +++ b/backend/lcfs/web/api/notification/schema.py @@ -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,