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)
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
}

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
# 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
# ---------------

View File

@ -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: () => {

View File

@ -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) => {