update bugs
This commit is contained in:
parent
520e239741
commit
fe46f18d60
6 changed files with 198 additions and 203 deletions
|
|
@ -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