diff --git a/custom_ui/api/db/estimates.py b/custom_ui/api/db/estimates.py index 1e9b16a..605365f 100644 --- a/custom_ui/api/db/estimates.py +++ b/custom_ui/api/db/estimates.py @@ -96,11 +96,10 @@ def upsert_estimate(data): print("DOIFJSEOFJISLFK") try: data = json.loads(data) if isinstance(data, str) else data - print("DEBUG: Upsert estimate data received:", data) - address_name = frappe.get_value("Address", fieldname="name", filters={"full_address": data.get("address")}) + print("DEBUG: Retrieved address name:", data.get("address_name")) new_estimate = frappe.get_doc({ "doctype": "Quotation", - "custom_installation_address": address_name, + "custom_installation_address": data.get("address_name"), "contact_email": data.get("contact_email"), "party_name": data.get("contact_name"), "customer_name": data.get("customer_name"), diff --git a/custom_ui/events/estimate.py b/custom_ui/events/estimate.py new file mode 100644 index 0000000..7f004bc --- /dev/null +++ b/custom_ui/events/estimate.py @@ -0,0 +1,21 @@ +import frappe + +def after_insert(doc, method): + try: + print("DEBUG: after_insert hook triggered for Quotation:", doc.name) + print("DEBUG: custom_installation_address:", doc.custom_installation_address) + + if not doc.custom_installation_address: + print("ERROR: custom_installation_address is empty") + return + + address_doc = frappe.get_doc("Address", doc.custom_installation_address) + print("DEBUG: Retrieved address document:", address_doc.name) + + address_doc.custom_estimate_sent_status = "In Progress" + address_doc.save() + print("DEBUG: Address status updated successfully") + + except Exception as e: + print("ERROR in after_insert hook:", str(e)) + frappe.log_error(f"Error in estimate after_insert: {str(e)}", "Estimate Hook Error") \ No newline at end of file diff --git a/custom_ui/hooks.py b/custom_ui/hooks.py index 801b001..e4b9cbe 100644 --- a/custom_ui/hooks.py +++ b/custom_ui/hooks.py @@ -165,6 +165,9 @@ doc_events = { "Address": { "after_insert": "custom_ui.events.address.after_insert" }, + "Quotation": { + "after_insert": "custom_ui.events.estimate.after_insert" + } } # Scheduled Tasks