Compare commits

..

No commits in common. "97241f14ead6a796e1dfec203c913da69595f21d" and "702e7184318b9bd8105f5a429cc6151031d932fc" have entirely different histories.

6 changed files with 22 additions and 416 deletions

View file

@ -260,119 +260,8 @@ def update_response(name, response):
html = frappe.render_template(template, {"error": str(e)})
return Response(html, mimetype="text/html")
@frappe.whitelist()
def get_estimate_templates(company):
"""Get available estimate templates."""
filters = {"is_active": 1}
if company:
filters["company"] = company
try:
print("DEBUG: Fetching estimate templates for company:", company)
templates = frappe.get_all("Quotation Template", fields=["*"], filters=filters)
result = []
if not templates:
print("DEBUG: No templates found.")
return build_success_response(result)
print(f"DEBUG: Found {len(templates)} templates.")
for template in templates:
print("DEBUG: Processing template:", template)
items = frappe.get_all("Quotation Template Item",
fields=["item_code", "item_name", "description", "quantity", "discount_percentage", "rate"],
filters={"parent": template.name},
order_by="idx")
# Map fields to camelCase as requested
mapped_items = []
for item in items:
mapped_items.append({
"itemCode": item.item_code,
"itemName": item.item_name,
"description": item.description,
"quantity": item.qty,
"discountPercentage": item.discount_percentage,
"rate": item.rate
})
result.append({
"name": template.name,
"templateName": template.template_name,
"active": template.is_active,
"description": template.description,
"items": mapped_items
})
return build_success_response(result)
except Exception as e:
return build_error_response(str(e), 500)
@frappe.whitelist()
def create_estimate_template(data):
"""Create a new estimate template."""
try:
print("DEBUG: Creating estimate template with data:", data)
data = json.loads(data) if isinstance(data, str) else data
doc_data = {
"doctype": "Quotation Template",
"is_active": 1,
"description": data.get("description"),
"company": data.get("company"),
"items": [],
"template_name": data.get("template_name"),
"source_quotation": data.get("source_quotation", "")
}
new_template = frappe.get_doc(doc_data)
for item in data.get("items", []):
new_template.append("items", {
"item_code": item.get("item_code"),
"item_name": item.get("item_name"),
"description": item.get("description"),
"qty": item.get("qty") or item.get("quantity"),
"rate": item.get("standard_rate") or item.get("rate"),
"discount_percentage": item.get("discount_percentage")
})
new_template.insert()
return build_success_response(new_template.name)
except Exception as e:
return build_error_response(str(e), 500)
# @frappe.whitelist()
# def create_template(data):
# """Create a new estimate template."""
# try:
# data = json.loads(data) if isinstance(data, str) else data
# print("DEBUG: Creating estimate template with data:", data)
# new_template = frappe.get_doc({
# "doctype": "Quotation Template",
# "template_name": data.get("templateName"),
# "is_active": data.get("active", 1),
# "description": data.get("description", ""),
# "company": data.get("company", ""),
# "source_quotation": data.get("source_quotation", "")
# })
# for item in data.get("items", []):
# item = json.loads(item) if isinstance(item, str) else item
# new_template.append("items", {
# "item_code": item.get("itemCode"),
# "item_name": item.get("itemName"),
# "description": item.get("description"),
# "qty": item.get("quantity"),
# "discount_percentage": item.get("discountPercentage"),
# "rate": item.get("rate")
# })
# new_template.insert()
# print("DEBUG: New estimate template created with name:", new_template.name)
# return build_success_response(new_template.as_dict())
# except Exception as e:
# return build_error_response(str(e), 500)
@frappe.whitelist()
def upsert_estimate(data):

View file

@ -413,70 +413,6 @@
"trigger": null,
"unique": 0,
"width": null
},
{
"allow_bulk_edit": 0,
"allow_in_quick_entry": 0,
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"collapsible_depends_on": null,
"columns": 0,
"default": null,
"depends_on": null,
"description": null,
"documentation_url": null,
"fetch_from": null,
"fetch_if_empty": 0,
"fieldname": "company",
"fieldtype": "Link",
"hidden": 0,
"hide_border": 0,
"hide_days": 0,
"hide_seconds": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 0,
"in_list_view": 0,
"in_preview": 0,
"in_standard_filter": 0,
"is_virtual": 0,
"label": "Company",
"length": 0,
"link_filters": null,
"make_attachment_public": 0,
"mandatory_depends_on": null,
"max_height": null,
"no_copy": 0,
"non_negative": 0,
"oldfieldname": null,
"oldfieldtype": null,
"options": "Company",
"parent": "Quotation Template",
"parentfield": "fields",
"parenttype": "DocType",
"permlevel": 0,
"placeholder": null,
"precision": "",
"print_hide": 0,
"print_hide_if_no_value": 0,
"print_width": null,
"read_only": 0,
"read_only_depends_on": null,
"remember_last_selected_value": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"show_dashboard": 0,
"show_on_timeline": 0,
"show_preview_popup": 0,
"sort_options": 0,
"translatable": 0,
"trigger": null,
"unique": 0,
"width": null
}
],
"force_re_route_to_default_view": 0,
@ -499,7 +435,7 @@
"max_attachments": 0,
"menu_index": null,
"migration_hash": null,
"modified": "2026-01-02 11:26:31.164108",
"modified": "2025-12-23 02:03:44.840865",
"module": "Selling",
"name": "Quotation Template",
"naming_rule": "",

