diff --git a/custom_ui/api/db/estimates.py b/custom_ui/api/db/estimates.py index 5b54659..d43d1eb 100644 --- a/custom_ui/api/db/estimates.py +++ b/custom_ui/api/db/estimates.py @@ -316,11 +316,19 @@ def manual_response(name, response): accepted = True if response == "Accepted" else False new_status = "Estimate Accepted" if accepted else "Lost" + # If the estimate hasn't been submitted yet, submit it first + # so that on_update_after_submit hooks fire (Lead conversion, SO/Project creation, etc.) + if estimate.docstatus == 0: + print("DEBUG: Estimate not yet submitted, submitting now before setting response.") + estimate.flags.ignore_permissions = True + estimate.submit() + estimate.custom_response = response estimate.custom_current_status = new_status estimate.flags.ignore_permissions = True print("DEBUG: Updating estimate with response:", response, "and status:", new_status) estimate.save() + frappe.db.commit() return build_success_response(estimate.as_dict()) except Exception as e: return build_error_response(str(e), 500)