Skip to content

Commit

Permalink
Merge pull request #221 from dinesh-aot/COMP-317
Browse files Browse the repository at this point in the history
Close status for inspection
  • Loading branch information
dinesh-aot authored Feb 6, 2025
2 parents e5fbe7e + 2496a2a commit f77077f
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 13 deletions.
2 changes: 1 addition & 1 deletion compliance-api/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ install-dev: ## Install local application
ci: lint flake8 test ## CI flow

pylint: ## Linting with pylint
. venv/bin/activate && pylint --rcfile=setup.cfg src/$(PROJECT_NAME)
. venv/bin/activate && pylint --rcfile=setup.cfg --jobs=5 src/$(PROJECT_NAME)

flake8: ## Linting with flake8
. venv/bin/activate && flake8 --ignore=Q000,W503 src/$(PROJECT_NAME) tests
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
"""Remove closed as note status
Revision ID: 3aa492aa47db
Revises: 91f76d883f32
Create Date: 2025-02-06 13:22:09.682441
"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = '3aa492aa47db'
down_revision = '91f76d883f32'
branch_labels = None
depends_on = None


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.execute("UPDATE inspections set inspection_status='CLOSED' WHERE inspection_status='CLOSED_AS_NOTE'")
op.execute("UPDATE inspections_version SET inspection_status='CLOSED' WHERE inspection_status='CLOSED_AS_NOTE'")
op.execute("""
CREATE TYPE inspectionstatusenum_old AS ENUM ('OPEN', 'CLOSED', 'CANCELED');
""")
op.execute("""
ALTER TABLE inspections
ALTER COLUMN inspection_status TYPE inspectionstatusenum_old
USING inspection_status::text::inspectionstatusenum_old;
""")
op.execute("""
ALTER TABLE inspections_version
ALTER COLUMN inspection_status TYPE inspectionstatusenum_old
USING inspection_status::text::inspectionstatusenum_old;
""")
op.execute("DROP TYPE inspectionstatusenum;")
op.execute("ALTER TYPE inspectionstatusenum_old RENAME TO inspectionstatusenum;")

# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
pass

# ### end Alembic commands ###
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,4 @@ class InspectionStatusEnum(enum.Enum):

OPEN = "Open"
CLOSED = "Closed"
CLOSED_AS_NOTE = "Closed as note"
CANCELED = "Canceled"
12 changes: 7 additions & 5 deletions compliance-api/src/compliance_api/schemas/inspection.py
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,12 @@ class Meta: # pylint: disable=too-few-public-methods
metadata={"description": "The status of the complaint"},
required=True,
)
alt_status_text = fields.Str(
metadata={
"description": "Alternate text for the status to be written to continuation report"
},
allow_none=True
)

@post_load
def extract_status_value(
Expand All @@ -390,11 +396,7 @@ def validate_status(
"""Ensure only Closed and Canceled status are passed."""
# Retrieve the context to access other fields
status = data.get("status")
if status not in [
InspectionStatusEnum.CANCELED,
InspectionStatusEnum.CLOSED,
InspectionStatusEnum.CLOSED_AS_NOTE
]:
if status not in [InspectionStatusEnum.CANCELED, InspectionStatusEnum.CLOSED]:
raise ValidationError(
"Invalid status value passed",
field_name="status",
Expand Down
2 changes: 1 addition & 1 deletion compliance-api/src/compliance_api/services/inspection.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ def change_status(cls, inspection_id, status):
inspection.id,
inspection.ir_number,
inspection.case_file_id,
status_enum.value.lower(),
status.get("alt_status_text", status_enum.value).lower()
)
ContinuationReportService.create(
cr_entry, sys_generated=True, ho_session=session
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,10 @@ const InspectionFileActions: React.FC<InspectionFileActionsProps> = ({
),
});
},
hidden: ["canceled", "closed", "closed as note"].includes(status?.toLowerCase()),
hidden: ["canceled", "closed"].includes(status?.toLowerCase()),
},
{
text: "Close as Note to File",
text: "Closed as note to file",
onClick: () => {
// Handle closing inspection
setOpen({
Expand All @@ -88,15 +88,18 @@ const InspectionFileActions: React.FC<InspectionFileActionsProps> = ({
onConfirm={() => {
updateInspectionInspection({
id: inspectionData?.id ?? 0,
inspectionStatus: { status: "CLOSED_AS_NOTE" },
inspectionStatus: {
status: "CLOSED",
alt_status_text: "Closed as note to file",
},
});
}}
/>
),
width: "420px",
});
},
hidden: ["canceled", "closed as note", "closed"].includes(status?.toLowerCase()),
hidden: ["canceled", "closed"].includes(status?.toLowerCase()),
},
{
text: "Closed",
Expand All @@ -119,7 +122,7 @@ const InspectionFileActions: React.FC<InspectionFileActionsProps> = ({
width: "420px",
});
},
hidden: ["canceled", "closed", "closed as note"].includes(status?.toLowerCase()),
hidden: ["canceled", "closed"].includes(status?.toLowerCase()),
},
{
text: "Delete Inspection",
Expand Down
1 change: 1 addition & 0 deletions compliance-web/src/models/Inspection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,5 @@ export interface InspectionAPIData {

export interface InspectionStatusAPIData {
status: string;
alt_status_text: string;
}

0 comments on commit f77077f

Please sign in to comment.