Fixed merge conflict.
This commit is contained in:
parent
c35689aaf8
commit
3fa8b1ce99
@ -95,7 +95,7 @@ def get_client(client_name):
|
||||
clientData = {"addresses": [], "contacts": [], "jobs": [], "sales_invoices": [], "payment_entries": [], "sales_orders": [], "tasks": []}
|
||||
customer = frappe.get_doc("Customer", client_name)
|
||||
clientData = {**clientData, **customer.as_dict()}
|
||||
|
||||
|
||||
for contact_link in customer.custom_add_contacts:
|
||||
contact_doc = frappe.get_doc("Contact", contact_link.contact)
|
||||
clientData["contacts"].append(contact_doc.as_dict())
|
||||
@ -131,19 +131,20 @@ def get_client(client_name):
|
||||
return build_error_response(str(ve), 400)
|
||||
except Exception as e:
|
||||
return build_error_response(str(e), 500)
|
||||
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_clients_table_data(filters={}, sortings=[], page=1, page_size=10):
|
||||
"""Get paginated client table data with filtering and sorting support."""
|
||||
try:
|
||||
|
||||
|
||||
print("DEBUG: Raw client table query received:", {
|
||||
"filters": filters,
|
||||
"sortings": sortings,
|
||||
"page": page,
|
||||
"page_size": page_size
|
||||
})
|
||||
|
||||
|
||||
processed_filters, processed_sortings, is_or, page, page_size = process_query_conditions(filters, sortings, page, page_size)
|
||||
print("DEBUG: Processed filters:", processed_filters)
|
||||
print("DEBUG: Processed sortings:", processed_sortings)
|
||||
@ -152,9 +153,9 @@ def get_clients_table_data(filters={}, sortings=[], page=1, page_size=10):
|
||||
count = frappe.db.sql(*get_count_or_filters("Address", processed_filters))[0][0]
|
||||
else:
|
||||
count = frappe.db.count("Address", filters=processed_filters)
|
||||
|
||||
|
||||
print("DEBUG: Count of addresses matching filters:", count)
|
||||
|
||||
|
||||
address_names = frappe.db.get_all(
|
||||
"Address",
|
||||
fields=["name"],
|
||||
@ -164,7 +165,7 @@ def get_clients_table_data(filters={}, sortings=[], page=1, page_size=10):
|
||||
start=(page - 1) * page_size,
|
||||
order_by=processed_sortings
|
||||
)
|
||||
|
||||
|
||||
addresses = [frappe.get_doc("Address", addr["name"]).as_dict() for addr in address_names]
|
||||
tableRows = []
|
||||
for address in addresses:
|
||||
@ -190,7 +191,7 @@ def get_clients_table_data(filters={}, sortings=[], page=1, page_size=10):
|
||||
tableRow["job_status"] = address.custom_job_status
|
||||
tableRow["payment_received_status"] = address.custom_payment_received_status
|
||||
tableRows.append(tableRow)
|
||||
tableDataDict = build_datatable_dict(data=tableRows, count=count, page=page, page_size=page_size)
|
||||
tableDataDict = build_datatable_dict(data=tableRows, count=count, page=page, page_size=page_size)
|
||||
return build_success_response(tableDataDict)
|
||||
except frappe.ValidationError as ve:
|
||||
return build_error_response(str(ve), 400)
|
||||
@ -202,8 +203,12 @@ def get_clients_table_data(filters={}, sortings=[], page=1, page_size=10):
|
||||
def upsert_client(data):
|
||||
"""Create or update a client (customer and address)."""
|
||||
try:
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
|
||||
>>>>>>> 8f44d90 (Fixed an API error when searching for a non existent client name.)
|
||||
data = json.loads(data)
|
||||
|
||||
|
||||
# Handle customer creation/update
|
||||
print("#####DEBUG: Upsert client data received:", data)
|
||||
print("#####DEBUG: Checking for existing customer with name:", data.get("customer_name"))
|
||||
@ -216,8 +221,9 @@ def upsert_client(data):
|
||||
}).insert(ignore_permissions=True)
|
||||
else:
|
||||
customer_doc = frappe.get_doc("Customer", data.get("customer_name"))
|
||||
<<<<<<< HEAD
|
||||
print("Customer:", customer_doc.as_dict())
|
||||
|
||||
|
||||
# Handle address creation
|
||||
print("#####DEBUG: Checking for existing address for customer:", data.get("customer_name"))
|
||||
existing_address = frappe.db.exists(
|
||||
@ -230,6 +236,23 @@ def upsert_client(data):
|
||||
print("Existing address check:", existing_address)
|
||||
if existing_address:
|
||||
frappe.throw(f"Address already exists for customer {data.get('customer_name')}.", frappe.ValidationError)
|
||||
=======
|
||||
|
||||
print("Customer:", customer_doc.as_dict())
|
||||
|
||||
# Check for existing address
|
||||
filters = {
|
||||
"address_line1": data.get("address_line1"),
|
||||
"city": data.get("city"),
|
||||
"state": data.get("state"),
|
||||
}
|
||||
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)
|
||||
|
||||
# Create address
|
||||
>>>>>>> 8f44d90 (Fixed an API error when searching for a non existent client name.)
|
||||
address_doc = frappe.get_doc({
|
||||
"doctype": "Address",
|
||||
"address_title": data.get("address_title"),
|
||||
@ -241,8 +264,9 @@ def upsert_client(data):
|
||||
"pincode": data.get("pincode"),
|
||||
"custom_customer_to_bill": customer_doc.name
|
||||
}).insert(ignore_permissions=True)
|
||||
<<<<<<< HEAD
|
||||
print("Address:", address_doc.as_dict())
|
||||
|
||||
|
||||
#Handle contact creation
|
||||
contact_docs = []
|
||||
for contact_data in data.get("contacts", []):
|
||||
@ -268,7 +292,7 @@ def upsert_client(data):
|
||||
contact_doc = frappe.get_doc("Contact", {"email_id": data.get("email")})
|
||||
print("Contact already exists:", contact_doc.as_dict())
|
||||
contact_docs.append(contact_doc)
|
||||
|
||||
|
||||
##### Create links
|
||||
# Customer -> Address
|
||||
print("#####DEBUG: Creating links between customer, address, and contacts.")
|
||||
@ -279,7 +303,7 @@ def upsert_client(data):
|
||||
"state": address_doc.state,
|
||||
"pincode": address_doc.pincode
|
||||
})
|
||||
|
||||
|
||||
# Customer -> Contact
|
||||
print("#####DEBUG: Linking contacts to customer.")
|
||||
for contact_doc in contact_docs:
|
||||
@ -292,14 +316,19 @@ def upsert_client(data):
|
||||
"phone": contact_doc.phone,
|
||||
"role": contact_doc.role
|
||||
})
|
||||
|
||||
|
||||
# Address -> Customer
|
||||
print("#####DEBUG: Linking address to customer.")
|
||||
address_doc.append("links", {
|
||||
=======
|
||||
|
||||
# Link address to customer
|
||||
link = {
|
||||
>>>>>>> 8f44d90 (Fixed an API error when searching for a non existent client name.)
|
||||
"link_doctype": "Customer",
|
||||
"link_name": customer_doc.name
|
||||
})
|
||||
|
||||
|
||||
# Address -> Contact
|
||||
print("#####DEBUG: Linking address to contacts.")
|
||||
address_doc.custom_contact = next((c.name for c in contact_docs if c.is_primary_contact), contact_docs[0].name)
|
||||
@ -310,7 +339,7 @@ def upsert_client(data):
|
||||
"phone": contact_doc.phone,
|
||||
"role": contact_doc.role
|
||||
})
|
||||
|
||||
|
||||
# Contact -> Customer & Address
|
||||
print("#####DEBUG: Linking contacts to customer.")
|
||||
for contact_doc in contact_docs:
|
||||
@ -324,10 +353,10 @@ def upsert_client(data):
|
||||
})
|
||||
contact_doc.custom_customer = customer_doc.name
|
||||
contact_doc.save(ignore_permissions=True)
|
||||
|
||||
|
||||
address_doc.save(ignore_permissions=True)
|
||||
customer_doc.save(ignore_permissions=True)
|
||||
|
||||
|
||||
return build_success_response({
|
||||
"customer": customer_doc.as_dict(),
|
||||
"address": address_doc.as_dict(),
|
||||
@ -337,7 +366,7 @@ def upsert_client(data):
|
||||
return build_error_response(str(ve), 400)
|
||||
except Exception as e:
|
||||
return build_error_response(str(e), 500)
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_client_names(search_term):
|
||||
"""Search for client names matching the search term."""
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user