From a67e86af44d36ae0bcfddae0b22970e54e578e59 Mon Sep 17 00:00:00 2001 From: Casey Wittrock Date: Mon, 10 Nov 2025 09:51:01 -0600 Subject: [PATCH] add scripts for doctype changes --- custom_ui/api/db.py | 124 +++++++++++----------- custom_ui/events/__init__.py | 0 custom_ui/events/onsite_meeting.py | 11 ++ custom_ui/events/quotation.py | 19 ++++ custom_ui/hooks.py | 12 +-- frontend/src/components/SideBar.vue | 12 ++- frontend/src/components/pages/Clients.vue | 13 ++- 7 files changed, 115 insertions(+), 76 deletions(-) create mode 100644 custom_ui/events/__init__.py create mode 100644 custom_ui/events/onsite_meeting.py create mode 100644 custom_ui/events/quotation.py diff --git a/custom_ui/api/db.py b/custom_ui/api/db.py index d84e81c..9d152f2 100644 --- a/custom_ui/api/db.py +++ b/custom_ui/api/db.py @@ -89,7 +89,6 @@ def get_clients(options): options = json.loads(options) print("DEBUG: Raw options received:", options) defaultOptions = { - "fields": ["*"], "filters": {}, "sorting": {}, "page": 1, @@ -121,7 +120,6 @@ def get_clients(options): if isinstance(filter_obj, dict) and "value" in filter_obj: if filter_obj["value"] is not None and filter_obj["value"] != "": # Map frontend field names to backend field names - backend_field = map_field_name(field_name) # Handle different match modes match_mode = filter_obj.get("matchMode", "contains") @@ -129,16 +127,16 @@ def get_clients(options): match_mode = match_mode.lower() 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"): - processed_filters[backend_field] = ["like", f"{filter_obj['value']}%"] + processed_filters[field_name] = ["like", f"{filter_obj['value']}%"] 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"): - processed_filters[backend_field] = filter_obj["value"] + processed_filters[field_name] = filter_obj["value"] else: # Default to contains - processed_filters[backend_field] = ["like", f"%{filter_obj['value']}%"] + processed_filters[field_name] = ["like", f"%{filter_obj['value']}%"] # Process sorting order_by = None @@ -153,6 +151,8 @@ def get_clients(options): # Map frontend field to backend field backend_sort_field = map_field_name(sort_field) order_by = f"{backend_sort_field} {sort_direction}" + else: + order_by = "modified desc" print("DEBUG: Processed filters:", processed_filters) print("DEBUG: Order by:", order_by) @@ -162,75 +162,75 @@ def get_clients(options): addresses = frappe.db.get_all( "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, limit=options["page_size"], start=(options["page"] - 1) * options["page_size"], order_by=order_by ) - for address in addresses: - client = {} - tableRow = {} + # for address in addresses: + # client = {} + # tableRow = {} - on_site_meetings = frappe.db.get_all( - "On-Site Meeting", - fields=["*"], - filters={"address": address["address_title"]} - ) + # on_site_meetings = frappe.db.get_all( + # "On-Site Meeting", + # fields=["*"], + # filters={"address": address["address_title"]} + # ) - quotations = frappe.db.get_all( - "Quotation", - fields=["*"], - filters={"custom_installation_address": address["address_title"]} - ) + # quotations = frappe.db.get_all( + # "Quotation", + # fields=["*"], + # filters={"custom_installation_address": address["address_title"]} + # ) - sales_orders = frappe.db.get_all( - "Sales Order", - fields=["*"], - filters={"custom_installation_address": address["address_title"]} - ) + # sales_orders = frappe.db.get_all( + # "Sales Order", + # fields=["*"], + # filters={"custom_installation_address": address["address_title"]} + # ) - sales_invvoices = frappe.db.get_all( - "Sales Invoice", - fields=["*"], - filters={"custom_installation_address": address["address_title"]} - ) + # sales_invvoices = frappe.db.get_all( + # "Sales Invoice", + # fields=["*"], + # filters={"custom_installation_address": address["address_title"]} + # ) - payment_entries = frappe.db.get_all( - "Payment Entry", - fields=["*"], - filters={"custom_installation_address": address["address_title"]} - ) + # payment_entries = frappe.db.get_all( + # "Payment Entry", + # fields=["*"], + # filters={"custom_installation_address": address["address_title"]} + # ) - jobs = frappe.db.get_all( - "Project", - fields=["*"], - filters={ - "custom_installation_address": address["address_title"], - "project_template": "SNW Install" - } - ) + # jobs = frappe.db.get_all( + # "Project", + # fields=["*"], + # filters={ + # "custom_installation_address": address["address_title"], + # "project_template": "SNW Install" + # } + # ) - tasks = frappe.db.get_all( - "Task", - fields=["*"], - filters={"project": jobs[0]["name"]} - ) if jobs else [] + # tasks = frappe.db.get_all( + # "Task", + # fields=["*"], + # filters={"project": jobs[0]["name"]} + # ) if jobs else [] - tableRow["id"] = address["name"] - 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["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["job_status"] = calculate_job_status(jobs[0], tasks) if jobs and tasks else "Not Started" - tableRows.append(tableRow) + # tableRow["id"] = address["name"] + # 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["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["job_status"] = calculate_job_status(jobs[0], tasks) if jobs and tasks else "Not Started" + # tableRows.append(tableRow) - client["address"] = address - client["on_site_meetings"] = on_site_meetings - client["jobs"] = jobs - client["quotations"] = quotations - clients.append(client) + # client["address"] = address + # client["on_site_meetings"] = on_site_meetings + # client["jobs"] = jobs + # client["quotations"] = quotations + # clients.append(client) return { "pagination": { @@ -239,7 +239,7 @@ def get_clients(options): "page_size": options["page_size"], "total_pages": (count + options["page_size"] - 1) // options["page_size"] }, - "data": tableRows if options["for_table"] else clients + "data": addresses } diff --git a/custom_ui/events/__init__.py b/custom_ui/events/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/custom_ui/events/onsite_meeting.py b/custom_ui/events/onsite_meeting.py new file mode 100644 index 0000000..be3904c --- /dev/null +++ b/custom_ui/events/onsite_meeting.py @@ -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'.") \ No newline at end of file diff --git a/custom_ui/events/quotation.py b/custom_ui/events/quotation.py new file mode 100644 index 0000000..d6b5334 --- /dev/null +++ b/custom_ui/events/quotation.py @@ -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() \ No newline at end of file diff --git a/custom_ui/hooks.py b/custom_ui/hooks.py index 545b2b2..e937b2d 100644 --- a/custom_ui/hooks.py +++ b/custom_ui/hooks.py @@ -158,13 +158,11 @@ add_to_apps_screen = [ # --------------- # Hook on document methods and events -# doc_events = { -# "*": { -# "on_update": "method", -# "on_cancel": "method", -# "on_trash": "method" -# } -# } +doc_events = { + "On-Site Meeting": { + "after_insert": "custom_ui.events.onsite_meeting.after_insert" + } +} # Scheduled Tasks # --------------- diff --git a/frontend/src/components/SideBar.vue b/frontend/src/components/SideBar.vue index abe379f..91b10e2 100644 --- a/frontend/src/components/SideBar.vue +++ b/frontend/src/components/SideBar.vue @@ -38,10 +38,9 @@ const createButtons = ref([ }, }, { - label: "Job", + label: "On-Site Meeting", command: () => { - //frappe.new_doc("Job"); - modalStore.openModal("createJob"); + modalStore.openModal("createOnsiteMeeting"); }, }, { @@ -51,6 +50,13 @@ const createButtons = ref([ modalStore.openModal("createEstimate"); }, }, + { + label: "Job", + command: () => { + //frappe.new_doc("Job"); + modalStore.openModal("createJob"); + }, + }, { label: "Invoice", command: () => { diff --git a/frontend/src/components/pages/Clients.vue b/frontend/src/components/pages/Clients.vue index b79da30..cd283ca 100644 --- a/frontend/src/components/pages/Clients.vue +++ b/frontend/src/components/pages/Clients.vue @@ -122,18 +122,23 @@ const columns = [ }, { label: "Appt. Scheduled", - fieldName: "appointmentScheduledStatus", + fieldName: "customOnsiteMeetingScheduled", + type: "status", + sortable: true, + }, + { + label: "Estimate Sent", + fieldName: "customEstimateSentStatus", type: "status", sortable: true, }, - { label: "Estimate Sent", fieldName: "estimateSentStatus", type: "status", sortable: true }, { label: "Payment Received", - fieldName: "paymentReceivedStatus", + fieldName: "customPaymentReceivedStatus", type: "status", 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 const handleLazyLoad = async (event) => {