moving towards real data

This commit is contained in:
Casey 2025-11-06 13:00:19 -06:00
parent ac3c05cb78
commit 40c4a5a37f
8 changed files with 303 additions and 84 deletions

View file

@ -1,5 +1,58 @@
import frappe, json
@frappe.whitelist()
def get_clients(options):
options = json.loads(options)
defaultOptions = {
"fields": ["*"],
"filters": {},
"sorting": {},
"page": 1,
"page_size": 10
}
options = {**defaultOptions, **options}
clients = []
count = frappe.db.count("Address", filters=options["filters"])
print("DEBUG: Total addresses count:", count)
addresses = frappe.db.get_all(
"Address",
fields=options["fields"],
filters=options["filters"],
limit=options["page_size"],
start=(options["page"] - 1) * options["page_size"],
order_by=(options["sorting"])
)
for address in addresses:
client = {}
print("DEBUG: Processing address:", address)
quotations = frappe.db.get_all(
"Quotation",
fields=["*"],
filters={"custom_installation_address": address["name"]}
)
jobs = frappe.db.get_all("Project",
fields=["*"],
filters={"custom_installation_address": address["name"],
"project_template": "SNW Install"})
client["address"] = address
client["on_site_meetings"] = []
client["jobs"] = jobs
client["quotations"] = quotations
clients.append(client)
return {
"count": count,
"page": options["page"],
"page_size": options["page_size"],
"clients": clients
}
@frappe.whitelist()
def upsert_client(data):
data = json.loads(data)
@ -15,17 +68,14 @@ def upsert_client(data):
"customer_name": data.get("customer_name"),
"customer_type": data.get("customer_type")
}).insert(ignore_permissions=True)
customer = customer_doc.name
else:
customer_doc = frappe.get_doc("Customer", customer)
print("Customer:", customer_doc.as_dict())
filters = {
"address_line1": data.get("address_line1"),
"city": data.get("city"),
"state": data.get("state"),
"country": "US",
"pincode": data.get("pincode")
"address_title": data.get("address_title"),
}
existing_address = frappe.db.exists("Address", filters)
print("Existing address check:", existing_address)
if existing_address:
frappe.throw(f"Address already exists for customer {data.get('customer_name')}.", frappe.ValidationError)
address_doc = frappe.get_doc({
@ -33,17 +83,19 @@ def upsert_client(data):
"address_line1": data.get("address_line1"),
"city": data.get("city"),
"state": data.get("state"),
"country": "US",
"country": "United States",
"address_title": data.get("address_title"),
"pincode": data.get("pincode"),
}).insert(ignore_permissions=True)
link = {
"link_doctype": "Customer",
"link_name": customer
"link_name": customer_doc.name
}
address_doc.append("links", link)
address_doc.save(ignore_permissions=True)
return {
"customer": customer.name,
"address": address_doc.name
"customer": customer_doc,
"address": address_doc,
"success": True
}