Skip to content
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
3 changes: 2 additions & 1 deletion audit_management/patches.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ audit_management.patches.migrate_production_data_v3
audit_management.patches.migrate_production_data_v4
audit_management.patches.migrate_hardcoded_to_child_table
audit_management.patches.update_audit_level_branch_fields
audit_management.patches.fix_status_mispelling
audit_management.patches.fix_status_mispelling
audit_management.patches.fix_fake_responded_status
64 changes: 64 additions & 0 deletions audit_management/patches/fix_fake_responded_status.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import frappe

def execute():
"""
Patch to fix incorrect 'Responded' status.
Converts 'Responded' -> 'No Response' if:
- Status is 'Responded'
- Response is empty/blank
- pending_time exists
"""

# Mapping for legacy field synchronization
mapping = {
"BM": "bm",
"DH": "dh",
"COM": "com",
"RM": "rm",
"ROM": "rom",
"ZM": "zm",
"ZOM": "zom",
"GM": "gm",
"HR": "hr",
"CHRO": "chro",
"COO": "coo",
"CFO": "cfo",
"CEO": "ceo",
}

# Fetch all My Audits documents
audit_docs = frappe.get_all("My Audits", pluck="name")

count = 0
for docname in audit_docs:
doc = frappe.get_doc("My Audits", docname)
updated = False

for row in doc.audit_stages:
# Check conditions for corruption
if (row.status == "Responded" and
(not row.response or not str(row.response).strip()) and
row.pending_time):

# 1. Update child table
row.status = "No Response"

# 2. Sync to legacy hardcoded fields
prefix = mapping.get((row.stage_name or "").strip().upper())
if prefix:
doc.set(f"{prefix}_user_status", "No Response")
doc.set(f"{prefix}_response_box", None)

updated = True
frappe.log_error(
title="Patch Fix: Status Corrected",
message=f"Audit: {docname}, Stage: {row.stage_name}, User: {row.user_id}, Row ID: {row.name}"
)

if updated:
# Save without triggering unnecessary validations
doc.save(ignore_permissions=True)
count += 1

frappe.db.commit()
frappe.logger().info(f"Patch complete. {count} audit records updated.")
Loading