From c842bcff12304623c8fb0da62c3ed1be0fe4036f Mon Sep 17 00:00:00 2001 From: Casey Date: Tue, 23 Dec 2025 08:21:12 -0600 Subject: [PATCH] sales order automation --- custom_ui/api/db/estimates.py | 3 ++- custom_ui/events/estimate.py | 4 +++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/custom_ui/api/db/estimates.py b/custom_ui/api/db/estimates.py index 64af73a..5bdad84 100644 --- a/custom_ui/api/db/estimates.py +++ b/custom_ui/api/db/estimates.py @@ -207,6 +207,7 @@ def manual_response(name, response): new_status = "Estimate Accepted" if accepted else "Lost" estimate.custom_response = response + estimate.custom_current_status = new_status # estimate.custom_current_status = new_status # estimate.status = "Ordered" if accepted else "Closed" estimate.flags.ignore_permissions = True @@ -311,7 +312,7 @@ def upsert_estimate(data): "customer_name": data.get("customer"), "customer_address": data.get("address_name"), "contact_person": data.get("contact_name"), - "letter_head": "company", + "letter_head": data.get("company"), }) for item in data.get("items", []): item = json.loads(item) if isinstance(item, str) else item diff --git a/custom_ui/events/estimate.py b/custom_ui/events/estimate.py index a78fae0..2e1c95c 100644 --- a/custom_ui/events/estimate.py +++ b/custom_ui/events/estimate.py @@ -24,10 +24,11 @@ def after_save(doc, method): def on_update_after_submit(doc, method): print("DEBUG: on_update_after_submit hook triggered for Quotation:", doc.name) + print("DEBUG: Current custom_current_status:", doc.custom_current_status) if doc.custom_current_status == "Estimate Accepted": doc.custom_current_status = "Won" print("DEBUG: Creating Sales Order from accepted Estimate") - address_doc = frappe.get_doc("Address", doc.custom_installation_address) + address_doc = frappe.get_doc("Address", doc.customer_address) address_doc.custom_estimate_sent_status = "Completed" address_doc.save() try: @@ -41,6 +42,7 @@ def on_update_after_submit(doc, method): new_sales_order.insert() print("DEBUG: Submitting Sales Order") new_sales_order.submit() + frappe.db.commit() print("DEBUG: Sales Order created successfully:", new_sales_order.name) except Exception as e: print("ERROR creating Sales Order from Estimate:", str(e))