lots of updates
This commit is contained in:
parent
02c48e6108
commit
8ed083fce1
14 changed files with 730 additions and 83 deletions
|
|
@ -1,6 +1,7 @@
|
|||
import frappe, json
|
||||
from frappe.utils.pdf import get_pdf
|
||||
from custom_ui.db_utils import process_query_conditions, build_datatable_dict, get_count_or_filters, build_success_response, build_error_response
|
||||
from werkzeug.wrappers import Response
|
||||
|
||||
# ===============================================================================
|
||||
# ESTIMATES & INVOICES API METHODS
|
||||
|
|
@ -152,7 +153,6 @@ def send_estimate_email(estimate_name):
|
|||
quotation.custom_sent = 1
|
||||
quotation.save()
|
||||
updated_quotation = frappe.get_doc("Quotation", estimate_name)
|
||||
print("DEBUG: Quotation submitted successfully.")
|
||||
return build_success_response(updated_quotation.as_dict())
|
||||
except Exception as e:
|
||||
print(f"DEBUG: Error in send_estimate_email: {str(e)}")
|
||||
|
|
@ -161,16 +161,35 @@ def send_estimate_email(estimate_name):
|
|||
@frappe.whitelist(allow_guest=True)
|
||||
def update_response(name, response):
|
||||
"""Update the response for a given estimate."""
|
||||
estimate = frappe.get_doc("Quotation", name)
|
||||
accepted = True if response == "Accepted" else False
|
||||
new_status = "Estimate Accepted" if accepted else "Lost"
|
||||
|
||||
estimate.custom_response = response
|
||||
estimate.custom_current_status = new_status
|
||||
estimate.custom_followup_needed = 1 if response == "Requested call" else 0
|
||||
estimate.flags.ignore_permissions = True
|
||||
estimate.save()
|
||||
frappe.db.commit()
|
||||
print("DEBUG: RESPONSE RECEIVED:", name, response)
|
||||
try:
|
||||
if not frappe.db.exists("Quotation", name):
|
||||
raise Exception("Estimate not found.")
|
||||
estimate = frappe.get_doc("Quotation", name)
|
||||
accepted = True if response == "Accepted" else False
|
||||
new_status = "Estimate Accepted" if accepted else "Lost"
|
||||
|
||||
estimate.custom_response = response
|
||||
estimate.custom_current_status = new_status
|
||||
estimate.custom_followup_needed = 1 if response == "Requested call" else 0
|
||||
estimate.flags.ignore_permissions = True
|
||||
print("DEBUG: Updating estimate with response:", response, "and status:", new_status)
|
||||
# estimate.save()
|
||||
estimate.submit()
|
||||
frappe.db.commit()
|
||||
|
||||
if accepted:
|
||||
template = "custom_ui/templates/estimates/accepted.html"
|
||||
elif response == "Requested call":
|
||||
template = "custom_ui/templates/estimates/request-call.html"
|
||||
else:
|
||||
template = "custom_ui/templates/estimates/rejected.html"
|
||||
html = frappe.render_template(template, {"doc": estimate})
|
||||
return Response(html, mimetype="text/html")
|
||||
except Exception as e:
|
||||
template = "custom_ui/templates/estimates/error.html"
|
||||
html = frappe.render_template(template, {"error_message": str(e)})
|
||||
return Response(html, mimetype="text/html")
|
||||
|
||||
|
||||
|
||||
|
|
@ -212,6 +231,7 @@ def upsert_estimate(data):
|
|||
print("DEBUG: Retrieved address name:", data.get("address_name"))
|
||||
new_estimate = frappe.get_doc({
|
||||
"doctype": "Quotation",
|
||||
"custom_requires_half_payment": data.get("requires_half_payment", 0),
|
||||
"custom_installation_address": data.get("address_name"),
|
||||
"custom_current_status": "Draft",
|
||||
"contact_email": data.get("contact_email"),
|
||||
|
|
|
|||
|
|
@ -118,9 +118,16 @@ def update_onsite_meeting(name, data):
|
|||
try:
|
||||
if isinstance(data, str):
|
||||
data = json.loads(data)
|
||||
data = {**defualts, **data}
|
||||
|
||||
# Ensure we always have the expected keys so fields can be cleared
|
||||
data = {**defualts, **(data or {})}
|
||||
meeting = frappe.get_doc("On-Site Meeting", name)
|
||||
for key, value in data.items():
|
||||
# Allow explicitly clearing date/time and assignment fields
|
||||
if key in ["start_time", "end_time", "assigned_employee", "completed_by"] and value is None:
|
||||
meeting.set(key, None)
|
||||
continue
|
||||
|
||||
if value is not None:
|
||||
if key == "address":
|
||||
value = frappe.db.get_value("Address", {"full_address": value}, "name")
|
||||
|
|
@ -128,6 +135,7 @@ def update_onsite_meeting(name, data):
|
|||
value = frappe.db.get_value("Employee", {"employee_name": value}, "name")
|
||||
meeting.set(key, value)
|
||||
meeting.save()
|
||||
frappe.db.commit()
|
||||
return build_success_response(meeting.as_dict())
|
||||
except frappe.DoesNotExistError:
|
||||
return build_error_response(f"On-Site Meeting '{name}' does not exist.", 404)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue