job creation working

This commit is contained in:
Casey 2026-01-16 09:06:59 -06:00
parent bd9e00c6f1
commit d3818d1985
22 changed files with 591 additions and 179 deletions

View file

@ -310,7 +310,6 @@ def upsert_client(data):
"phone": primary_contact.get("phone_number"),
"custom_customer_name": customer_name,
"customer_type": customer_type,
"address_type": "Billing",
"companies": [{ "company": data.get("company_name")
}]
}
@ -338,7 +337,7 @@ def upsert_client(data):
"last_name": contact_data.get("last_name"),
"role": contact_data.get("contact_role", "Other"),
"custom_email": contact_data.get("email"),
"is_primary_contact":1 if contact_data.get("is_primary", False) else 0,
"is_primary_contact": 1 if contact_data.get("is_primary", False) else 0,
"customer_type": "Lead",
"customer_name": client_doc.name,
"email_ids": [{
@ -370,11 +369,13 @@ def upsert_client(data):
# Handle address creation
address_docs = []
for address in addresses:
is_billing = True if address.get("is_billing_address") else False
print("#####DEBUG: Creating address with data:", address)
address_doc = AddressService.create_address({
"address_title": build_address_title(customer_name, address),
"address_title": AddressService.build_address_title(customer_name, address),
"address_line1": address.get("address_line1"),
"address_line2": address.get("address_line2"),
"address_type": "Billing" if is_billing else "Service",
"city": address.get("city"),
"state": address.get("state"),
"country": "United States",
@ -385,6 +386,9 @@ def upsert_client(data):
})
AddressService.link_address_to_customer(address_doc, "Lead", client_doc.name)
address_doc.reload()
if is_billing:
client_doc.custom_billing_address = address_doc.name
client_doc.save(ignore_permissions=True)
for contact_to_link_idx in address.get("contacts", []):
contact_doc = contact_docs[contact_to_link_idx]
AddressService.link_address_to_contact(address_doc, contact_doc.name)

View file

@ -37,7 +37,7 @@ def get_estimate_table_data(filters={}, sortings=[], page=1, page_size=10):
tableRows = []
for estimate in estimates:
full_address = frappe.db.get_value("Address", estimate.get("custom_installation_address"), "full_address")
full_address = frappe.db.get_value("Address", estimate.get("custom_job_address"), "full_address")
tableRow = {}
tableRow["id"] = estimate["name"]
tableRow["address"] = full_address
@ -69,7 +69,7 @@ def get_estimate(estimate_name):
estimate = frappe.get_doc("Quotation", estimate_name)
est_dict = estimate.as_dict()
address_name = estimate.custom_installation_address or estimate.customer_address
address_name = estimate.custom_job_address or estimate.customer_address
if address_name:
# Fetch Address Doc
address_doc = frappe.get_doc("Address", address_name).as_dict()
@ -386,8 +386,6 @@ def upsert_estimate(data):
print("DEBUG: Upsert estimate data:", data)
address_doc = AddressService.get_or_throw(data.get("address_name"))
estimate_name = data.get("estimate_name")
client_doctype = ClientService.get_client_doctype(address_doc.customer_name)
print("DEBUG: Retrieved client doctype:", client_doctype)
project_template = data.get("project_template", None)
# If estimate_name exists, update existing estimate
@ -432,6 +430,12 @@ def upsert_estimate(data):
else:
print("DEBUG: Creating new estimate")
print("DEBUG: Retrieved address name:", data.get("address_name"))
client_doc = ClientService.get_client_or_throw(address_doc.customer_name)
# billing_address = next((addr for addr in address_doc if addr.address_type == "Billing"), None)
# if billing_address:
# print("DEBUG: Found billing address:", billing_address.name)
# else:
# print("DEBUG: No billing address found for client:", client_doc.name)
new_estimate = frappe.get_doc({
"doctype": "Quotation",
"custom_requires_half_payment": data.get("requires_half_payment", 0),
@ -441,9 +445,9 @@ def upsert_estimate(data):
"party_name": data.get("contact_name"),
"quotation_to": "Contact",
"company": data.get("company"),
"actual_customer_name": address_doc.customer_name,
"customer_type": client_doctype,
"customer_address": data.get("address_name"),
"actual_customer_name": client_doc.name,
"customer_type": address_doc.customer_type,
"customer_address": client_doc.custom_billing_address,
"contact_person": data.get("contact_name"),
"letter_head": data.get("company"),
"custom_project_template": data.get("project_template", None),

View file

@ -1,5 +1,6 @@
import frappe, json
from custom_ui.db_utils import process_query_conditions, build_datatable_dict, get_count_or_filters, build_success_response, build_error_response
from custom_ui.services import AddressService, ClientService
# ===============================================================================
# JOB MANAGEMENT API METHODS
@ -45,6 +46,10 @@ def get_job(job_id=""):
print("DEBUG: Loading Job from database:", job_id)
try:
project = frappe.get_doc("Project", job_id)
address_doc = AddressService.get_or_throw(project.job_address)
project = project.as_dict()
project["job_address"] = address_doc
project["client"] = ClientService.get_client_or_throw(project.customer)
return build_success_response(project)
except Exception as e:
return build_error_response(str(e), 500)

View file

@ -1,6 +1,18 @@
import frappe
from custom_ui.db_utils import process_query_conditions, build_datatable_dict, get_count_or_filters, build_success_response, build_error_response
from custom_ui.services import DbService
@frappe.whitelist()
def set_task_status(task_name, new_status):
"""Set the status of a specific task."""
try:
task = DbService.get_or_throw("Task", task_name)
task.status = new_status
task.save()
return build_success_response(f"Task {task_name} status updated to {new_status}.")
except Exception as e:
return build_error_response(str(e), 500)
@frappe.whitelist()
def get_job_task_list(job_id=""):