add scripts for doctype changes

This commit is contained in:
Casey Wittrock 2025-11-10 09:51:01 -06:00
parent 80aae6f09b
commit a67e86af44
7 changed files with 115 additions and 76 deletions

View File

@ -89,7 +89,6 @@ def get_clients(options):
options = json.loads(options) options = json.loads(options)
print("DEBUG: Raw options received:", options) print("DEBUG: Raw options received:", options)
defaultOptions = { defaultOptions = {
"fields": ["*"],
"filters": {}, "filters": {},
"sorting": {}, "sorting": {},
"page": 1, "page": 1,
@ -121,7 +120,6 @@ def get_clients(options):
if isinstance(filter_obj, dict) and "value" in filter_obj: if isinstance(filter_obj, dict) and "value" in filter_obj:
if filter_obj["value"] is not None and filter_obj["value"] != "": if filter_obj["value"] is not None and filter_obj["value"] != "":
# Map frontend field names to backend field names # Map frontend field names to backend field names
backend_field = map_field_name(field_name)
# Handle different match modes # Handle different match modes
match_mode = filter_obj.get("matchMode", "contains") match_mode = filter_obj.get("matchMode", "contains")
@ -129,16 +127,16 @@ def get_clients(options):
match_mode = match_mode.lower() match_mode = match_mode.lower()
if match_mode in ("contains", "contains"): if match_mode in ("contains", "contains"):
processed_filters[backend_field] = ["like", f"%{filter_obj['value']}%"] processed_filters[field_name] = ["like", f"%{filter_obj['value']}%"]
elif match_mode in ("startswith", "startsWith"): elif match_mode in ("startswith", "startsWith"):
processed_filters[backend_field] = ["like", f"{filter_obj['value']}%"] processed_filters[field_name] = ["like", f"{filter_obj['value']}%"]
elif match_mode in ("endswith", "endsWith"): elif match_mode in ("endswith", "endsWith"):
processed_filters[backend_field] = ["like", f"%{filter_obj['value']}"] processed_filters[field_name] = ["like", f"%{filter_obj['value']}"]
elif match_mode in ("equals", "equals"): elif match_mode in ("equals", "equals"):
processed_filters[backend_field] = filter_obj["value"] processed_filters[field_name] = filter_obj["value"]
else: else:
# Default to contains # Default to contains
processed_filters[backend_field] = ["like", f"%{filter_obj['value']}%"] processed_filters[field_name] = ["like", f"%{filter_obj['value']}%"]
# Process sorting # Process sorting
order_by = None order_by = None
@ -153,6 +151,8 @@ def get_clients(options):
# Map frontend field to backend field # Map frontend field to backend field
backend_sort_field = map_field_name(sort_field) backend_sort_field = map_field_name(sort_field)
order_by = f"{backend_sort_field} {sort_direction}" order_by = f"{backend_sort_field} {sort_direction}"
else:
order_by = "modified desc"
print("DEBUG: Processed filters:", processed_filters) print("DEBUG: Processed filters:", processed_filters)
print("DEBUG: Order by:", order_by) print("DEBUG: Order by:", order_by)
@ -162,75 +162,75 @@ def get_clients(options):
addresses = frappe.db.get_all( addresses = frappe.db.get_all(
"Address", "Address",
fields=options["fields"], fields=["address_title", "custom_onsite_meeting_scheduled", "custom_estimate_sent_status", "custom_job_status", "custom_payment_received_status"],
filters=processed_filters, filters=processed_filters,
limit=options["page_size"], limit=options["page_size"],
start=(options["page"] - 1) * options["page_size"], start=(options["page"] - 1) * options["page_size"],
order_by=order_by order_by=order_by
) )
for address in addresses: # for address in addresses:
client = {} # client = {}
tableRow = {} # tableRow = {}
on_site_meetings = frappe.db.get_all( # on_site_meetings = frappe.db.get_all(
"On-Site Meeting", # "On-Site Meeting",
fields=["*"], # fields=["*"],
filters={"address": address["address_title"]} # filters={"address": address["address_title"]}
) # )
quotations = frappe.db.get_all( # quotations = frappe.db.get_all(
"Quotation", # "Quotation",
fields=["*"], # fields=["*"],
filters={"custom_installation_address": address["address_title"]} # filters={"custom_installation_address": address["address_title"]}
) # )
sales_orders = frappe.db.get_all( # sales_orders = frappe.db.get_all(
"Sales Order", # "Sales Order",
fields=["*"], # fields=["*"],
filters={"custom_installation_address": address["address_title"]} # filters={"custom_installation_address": address["address_title"]}
) # )
sales_invvoices = frappe.db.get_all( # sales_invvoices = frappe.db.get_all(
"Sales Invoice", # "Sales Invoice",
fields=["*"], # fields=["*"],
filters={"custom_installation_address": address["address_title"]} # filters={"custom_installation_address": address["address_title"]}
) # )
payment_entries = frappe.db.get_all( # payment_entries = frappe.db.get_all(
"Payment Entry", # "Payment Entry",
fields=["*"], # fields=["*"],
filters={"custom_installation_address": address["address_title"]} # filters={"custom_installation_address": address["address_title"]}
) # )
jobs = frappe.db.get_all( # jobs = frappe.db.get_all(
"Project", # "Project",
fields=["*"], # fields=["*"],
filters={ # filters={
"custom_installation_address": address["address_title"], # "custom_installation_address": address["address_title"],
"project_template": "SNW Install" # "project_template": "SNW Install"
} # }
) # )
tasks = frappe.db.get_all( # tasks = frappe.db.get_all(
"Task", # "Task",
fields=["*"], # fields=["*"],
filters={"project": jobs[0]["name"]} # filters={"project": jobs[0]["name"]}
) if jobs else [] # ) if jobs else []
tableRow["id"] = address["name"] # tableRow["id"] = address["name"]
tableRow["address_title"] = address["address_title"] # tableRow["address_title"] = address["address_title"]
tableRow["appointment_scheduled_status"] = calculate_appointment_scheduled_status(on_site_meetings[0]) if on_site_meetings else "Not Started" # tableRow["appointment_scheduled_status"] = calculate_appointment_scheduled_status(on_site_meetings[0]) if on_site_meetings else "Not Started"
tableRow["estimate_sent_status"] = calculate_estimate_sent_status(quotations[0]) if quotations else "Not Started" # tableRow["estimate_sent_status"] = calculate_estimate_sent_status(quotations[0]) if quotations else "Not Started"
tableRow["payment_received_status"] = calculate_payment_recieved_status(sales_invvoices[0], payment_entries) if sales_invvoices and payment_entries else "Not Started" # tableRow["payment_received_status"] = calculate_payment_recieved_status(sales_invvoices[0], payment_entries) if sales_invvoices and payment_entries else "Not Started"
tableRow["job_status"] = calculate_job_status(jobs[0], tasks) if jobs and tasks else "Not Started" # tableRow["job_status"] = calculate_job_status(jobs[0], tasks) if jobs and tasks else "Not Started"
tableRows.append(tableRow) # tableRows.append(tableRow)
client["address"] = address # client["address"] = address
client["on_site_meetings"] = on_site_meetings # client["on_site_meetings"] = on_site_meetings
client["jobs"] = jobs # client["jobs"] = jobs
client["quotations"] = quotations # client["quotations"] = quotations
clients.append(client) # clients.append(client)
return { return {
"pagination": { "pagination": {
@ -239,7 +239,7 @@ def get_clients(options):
"page_size": options["page_size"], "page_size": options["page_size"],
"total_pages": (count + options["page_size"] - 1) // options["page_size"] "total_pages": (count + options["page_size"] - 1) // options["page_size"]
}, },
"data": tableRows if options["for_table"] else clients "data": addresses
} }

View File

View File

@ -0,0 +1,11 @@
import frappe
def after_insert(doc, method):
print(doc.address)
frappe.msgprint(f"On-Site Meeting '{doc.name}' has been created. Updating related records...")
address_name = frappe.db.get_value("Address", fieldname="name", filters={"address_line1": doc.address})
address_doc = frappe.get_doc("Address", address_name)
frappe.msgprint(f"Related Address '{address_doc.address_title}' has been retrieved.")
address_doc.custom_onsite_meeting_scheduled = "Completed"
address_doc.save()
frappe.msgprint(f"Related Address '{address_doc.address_title}' has been updated with custom_onsite_meeting_scheduled = 'Completed'.")

View File

@ -0,0 +1,19 @@
import frappe
def after_insert(doc, method):
address_title = doc.custom_installation_address
address_name = frappe.db.get_value("Address", fieldname="name", filters={"address_title": address_title})
if address_name:
address_doc = frappe.get_doc("Address", address_name)
address_doc.custom_estimate_sent_status = "In Progress"
address_doc.save()
def after_save(doc, method):
if doc.custome_sent:
address_title = doc.custom_installation_address
address_name = frappe.db.get_value("Address", fieldname="name", filters={"address_title": address_title})
if address_name:
address_doc = frappe.get_doc("Address", address_name)
address_doc.custom_quotation_sent = "Completed"
address_doc.save()

View File

@ -158,13 +158,11 @@ add_to_apps_screen = [
# --------------- # ---------------
# Hook on document methods and events # Hook on document methods and events
# doc_events = { doc_events = {
# "*": { "On-Site Meeting": {
# "on_update": "method", "after_insert": "custom_ui.events.onsite_meeting.after_insert"
# "on_cancel": "method", }
# "on_trash": "method" }
# }
# }
# Scheduled Tasks # Scheduled Tasks
# --------------- # ---------------

View File

@ -38,10 +38,9 @@ const createButtons = ref([
}, },
}, },
{ {
label: "Job", label: "On-Site Meeting",
command: () => { command: () => {
//frappe.new_doc("Job"); modalStore.openModal("createOnsiteMeeting");
modalStore.openModal("createJob");
}, },
}, },
{ {
@ -51,6 +50,13 @@ const createButtons = ref([
modalStore.openModal("createEstimate"); modalStore.openModal("createEstimate");
}, },
}, },
{
label: "Job",
command: () => {
//frappe.new_doc("Job");
modalStore.openModal("createJob");
},
},
{ {
label: "Invoice", label: "Invoice",
command: () => { command: () => {

View File

@ -122,18 +122,23 @@ const columns = [
}, },
{ {
label: "Appt. Scheduled", label: "Appt. Scheduled",
fieldName: "appointmentScheduledStatus", fieldName: "customOnsiteMeetingScheduled",
type: "status",
sortable: true,
},
{
label: "Estimate Sent",
fieldName: "customEstimateSentStatus",
type: "status", type: "status",
sortable: true, sortable: true,
}, },
{ label: "Estimate Sent", fieldName: "estimateSentStatus", type: "status", sortable: true },
{ {
label: "Payment Received", label: "Payment Received",
fieldName: "paymentReceivedStatus", fieldName: "customPaymentReceivedStatus",
type: "status", type: "status",
sortable: true, sortable: true,
}, },
{ label: "Job Status", fieldName: "jobStatus", type: "status", sortable: true }, { label: "Job Status", fieldName: "customJobStatus", type: "status", sortable: true },
]; ];
// Handle lazy loading events from DataTable // Handle lazy loading events from DataTable
const handleLazyLoad = async (event) => { const handleLazyLoad = async (event) => {