View file

@ -12,8 +12,6 @@ const FRAPPE_GET_ESTIMATE_BY_ADDRESS_METHOD = "custom_ui.api.db.estimates.get_es
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_ESTIMATE_UPDATE_RESPONSE_METHOD = "custom_ui.api.db.estimates.manual_response";
const FRAPPE_GET_ESTIMATE_TEMPLATES_METHOD = "custom_ui.api.db.estimates.get_estimate_templates";
const FRAPPE_CREATE_ESTIMATE_TEMPLATE_METHOD = "custom_ui.api.db.estimates.create_estimate_template";
// Job methods
const FRAPPE_GET_JOB_METHOD = "custom_ui.api.db.jobs.get_job";
const FRAPPE_GET_JOBS_METHOD = "custom_ui.api.db.jobs.get_jobs_table_data";
@ -224,14 +222,6 @@ class Api {
return await this.request(FRAPPE_ESTIMATE_UPDATE_RESPONSE_METHOD, {name: estimateName, response});
}
static async getEstimateTemplates(company) {
return await this.request(FRAPPE_GET_ESTIMATE_TEMPLATES_METHOD, { company });
}
static async createEstimateTemplate(data) {
return await this.request(FRAPPE_CREATE_ESTIMATE_TEMPLATE_METHOD, { data });
}
// ============================================================================
// JOB / PROJECT METHODS
// ============================================================================

View file

@ -1,26 +1,24 @@
<template>
<div>
<h3>History</h3>
<Tabs value="0" class="tabs">
<TabList>
<Tab value="0">Communication History</Tab>
<Tab value="1">Site Visits</Tab>
<Tab value="2">Ownership History</Tab>
</TabList>
<TabPanels>
<TabPanel value="0">
<div>Descending order of communications with the customer go here.</div>
<button class="sidebar-button">Add New</button>
</TabPanel>
<TabPanel value="1">
<div>Site Visits</div>
</TabPanel>
<TabPanel value="2">
<div>Ownership History</div>
</TabPanel>
</TabPanels>
</Tabs>
</div>
<h3>History</h3>
<Tabs value="0" class="tabs">
<TabList>
<Tab value="0">Communication History</Tab>
<Tab value="1">Site Visits</Tab>
<Tab value="2">Ownership History</Tab>
</TabList>
<TabPanels>
<TabPanel value="0">
<div>Descending order of communications with the customer go here.</div>
<button class="sidebar-button">Add New</button>
</TabPanel>
<TabPanel value="1">
<div>Site Visits</div>
</TabPanel>
<TabPanel value="2">
<div>Ownership History</div>
</TabPanel>
</TabPanels>
</Tabs>
</template>
<script setup>

View file

@ -1,82 +0,0 @@
<template>
<Modal
:visible="visible"
@update:visible="$emit('update:visible', $event)"
@close="$emit('update:visible', false)"
:options="{ showActions: false }"
>
<template #title>Save As Template</template>
<div class="modal-content">
<div class="field-group">
<label for="templateName" class="field-label">Template Name</label>
<InputText id="templateName" v-model="templateData.templateName" fluid />
</div>
<div class="field-group">
<label for="templateDescription" class="field-label">Description</label>
<InputText id="templateDescription" v-model="templateData.description" fluid />
</div>
<div class="confirmation-buttons">
<Button label="Cancel" @click="$emit('update:visible', false)" severity="secondary" />
<Button label="Submit" @click="submit" :disabled="!templateData.templateName" />
</div>
</div>
</Modal>
</template>
<script setup>
import { reactive, watch } from "vue";
import Modal from "../common/Modal.vue";
import InputText from "primevue/inputtext";
import Button from "primevue/button";
const props = defineProps({
visible: {
type: Boolean,
required: true,
},
});
const emit = defineEmits(["update:visible", "save"]);
const templateData = reactive({
templateName: "",
description: "",
});
watch(
() => props.visible,
(newVal) => {
if (newVal) {
templateData.templateName = "";
templateData.description = "";
}
},
);
const submit = () => {
emit("save", { ...templateData });
};
</script>
<style scoped>
.field-label {
display: block;
margin-bottom: 0.5rem;
font-weight: 500;
}
.field-group {
margin-bottom: 1rem;
}
.confirmation-buttons {
display: flex;
gap: 1rem;
justify-content: flex-end;
margin-top: 1rem;
}
.modal-content {
padding: 1rem;
}
</style>

View file

