From 0663cd2d8c2fa6de41e8cd489723b67935a25b9a Mon Sep 17 00:00:00 2001 From: Casey Date: Tue, 2 Dec 2025 12:27:58 -0600 Subject: [PATCH] estimate view --- custom_ui/api/db/estimates.py | 29 +++++--- frontend/src/api.js | 3 +- frontend/src/components/pages/Estimate.vue | 82 +++++++++++++++++++-- frontend/src/components/pages/Estimates.vue | 25 ++++++- 4 files changed, 116 insertions(+), 23 deletions(-) diff --git a/custom_ui/api/db/estimates.py b/custom_ui/api/db/estimates.py index 605365f..d8a33ac 100644 --- a/custom_ui/api/db/estimates.py +++ b/custom_ui/api/db/estimates.py @@ -32,9 +32,10 @@ def get_estimate_table_data(filters={}, sortings=[], page=1, page_size=10): tableRows = [] for estimate in estimates: + full_address = frappe.db.get_value("Address", estimate.get("custom_installation_address"), "full_address") tableRow = {} tableRow["id"] = estimate["name"] - tableRow["name"] = estimate["name"] + tableRow["address"] = full_address tableRow["quotation_to"] = estimate.get("quotation_to", "") tableRow["customer"] = estimate.get("party_name", "") tableRow["status"] = estimate.get("custom_current_status", "") @@ -78,17 +79,21 @@ def get_estimate_items(): @frappe.whitelist() def get_estimate_from_address(full_address): - quotation = frappe.db.sql(""" - SELECT q.name, q.custom_installation_address - FROM `tabQuotation` q - JOIN `tabAddress` a - ON q.custom_installation_address = a.name - WHERE a.full_address =%s - """, (full_address,), as_dict=True) - if quotation: - return build_success_response(quotation) - else: - return build_error_response("No quotation found for the given address.", 404) + address_name = frappe.db.get_value("Address", {"full_address": full_address}, "name") + quotation_name = frappe.db.get_value("Quotation", {"custom_installation_address": address_name}, "name") + quotation_doc = frappe.get_doc("Quotation", quotation_name) + return build_success_response(quotation_doc.as_dict()) + # quotation = frappe.db.sql(""" + # SELECT q.name, q.custom_installation_address + # FROM `tabQuotation` q + # JOIN `tabAddress` a + # ON q.custom_installation_address = a.name + # WHERE a.full_address =%s + # """, (full_address,), as_dict=True) + # if quotation: + # return build_success_response(quotation) + # else: + # return build_error_response("No quotation found for the given address.", 404) @frappe.whitelist() def upsert_estimate(data): diff --git a/frontend/src/api.js b/frontend/src/api.js index 84b138f..5f8548d 100644 --- a/frontend/src/api.js +++ b/frontend/src/api.js @@ -7,6 +7,7 @@ const FRAPPE_PROXY_METHOD = "custom_ui.api.proxy.request"; // Estimate methods const FRAPPE_UPSERT_ESTIMATE_METHOD = "custom_ui.api.db.estimates.upsert_estimate"; const FRAPPE_GET_ESTIMATES_METHOD = "custom_ui.api.db.estimates.get_estimate_table_data"; +const FRAPPE_GET_ESTIMATE_BY_ADDRESS_METHOD = "custom_ui.api.db.estimates.get_estimate_from_address"; // Job methods const FRAPPE_GET_JOBS_METHOD = "custom_ui.api.db.get_jobs"; const FRAPPE_UPSERT_JOB_METHOD = "custom_ui.api.db.jobs.upsert_job"; @@ -61,7 +62,7 @@ class Api { } static async getEstimateFromAddress(fullAddress) { - return await this.request("custom_ui.api.db.estimates.get_estimate_from_address", { + return await this.request(FRAPPE_GET_ESTIMATE_BY_ADDRESS_METHOD, { full_address: fullAddress, }); } diff --git a/frontend/src/components/pages/Estimate.vue b/frontend/src/components/pages/Estimate.vue index afc2f7f..e056785 100644 --- a/frontend/src/components/pages/Estimate.vue +++ b/frontend/src/components/pages/Estimate.vue @@ -1,6 +1,6 @@