Job creation v1

This commit is contained in:
rocketdebris 2026-01-08 17:06:21 -05:00
parent 181db2c4e6
commit 9803f0718c
3 changed files with 30 additions and 7 deletions

View File

@ -13,7 +13,7 @@ def after_insert(doc, method):
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")
def after_save(doc, method):
print("DEBUG: after_save hook triggered for Quotation:", doc.name)
if doc.custom_sent and doc.custom_response:
@ -21,7 +21,7 @@ def after_save(doc, method):
address_doc = frappe.get_doc("Address", doc.custom_installation_address)
address_doc.custom_estimate_sent_status = "Completed"
address_doc.save()
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)
@ -46,4 +46,4 @@ def on_update_after_submit(doc, method):
print("DEBUG: Sales Order created successfully:", new_sales_order.name)
except Exception as e:
print("ERROR creating Sales Order from Estimate:", str(e))
frappe.log_error(f"Error creating Sales Order from Estimate {doc.name}: {str(e)}", "Estimate on_update_after_submit Error")
frappe.log_error(f"Error creating Sales Order from Estimate {doc.name}: {str(e)}", "Estimate on_update_after_submit Error")

View File

@ -1,9 +1,31 @@
import frappe
def after_insert(doc, method):
pass
def on_submit(doc, method):
print(doc.as_dict())
# Create Invoice and Project from Sales Order
try:
print("Creating Project from Sales Order", doc.name)
sales_order = frappe.get_doc("Sales Order", doc.name)
project_template = frappe.get_doc("Project Template", "SNW Install")
new_job = frappe.get_doc({
"doctype": "Project",
"custom_installation_address": sales_order.custom_installation_address,
"project_name": sales_order.custom_installation_address,
"project_template": project_template,
"custom_warranty_duration_days": 90,
"sales_order": sales_order
})
new_job.insert()
frappe.db.commit()
except Exception as e:
print("ERROR creating Project from Sales Order:", str(e))
def create_sales_invoice_from_sales_order(doc, method):
try:
print("DEBUG: after_submit hook triggered for Sales Order:", doc.name)
@ -34,11 +56,11 @@ def create_sales_invoice_from_sales_order(doc, method):
"ignore_pricing_rule": 1,
"payment_schedule": doc.payment_schedule if not half_payment else [] # optional
})
invoice.insert()
invoice.submit()
frappe.db.commit()
return invoice
except Exception as e:
print("ERROR creating Sales Invoice from Sales Order:", str(e))
frappe.log_error(f"Error creating Sales Invoice from Sales Order {doc.name}: {str(e)}", "Sales Order after_submit Error")
frappe.log_error(f"Error creating Sales Invoice from Sales Order {doc.name}: {str(e)}", "Sales Order after_submit Error")

View File

@ -173,7 +173,8 @@ doc_events = {
"on_update_after_submit": "custom_ui.events.estimate.on_update_after_submit"
},
"Sales Order": {
"after_insert": "custom_ui.events.sales_order.after_insert"
"after_insert": "custom_ui.events.sales_order.after_insert",
"on_submit": "custom_ui.events.sales_order.on_submit",
}
}