update bugs
This commit is contained in:
parent
520e239741
commit
fe46f18d60
6 changed files with 198 additions and 203 deletions
|
|
@ -253,17 +253,25 @@ def upsert_client(data):
|
|||
print("#####DEBUG: Processing contact data:", contact_data)
|
||||
contact_exists = frappe.db.exists("Contact", {"email_id": contact_data.get("email"), "phone": contact_data.get("phone_number")})
|
||||
if not contact_exists:
|
||||
is_primary_contact = 1 if contact_data.get("is_primary_contact") else 0
|
||||
contact_doc = frappe.get_doc({
|
||||
"doctype": "Contact",
|
||||
"first_name": contact_data.get("first_name"),
|
||||
"last_name": contact_data.get("last_name"),
|
||||
"email_id": contact_data.get("email"),
|
||||
"phone": contact_data.get("phone_number"),
|
||||
# "email_id": contact_data.get("email"),
|
||||
# "phone": contact_data.get("phone_number"),
|
||||
"custom_customer": customer_doc.name,
|
||||
"role": contact_data.get("contact_role", "Other"),
|
||||
"custom_email": contact_data.get("email"),
|
||||
"is_primary_contact": is_primary_contact
|
||||
"is_primary_contact": data.get("is_primary", False),
|
||||
"email_ids": [{
|
||||
"email_id": contact_data.get("email"),
|
||||
"is_primary": 1
|
||||
}],
|
||||
"phone_nos": [{
|
||||
"phone": contact_data.get("phone_number"),
|
||||
"is_primary_mobile_no": 1,
|
||||
"is_primary_phone": 1
|
||||
}]
|
||||
}).insert(ignore_permissions=True)
|
||||
print("Created new contact:", contact_doc.as_dict())
|
||||
else:
|
||||
|
|
@ -316,6 +324,7 @@ def upsert_client(data):
|
|||
# Contact -> Customer & Address
|
||||
print("#####DEBUG: Linking contacts to customer.")
|
||||
for contact_doc in contact_docs:
|
||||
contact_doc.address = address_doc.name
|
||||
contact_doc.append("links", {
|
||||
"link_doctype": "Customer",
|
||||
"link_name": customer_doc.name
|
||||
|
|
|
|||
|
|
@ -66,12 +66,6 @@ def get_estimate(estimate_name):
|
|||
except Exception as e:
|
||||
return build_error_response(str(e), 500)
|
||||
|
||||
@frappe.whitelist()
|
||||
def upsert_estimate(data):
|
||||
"""Create or update an estimate."""
|
||||
# TODO: Implement estimate creation/update logic
|
||||
pass
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_estimate_items():
|
||||
items = frappe.db.get_all("Quotation Item", fields=["*"])
|
||||
|
|
@ -98,25 +92,54 @@ def get_estimate_from_address(full_address):
|
|||
@frappe.whitelist()
|
||||
def upsert_estimate(data):
|
||||
"""Create or update an estimate."""
|
||||
print("DOIFJSEOFJISLFK")
|
||||
try:
|
||||
data = json.loads(data) if isinstance(data, str) else data
|
||||
print("DEBUG: Retrieved address name:", data.get("address_name"))
|
||||
new_estimate = frappe.get_doc({
|
||||
"doctype": "Quotation",
|
||||
"custom_installation_address": data.get("address_name"),
|
||||
"contact_email": data.get("contact_email"),
|
||||
"party_name": data.get("contact_name"),
|
||||
"customer_name": data.get("customer_name"),
|
||||
})
|
||||
for item in data.get("items", []):
|
||||
item = json.loads(item) if isinstance(item, str) else item
|
||||
new_estimate.append("items", {
|
||||
"item_code": item.get("item_code"),
|
||||
"qty": item.get("qty"),
|
||||
print("DEBUG: Upsert estimate data:", data)
|
||||
|
||||
estimate_name = data.get("estimate_name")
|
||||
|
||||
# If estimate_name exists, update existing estimate
|
||||
if estimate_name:
|
||||
print(f"DEBUG: Updating existing estimate: {estimate_name}")
|
||||
estimate = frappe.get_doc("Quotation", estimate_name)
|
||||
|
||||
# Update fields
|
||||
estimate.custom_installation_address = data.get("address_name")
|
||||
estimate.party_name = data.get("contact_name")
|
||||
|
||||
# Clear existing items and add new ones
|
||||
estimate.items = []
|
||||
for item in data.get("items", []):
|
||||
item = json.loads(item) if isinstance(item, str) else item
|
||||
estimate.append("items", {
|
||||
"item_code": item.get("item_code"),
|
||||
"qty": item.get("qty"),
|
||||
})
|
||||
|
||||
estimate.save()
|
||||
print(f"DEBUG: Estimate updated: {estimate.name}")
|
||||
return build_success_response(estimate.as_dict())
|
||||
|
||||
# Otherwise, create new estimate
|
||||
else:
|
||||
print("DEBUG: Creating new estimate")
|
||||
print("DEBUG: Retrieved address name:", data.get("address_name"))
|
||||
new_estimate = frappe.get_doc({
|
||||
"doctype": "Quotation",
|
||||
"custom_installation_address": data.get("address_name"),
|
||||
"contact_email": data.get("contact_email"),
|
||||
"party_name": data.get("contact_name"),
|
||||
"customer_name": data.get("customer_name"),
|
||||
})
|
||||
new_estimate.insert()
|
||||
print("DEBUG: New estimate created with name:", new_estimate.name)
|
||||
return build_success_response(new_estimate.as_dict())
|
||||
for item in data.get("items", []):
|
||||
item = json.loads(item) if isinstance(item, str) else item
|
||||
new_estimate.append("items", {
|
||||
"item_code": item.get("item_code"),
|
||||
"qty": item.get("qty"),
|
||||
})
|
||||
new_estimate.insert()
|
||||
print("DEBUG: New estimate created with name:", new_estimate.name)
|
||||
return build_success_response(new_estimate.as_dict())
|
||||
except Exception as e:
|
||||
print(f"DEBUG: Error in upsert_estimate: {str(e)}")
|
||||
return build_error_response(str(e), 500)
|
||||
Loading…
Add table
Add a link
Reference in a new issue