@ -59,32 +59,6 @@
</div>
</div>
<!-- Template Section -->
<div class="template-section">
<div v-if="isNew">
<label for="template" class="field-label">Template</label>
<Select
v-model="selectedTemplate"
:options="templates"
optionLabel="templateName"
optionValue="name"
placeholder="Select a template"
fluid
@change="onTemplateChange"
>
<template #option="slotProps">
<div class="template-option">
<div class="template-name">{{ slotProps.option.templateName }}</div>
<div class="template-desc">{{ slotProps.option.description }}</div>
</div>
</template>
</Select>
</div>
<div v-else>
<Button label="Save As Template" icon="pi pi-save" @click="openSaveTemplateModal" />
</div>
</div>
<!-- Items Section -->
<div class="items-section">
<h3>Items</h3>
@ -203,13 +177,6 @@
<Button label="Submit" @click="submitResponse"/>
</Modal>
<!-- Save Template Modal -->
<SaveTemplateModal
:visible="showSaveTemplateModal"
@update:visible="showSaveTemplateModal = $event"
@save="confirmSaveTemplate"
/>
<!-- Address Search Modal -->
<Modal
:visible="showAddressModal"
@ -323,7 +290,6 @@
import { ref, reactive, computed, onMounted, watch } from "vue";
import { useRoute, useRouter } from "vue-router";
import Modal from "../common/Modal.vue";
import SaveTemplateModal from "../modals/SaveTemplateModal.vue";
import DataTable from "../common/DataTable.vue";
import DocHistory from "../common/DocHistory.vue";
import InputText from "primevue/inputtext";
@ -368,14 +334,11 @@ const contactOptions = ref([]);
const quotationItems = ref([]);
const selectedItems = ref([]);
const responses = ref(["Accepted", "Rejected"]);
const templates = ref([]);
const selectedTemplate = ref(null);
const showAddressModal = ref(false);
const showAddItemModal = ref(false);
const showConfirmationModal = ref(false);
const showResponseModal = ref(false);
const showSaveTemplateModal = ref(false);
const addressSearchResults = ref([]);
const itemSearchTerm = ref("");
@ -396,67 +359,6 @@ const itemColumns = [
];
// Methods
const fetchTemplates = async () => {
if (!isNew.value) return;
try {
const result = await Api.getEstimateTemplates(company.currentCompany);
templates.value = result;
} catch (error) {
console.error("Error fetching templates:", error);
notificationStore.addNotification("Failed to fetch templates", "error");
}
};
const onTemplateChange = () => {
const template = templates.value.find(t => t.name === selectedTemplate.value);
if (template && template.items) {
selectedItems.value = template.items.map(item => ({
itemCode: item.itemCode,
itemName: item.itemName,
qty: item.quantity,
standardRate: item.rate,
discountAmount: null,
discountPercentage: item.discountPercentage,
discountType: item.discountPercentage > 0 ? 'percentage' : 'currency'
}));
// Calculate discount amounts
selectedItems.value.forEach(item => {
if (item.discountType === 'percentage') {
updateDiscountFromPercentage(item);
}
});
}
};
const openSaveTemplateModal = () => {
showSaveTemplateModal.value = true;
};
const confirmSaveTemplate = async (templateData) => {
try {
const data = {
templateName: templateData.templateName,
description: templateData.description,
company: company.currentCompany,
sourceQuotation: estimate.value.name,
items: selectedItems.value.map(item => ({
itemCode: item.itemCode,
itemName: item.itemName,
description: item.description,
qty: item.qty,
standardRate: item.standardRate,
discountPercentage: item.discountPercentage
}))
};
await Api.createEstimateTemplate(data);
notificationStore.addSuccess("Template saved successfully", "success");
showSaveTemplateModal.value = false;
} catch (error) {
console.error("Error saving template:", error);
notificationStore.addNotification("Failed to save template", "error");
}
};
const searchAddresses = async () => {
const searchTerm = formData.address.trim();
if (!searchTerm) return;
@ -672,10 +574,6 @@ watch(
},
);
watch(() => company.currentCompany, () => {
fetchTemplates();
});
// Watch for query param changes to refresh page behavior
watch(
() => route.query,
@ -774,10 +672,6 @@ onMounted(async () => {
console.error("Error loading quotation items:", error);
}
if (isNew.value) {
fetchTemplates();
}
if (addressQuery.value && isNew.value) {
// Creating new estimate - pre-fill address
await selectAddress(addressQuery.value);
@ -853,8 +747,7 @@ onMounted(async () => {
}
.address-section,
.contact-section,
.template-section {
.contact-section {
margin-bottom: 1.5rem;
}
@ -1121,23 +1014,5 @@ onMounted(async () => {
font-size: 0.9em;
color: #333;
}
.template-option {
display: flex;
flex-direction: column;
}
.template-name {
font-weight: bold;
}
.template-desc {
font-size: 0.85rem;
color: #666;
}
.field-group {
margin-bottom: 1rem;
}
</style>
<parameter name="filePath"></parameter>