Added the Confirm Estimate reponse in the UI.
This commit is contained in:
parent
20a3517d7b
commit
d30fc77527
3 changed files with 70 additions and 21 deletions
|
|
@ -91,7 +91,7 @@ def get_estimate_from_address(full_address):
|
||||||
# return build_success_response(quotation)
|
# return build_success_response(quotation)
|
||||||
# else:
|
# else:
|
||||||
# return build_error_response("No quotation found for the given address.", 404)
|
# return build_error_response("No quotation found for the given address.", 404)
|
||||||
|
|
||||||
# @frappe.whitelist()
|
# @frappe.whitelist()
|
||||||
# def send_estimate_email(estimate_name):
|
# def send_estimate_email(estimate_name):
|
||||||
# print("DEBUG: Queuing email send job for estimate:", estimate_name)
|
# print("DEBUG: Queuing email send job for estimate:", estimate_name)
|
||||||
|
|
@ -103,31 +103,31 @@ def get_estimate_from_address(full_address):
|
||||||
# )
|
# )
|
||||||
# return build_success_response("Email queued for sending.")
|
# return build_success_response("Email queued for sending.")
|
||||||
|
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
def send_estimate_email(estimate_name):
|
def send_estimate_email(estimate_name):
|
||||||
# def send_estimate_email_job(estimate_name):
|
# def send_estimate_email_job(estimate_name):
|
||||||
try:
|
try:
|
||||||
print("DEBUG: Sending estimate email for:", estimate_name)
|
print("DEBUG: Sending estimate email for:", estimate_name)
|
||||||
quotation = frappe.get_doc("Quotation", estimate_name)
|
quotation = frappe.get_doc("Quotation", estimate_name)
|
||||||
|
|
||||||
party_exists = frappe.db.exists(quotation.quotation_to, quotation.party_name)
|
party_exists = frappe.db.exists(quotation.quotation_to, quotation.party_name)
|
||||||
if not party_exists:
|
if not party_exists:
|
||||||
return build_error_response("No email found for the customer.", 400)
|
return build_error_response("No email found for the customer.", 400)
|
||||||
party = frappe.get_doc(quotation.quotation_to, quotation.party_name)
|
party = frappe.get_doc(quotation.quotation_to, quotation.party_name)
|
||||||
|
|
||||||
email = None
|
email = None
|
||||||
if (getattr(party, 'email_id', None)):
|
if (getattr(party, 'email_id', None)):
|
||||||
email = party.email_id
|
email = party.email_id
|
||||||
elif (getattr(party, 'contact_ids', None) and len(party.email_ids) > 0):
|
elif (getattr(party, 'contact_ids', None) and len(party.email_ids) > 0):
|
||||||
primary = next((e for e in party.email_ids if e.is_primary), None)
|
primary = next((e for e in party.email_ids if e.is_primary), None)
|
||||||
email = primary.email_id if primary else party.email_ids[0].email_id
|
email = primary.email_id if primary else party.email_ids[0].email_id
|
||||||
|
|
||||||
if not email and quotation.custom_installation_address:
|
if not email and quotation.custom_installation_address:
|
||||||
address = frappe.get_doc("Address", quotation.custom_installation_address)
|
address = frappe.get_doc("Address", quotation.custom_installation_address)
|
||||||
email = getattr(address, 'email_id', None)
|
email = getattr(address, 'email_id', None)
|
||||||
if not email:
|
if not email:
|
||||||
return build_error_response("No email found for the customer or address.", 400)
|
return build_error_response("No email found for the customer or address.", 400)
|
||||||
|
|
||||||
# email = "casey@shilohcode.com"
|
# email = "casey@shilohcode.com"
|
||||||
template_name = "Quote with Actions - SNW"
|
template_name = "Quote with Actions - SNW"
|
||||||
template = frappe.get_doc("Email Template", template_name)
|
template = frappe.get_doc("Email Template", template_name)
|
||||||
|
|
@ -161,6 +161,30 @@ def send_estimate_email(estimate_name):
|
||||||
print(f"DEBUG: Error in send_estimate_email: {str(e)}")
|
print(f"DEBUG: Error in send_estimate_email: {str(e)}")
|
||||||
return build_error_response(str(e), 500)
|
return build_error_response(str(e), 500)
|
||||||
|
|
||||||
|
|
||||||
|
@frappe.whitelist()
|
||||||
|
def manual_response(name, response):
|
||||||
|
"""Update the response for an estimate in the UI."""
|
||||||
|
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)
|
||||||
|
if estimate.docstatus != 1:
|
||||||
|
raise Exception("Estimate must be submitted to update response.")
|
||||||
|
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.status = "Ordered" if accepted else "Closed"
|
||||||
|
estimate.flags.ignore_permissions = True
|
||||||
|
print("DEBUG: Updating estimate with response:", response, "and status:", new_status)
|
||||||
|
estimate.save()
|
||||||
|
except Exception as e:
|
||||||
|
return e
|
||||||
|
|
||||||
|
|
||||||
@frappe.whitelist(allow_guest=True)
|
@frappe.whitelist(allow_guest=True)
|
||||||
def update_response(name, response):
|
def update_response(name, response):
|
||||||
"""Update the response for a given estimate."""
|
"""Update the response for a given estimate."""
|
||||||
|
|
@ -181,7 +205,7 @@ def update_response(name, response):
|
||||||
estimate.flags.ignore_permissions = True
|
estimate.flags.ignore_permissions = True
|
||||||
print("DEBUG: Updating estimate with response:", response, "and status:", new_status)
|
print("DEBUG: Updating estimate with response:", response, "and status:", new_status)
|
||||||
estimate.save()
|
estimate.save()
|
||||||
|
|
||||||
if accepted:
|
if accepted:
|
||||||
template = "custom_ui/templates/estimates/accepted.html"
|
template = "custom_ui/templates/estimates/accepted.html"
|
||||||
if check_if_customer(estimate.party_name):
|
if check_if_customer(estimate.party_name):
|
||||||
|
|
@ -200,8 +224,8 @@ def update_response(name, response):
|
||||||
html = frappe.render_template(template, {"error_message": str(e)})
|
html = frappe.render_template(template, {"error_message": str(e)})
|
||||||
return Response(html, mimetype="text/html")
|
return Response(html, mimetype="text/html")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
def upsert_estimate(data):
|
def upsert_estimate(data):
|
||||||
|
|
@ -209,19 +233,19 @@ def upsert_estimate(data):
|
||||||
try:
|
try:
|
||||||
data = json.loads(data) if isinstance(data, str) else data
|
data = json.loads(data) if isinstance(data, str) else data
|
||||||
print("DEBUG: Upsert estimate data:", data)
|
print("DEBUG: Upsert estimate data:", data)
|
||||||
|
|
||||||
estimate_name = data.get("estimate_name")
|
estimate_name = data.get("estimate_name")
|
||||||
|
|
||||||
# If estimate_name exists, update existing estimate
|
# If estimate_name exists, update existing estimate
|
||||||
if estimate_name:
|
if estimate_name:
|
||||||
print(f"DEBUG: Updating existing estimate: {estimate_name}")
|
print(f"DEBUG: Updating existing estimate: {estimate_name}")
|
||||||
estimate = frappe.get_doc("Quotation", estimate_name)
|
estimate = frappe.get_doc("Quotation", estimate_name)
|
||||||
|
|
||||||
# Update fields
|
# Update fields
|
||||||
estimate.custom_installation_address = data.get("address_name")
|
estimate.custom_installation_address = data.get("address_name")
|
||||||
estimate.party_name = data.get("contact_name")
|
estimate.party_name = data.get("contact_name")
|
||||||
estimate.custom_requires_half_payment = data.get("requires_half_payment", 0)
|
estimate.custom_requires_half_payment = data.get("requires_half_payment", 0)
|
||||||
|
|
||||||
# Clear existing items and add new ones
|
# Clear existing items and add new ones
|
||||||
estimate.items = []
|
estimate.items = []
|
||||||
for item in data.get("items", []):
|
for item in data.get("items", []):
|
||||||
|
|
@ -230,11 +254,11 @@ def upsert_estimate(data):
|
||||||
"item_code": item.get("item_code"),
|
"item_code": item.get("item_code"),
|
||||||
"qty": item.get("qty"),
|
"qty": item.get("qty"),
|
||||||
})
|
})
|
||||||
|
|
||||||
estimate.save()
|
estimate.save()
|
||||||
print(f"DEBUG: Estimate updated: {estimate.name}")
|
print(f"DEBUG: Estimate updated: {estimate.name}")
|
||||||
return build_success_response(estimate.as_dict())
|
return build_success_response(estimate.as_dict())
|
||||||
|
|
||||||
# Otherwise, create new estimate
|
# Otherwise, create new estimate
|
||||||
else:
|
else:
|
||||||
print("DEBUG: Creating new estimate")
|
print("DEBUG: Creating new estimate")
|
||||||
|
|
@ -261,4 +285,4 @@ def upsert_estimate(data):
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"DEBUG: Error in upsert_estimate: {str(e)}")
|
print(f"DEBUG: Error in upsert_estimate: {str(e)}")
|
||||||
return build_error_response(str(e), 500)
|
return build_error_response(str(e), 500)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,7 @@ const FRAPPE_GET_ESTIMATES_METHOD = "custom_ui.api.db.estimates.get_estimate_tab
|
||||||
const FRAPPE_GET_ESTIMATE_BY_ADDRESS_METHOD = "custom_ui.api.db.estimates.get_estimate_from_address";
|
const FRAPPE_GET_ESTIMATE_BY_ADDRESS_METHOD = "custom_ui.api.db.estimates.get_estimate_from_address";
|
||||||
const FRAPPE_SEND_ESTIMATE_EMAIL_METHOD = "custom_ui.api.db.estimates.send_estimate_email";
|
const FRAPPE_SEND_ESTIMATE_EMAIL_METHOD = "custom_ui.api.db.estimates.send_estimate_email";
|
||||||
const FRAPPE_LOCK_ESTIMATE_METHOD = "custom_ui.api.db.estimates.lock_estimate";
|
const FRAPPE_LOCK_ESTIMATE_METHOD = "custom_ui.api.db.estimates.lock_estimate";
|
||||||
|
const FRAPPE_ESTIMATE_UPDATE_RESPONSE_METHOD = "custom_ui.api.db.estimates.manual_response";
|
||||||
// Job methods
|
// Job methods
|
||||||
const FRAPPE_GET_JOBS_METHOD = "custom_ui.api.db.get_jobs";
|
const FRAPPE_GET_JOBS_METHOD = "custom_ui.api.db.get_jobs";
|
||||||
const FRAPPE_UPSERT_JOB_METHOD = "custom_ui.api.db.jobs.upsert_job";
|
const FRAPPE_UPSERT_JOB_METHOD = "custom_ui.api.db.jobs.upsert_job";
|
||||||
|
|
@ -203,6 +204,10 @@ class Api {
|
||||||
return await this.request(FRAPPE_LOCK_ESTIMATE_METHOD, { estimateName });
|
return await this.request(FRAPPE_LOCK_ESTIMATE_METHOD, { estimateName });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static async updateEstimateResponse(estimateName, response) {
|
||||||
|
return await this.request(FRAPPE_ESTIMATE_UPDATE_RESPONSE_METHOD, {name: estimateName, response});
|
||||||
|
}
|
||||||
|
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
// JOB / PROJECT METHODS
|
// JOB / PROJECT METHODS
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
<div class="estimate-page">
|
<div class="estimate-page">
|
||||||
<h2>{{ isNew ? 'Create Estimate' : 'View Estimate' }}</h2>
|
<h2>{{ isNew ? 'Create Estimate' : 'View Estimate' }}</h2>
|
||||||
<div v-if="!isNew && estimate" class="page-actions">
|
<div v-if="!isNew && estimate" class="page-actions">
|
||||||
|
<Button label="Estimate Response" @click="showResponseModal = true" />
|
||||||
<Button label="Duplicate" icon="pi pi-copy" @click="duplicateEstimate" />
|
<Button label="Duplicate" icon="pi pi-copy" @click="duplicateEstimate" />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
@ -113,6 +114,18 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<!-- Manual Response Modal -->
|
||||||
|
<Modal
|
||||||
|
:visible="showResponseModal"
|
||||||
|
@update:visible="showResponseModal = $event"
|
||||||
|
@close="showResponseModal = false"
|
||||||
|
:options="{ showActions: false }"
|
||||||
|
>
|
||||||
|
<template #title>Set Response</template>
|
||||||
|
<Select v-model="estimateResponse" :options="responses" placeholder="Select Response"/>
|
||||||
|
<Button label="Submit" @click="submitResponse"/>
|
||||||
|
</Modal>
|
||||||
|
|
||||||
<!-- Address Search Modal -->
|
<!-- Address Search Modal -->
|
||||||
<Modal
|
<Modal
|
||||||
:visible="showAddressModal"
|
:visible="showAddressModal"
|
||||||
|
|
@ -260,14 +273,17 @@ const formData = reactive({
|
||||||
|
|
||||||
const selectedAddress = ref(null);
|
const selectedAddress = ref(null);
|
||||||
const selectedContact = ref(null);
|
const selectedContact = ref(null);
|
||||||
|
const estimateResponse = ref(null);
|
||||||
const contacts = ref([]);
|
const contacts = ref([]);
|
||||||
const contactOptions = ref([]);
|
const contactOptions = ref([]);
|
||||||
const quotationItems = ref([]);
|
const quotationItems = ref([]);
|
||||||
const selectedItems = ref([]);
|
const selectedItems = ref([]);
|
||||||
|
const responses = ref(["Accepted", "Rejected"]);
|
||||||
|
|
||||||
const showAddressModal = ref(false);
|
const showAddressModal = ref(false);
|
||||||
const showAddItemModal = ref(false);
|
const showAddItemModal = ref(false);
|
||||||
const showConfirmationModal = ref(false);
|
const showConfirmationModal = ref(false);
|
||||||
|
const showResponseModal = ref(false);
|
||||||
const addressSearchResults = ref([]);
|
const addressSearchResults = ref([]);
|
||||||
const itemSearchTerm = ref("");
|
const itemSearchTerm = ref("");
|
||||||
|
|
||||||
|
|
@ -384,7 +400,7 @@ const saveDraft = async () => {
|
||||||
formData.estimateName ? "Estimate updated successfully" : "Estimate created successfully",
|
formData.estimateName ? "Estimate updated successfully" : "Estimate created successfully",
|
||||||
"success"
|
"success"
|
||||||
);
|
);
|
||||||
|
|
||||||
// Redirect to view mode (remove new param)
|
// Redirect to view mode (remove new param)
|
||||||
router.push(`/estimate?address=${encodeURIComponent(formData.address)}`);
|
router.push(`/estimate?address=${encodeURIComponent(formData.address)}`);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|
@ -395,6 +411,10 @@ const saveDraft = async () => {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const submitResponse = () => {
|
||||||
|
Api.updateEstimateResponse(estimate.value.name, estimateResponse.value, false);
|
||||||
|
}
|
||||||
|
|
||||||
const duplicateEstimate = () => {
|
const duplicateEstimate = () => {
|
||||||
if (!estimate.value) return;
|
if (!estimate.value) return;
|
||||||
|
|
||||||
|
|
@ -501,7 +521,7 @@ watch(
|
||||||
// Reload data based on new query params
|
// Reload data based on new query params
|
||||||
const newIsNew = newQuery.new === "true";
|
const newIsNew = newQuery.new === "true";
|
||||||
const newAddressQuery = newQuery.address;
|
const newAddressQuery = newQuery.address;
|
||||||
|
|
||||||
if (newAddressQuery && newIsNew) {
|
if (newAddressQuery && newIsNew) {
|
||||||
// Creating new estimate - pre-fill address
|
// Creating new estimate - pre-fill address
|
||||||
await selectAddress(newAddressQuery);
|
await selectAddress(newAddressQuery);
|
||||||
|
|
@ -509,13 +529,13 @@ watch(
|
||||||
// Viewing existing estimate - load and populate all fields
|
// Viewing existing estimate - load and populate all fields
|
||||||
try {
|
try {
|
||||||
estimate.value = await Api.getEstimateFromAddress(newAddressQuery);
|
estimate.value = await Api.getEstimateFromAddress(newAddressQuery);
|
||||||
|
|
||||||
if (estimate.value) {
|
if (estimate.value) {
|
||||||
formData.estimateName = estimate.value.name;
|
formData.estimateName = estimate.value.name;
|
||||||
await selectAddress(newAddressQuery);
|
await selectAddress(newAddressQuery);
|
||||||
formData.contact = estimate.value.partyName;
|
formData.contact = estimate.value.partyName;
|
||||||
selectedContact.value = contacts.value.find((c) => c.name === estimate.value.partyName) || null;
|
selectedContact.value = contacts.value.find((c) => c.name === estimate.value.partyName) || null;
|
||||||
|
|
||||||
if (estimate.value.items && estimate.value.items.length > 0) {
|
if (estimate.value.items && estimate.value.items.length > 0) {
|
||||||
selectedItems.value = estimate.value.items.map(item => {
|
selectedItems.value = estimate.value.items.map(item => {
|
||||||
const fullItem = quotationItems.value.find(qi => qi.itemCode === item.itemCode);
|
const fullItem = quotationItems.value.find(qi => qi.itemCode === item.itemCode);
|
||||||
|
|
@ -562,7 +582,7 @@ onMounted(async () => {
|
||||||
if (estimate.value) {
|
if (estimate.value) {
|
||||||
// Set the estimate name for upserting
|
// Set the estimate name for upserting
|
||||||
formData.estimateName = estimate.value.name;
|
formData.estimateName = estimate.value.name;
|
||||||
|
|
||||||
await selectAddress(addressQuery.value);
|
await selectAddress(addressQuery.value);
|
||||||
// Set the contact from the estimate
|
// Set the contact from the estimate
|
||||||
formData.contact = estimate.value.partyName;
|
formData.contact = estimate.value.partyName;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue