Update app.py
Browse files
app.py
CHANGED
|
@@ -114,7 +114,7 @@ def summarize_text(text, max_length=100, min_length=30):
|
|
| 114 |
return text # Fallback to original text
|
| 115 |
|
| 116 |
# Create Salesforce record in custom object Project_Closure_Handover__c
|
| 117 |
-
def create_salesforce_record(score, checklist_summary, missing_summary, status, escalated, logs, qa_report, punch_list_text, open_punch_items, pdf_path=None):
|
| 118 |
if not SALESFORCE_AVAILABLE:
|
| 119 |
logging.error("Salesforce library not available. Skipping record creation.")
|
| 120 |
return "Salesforce library not available"
|
|
@@ -139,6 +139,7 @@ def create_salesforce_record(score, checklist_summary, missing_summary, status,
|
|
| 139 |
logs = str(logs) if logs else ""
|
| 140 |
qa_report = str(qa_report) if qa_report else ""
|
| 141 |
punch_list_text = str(punch_list_text) if punch_list_text else ""
|
|
|
|
| 142 |
missing_documents = len(missing_summary.split(", ")) if missing_summary and missing_summary != "None" else 0
|
| 143 |
open_punch_items = int(open_punch_items) if open_punch_items is not None else 0
|
| 144 |
evaluated_at = datetime.now().strftime("%Y-%m-%dT%H:%M:%SZ") # Salesforce Date/Time format
|
|
@@ -161,7 +162,8 @@ def create_salesforce_record(score, checklist_summary, missing_summary, status,
|
|
| 161 |
"Logs__c": logs,
|
| 162 |
"Open_Punch_Items__c": open_punch_items,
|
| 163 |
"Punch_List__c": punch_list_text,
|
| 164 |
-
"QA_Report__c": qa_report
|
|
|
|
| 165 |
}
|
| 166 |
|
| 167 |
logging.debug(f"Attempting to create Salesforce record in Project_Closure_Handover__c with data: {record}")
|
|
@@ -210,7 +212,7 @@ def create_salesforce_record(score, checklist_summary, missing_summary, status,
|
|
| 210 |
logging.error("Check the following in your Salesforce org:")
|
| 211 |
logging.error("- Ensure the user has Create and Edit permission on Project_Closure_Handover__c.")
|
| 212 |
logging.error("- Ensure the user has permission to create and read Attachments.")
|
| 213 |
-
logging.error("- Verify field-level security for all fields in the record.")
|
| 214 |
logging.error("- Check for validation rules or required fields that might be failing.")
|
| 215 |
return f"Salesforce error: {str(e)}"
|
| 216 |
except Exception as e:
|
|
@@ -390,6 +392,7 @@ with gr.Blocks(css="""
|
|
| 390 |
)
|
| 391 |
with gr.Row():
|
| 392 |
with gr.Column(scale=2):
|
|
|
|
| 393 |
logs_input = gr.Textbox(label="Project Logs", lines=5, placeholder="Enter project logs (e.g., 'Project complete, handover done')")
|
| 394 |
qa_input = gr.Dropdown(
|
| 395 |
label="QA Report",
|
|
@@ -433,7 +436,7 @@ with gr.Blocks(css="""
|
|
| 433 |
fn=create_salesforce_record,
|
| 434 |
inputs=[
|
| 435 |
score_output, checklist_output, missing_output, status_output,
|
| 436 |
-
gr.State(), gr.State(), gr.State(), gr.State(), open_punch_items_output, pdf_output
|
| 437 |
],
|
| 438 |
outputs=None
|
| 439 |
)
|
|
|
|
| 114 |
return text # Fallback to original text
|
| 115 |
|
| 116 |
# Create Salesforce record in custom object Project_Closure_Handover__c
|
| 117 |
+
def create_salesforce_record(score, checklist_summary, missing_summary, status, escalated, logs, qa_report, punch_list_text, open_punch_items, pdf_path=None, project_id=None):
|
| 118 |
if not SALESFORCE_AVAILABLE:
|
| 119 |
logging.error("Salesforce library not available. Skipping record creation.")
|
| 120 |
return "Salesforce library not available"
|
|
|
|
| 139 |
logs = str(logs) if logs else ""
|
| 140 |
qa_report = str(qa_report) if qa_report else ""
|
| 141 |
punch_list_text = str(punch_list_text) if punch_list_text else ""
|
| 142 |
+
project_id = str(project_id) if project_id else "" # Ensure project_id is a string
|
| 143 |
missing_documents = len(missing_summary.split(", ")) if missing_summary and missing_summary != "None" else 0
|
| 144 |
open_punch_items = int(open_punch_items) if open_punch_items is not None else 0
|
| 145 |
evaluated_at = datetime.now().strftime("%Y-%m-%dT%H:%M:%SZ") # Salesforce Date/Time format
|
|
|
|
| 162 |
"Logs__c": logs,
|
| 163 |
"Open_Punch_Items__c": open_punch_items,
|
| 164 |
"Punch_List__c": punch_list_text,
|
| 165 |
+
"QA_Report__c": qa_report,
|
| 166 |
+
"Project_ID__c": project_id # Added Project ID field
|
| 167 |
}
|
| 168 |
|
| 169 |
logging.debug(f"Attempting to create Salesforce record in Project_Closure_Handover__c with data: {record}")
|
|
|
|
| 212 |
logging.error("Check the following in your Salesforce org:")
|
| 213 |
logging.error("- Ensure the user has Create and Edit permission on Project_Closure_Handover__c.")
|
| 214 |
logging.error("- Ensure the user has permission to create and read Attachments.")
|
| 215 |
+
logging.error("- Verify field-level security for all fields in the record, including Project_ID__c.")
|
| 216 |
logging.error("- Check for validation rules or required fields that might be failing.")
|
| 217 |
return f"Salesforce error: {str(e)}"
|
| 218 |
except Exception as e:
|
|
|
|
| 392 |
)
|
| 393 |
with gr.Row():
|
| 394 |
with gr.Column(scale=2):
|
| 395 |
+
project_id_input = gr.Textbox(label="Project ID", placeholder="Enter Project ID (e.g., PROJ-1234)")
|
| 396 |
logs_input = gr.Textbox(label="Project Logs", lines=5, placeholder="Enter project logs (e.g., 'Project complete, handover done')")
|
| 397 |
qa_input = gr.Dropdown(
|
| 398 |
label="QA Report",
|
|
|
|
| 436 |
fn=create_salesforce_record,
|
| 437 |
inputs=[
|
| 438 |
score_output, checklist_output, missing_output, status_output,
|
| 439 |
+
gr.State(), gr.State(), gr.State(), gr.State(), open_punch_items_output, pdf_output, project_id_input
|
| 440 |
],
|
| 441 |
outputs=None
|
| 442 |
)
|