project template in quotation

This commit is contained in:
Casey 2026-01-09 17:01:43 -06:00
parent 89bdbcfdcb
commit 909dab62b5
3 changed files with 111 additions and 53 deletions

View file

@ -286,20 +286,21 @@ def get_estimate_templates(company):
mapped_items = [] mapped_items = []
for item in items: for item in items:
mapped_items.append({ mapped_items.append({
"itemCode": item.item_code, "item_code": item.item_code,
"itemName": item.item_name, "item_name": item.item_name,
"description": item.description, "description": item.description,
"quantity": item.qty, "quantity": item.quantity,
"discountPercentage": item.discount_percentage, "discount_percentage": item.discount_percentage,
"rate": item.rate "rate": item.rate
}) })
result.append({ result.append({
"name": template.name, "name": template.name,
"templateName": template.template_name, "template_name": template.template_name,
"active": template.is_active, "active": template.is_active,
"description": template.description, "description": template.description,
"items": mapped_items "items": mapped_items,
"project_template": template.project_template,
}) })
return build_success_response(result) return build_success_response(result)
@ -320,6 +321,7 @@ def create_estimate_template(data):
"company": data.get("company"), "company": data.get("company"),
"items": [], "items": [],
"template_name": data.get("template_name"), "template_name": data.get("template_name"),
"custom_project_template": data.get("project_template", ""),
"source_quotation": data.get("source_quotation", "") "source_quotation": data.get("source_quotation", "")
} }
@ -448,8 +450,8 @@ def upsert_estimate(data):
def get_estimate_history(estimate_name): def get_estimate_history(estimate_name):
"""Get the history of changes for a specific estimate.""" """Get the history of changes for a specific estimate."""
pass
return history # return history
# @frappe.whitelist() # @frappe.whitelist()
# def get_estimate_counts(): # def get_estimate_counts():

View file

@ -1,5 +1,5 @@
import frappe import frappe
def after_insert(doc, method): def before_insert(doc, method):
# This is where we will add logic to set tasks and other properties of a job based on it's project_template # This is where we will add logic to set tasks and other properties of a job based on it's project_template
pass pass

View file

@ -59,6 +59,41 @@
</div> </div>
</div> </div>
<!-- Template Section -->
<div class="template-section">
<div v-if="isNew">
<label for="template" class="field-label">From Template</label>
<div class="template-input-group">
<Select
v-model="selectedTemplate"
:options="templateOptions"
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>
<Button
v-if="selectedTemplate"
icon="pi pi-times"
@click="clearTemplate"
class="clear-button"
severity="secondary"
/>
</div>
</div>
<div v-else>
<Button label="Save As Template" icon="pi pi-save" @click="openSaveTemplateModal" />
</div>
</div>
<!-- Project Template Section --> <!-- Project Template Section -->
<div class="project-template-section"> <div class="project-template-section">
<label for="projectTemplate" class="field-label"> <label for="projectTemplate" class="field-label">
@ -71,37 +106,11 @@
optionLabel="name" optionLabel="name"
optionValue="name" optionValue="name"
placeholder="Select a project template" placeholder="Select a project template"
:disabled="!isEditable" :disabled="!isEditable || isProjectTemplateDisabled"
fluid fluid
/> />
</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 --> <!-- Items Section -->
<div class="items-section"> <div class="items-section">
<h3>Items</h3> <h3>Items</h3>
@ -408,6 +417,17 @@ const isEditable = computed(() => {
return estimate.value.customSent === 0; return estimate.value.customSent === 0;
}); });
const templateOptions = computed(() => {
return [
{ name: null, templateName: 'None', description: 'Start from scratch' },
...templates.value
];
});
const isProjectTemplateDisabled = computed(() => {
return selectedTemplate.value !== null;
});
const itemColumns = [ const itemColumns = [
{ label: "Item Code", fieldName: "itemCode", type: "text" }, { label: "Item Code", fieldName: "itemCode", type: "text" },
{ label: "Item Name", fieldName: "itemName", type: "text" }, { label: "Item Name", fieldName: "itemName", type: "text" },
@ -437,24 +457,49 @@ const fetchTemplates = async () => {
}; };
const onTemplateChange = () => { const onTemplateChange = () => {
const template = templates.value.find(t => t.name === selectedTemplate.value); if (!selectedTemplate.value) {
if (template && template.items) { // None selected - clear items and project template
selectedItems.value = template.items.map(item => ({ selectedItems.value = [];
itemCode: item.itemCode, formData.projectTemplate = null;
itemName: item.itemName, return;
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 template = templates.value.find(t => t.name === selectedTemplate.value);
console.log("DEBUG: Selected template:", template);
if (template) {
// Auto-select project template if available (check both camelCase and snake_case)
const projectTemplateValue = template.projectTemplate || template.project_template;
console.log("DEBUG: Project template value from template:", projectTemplateValue);
console.log("DEBUG: Available project templates:", projectTemplates.value);
if (projectTemplateValue) {
formData.projectTemplate = projectTemplateValue;
console.log("DEBUG: Set formData.projectTemplate to:", formData.projectTemplate);
}
if (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 clearTemplate = () => {
selectedTemplate.value = null;
selectedItems.value = [];
formData.projectTemplate = null;
}; };
const openSaveTemplateModal = () => { const openSaveTemplateModal = () => {
@ -468,6 +513,7 @@ const confirmSaveTemplate = async (templateData) => {
description: templateData.description, description: templateData.description,
company: company.currentCompany, company: company.currentCompany,
sourceQuotation: estimate.value.name, sourceQuotation: estimate.value.name,
projectTemplate: formData.projectTemplate,
items: selectedItems.value.map(item => ({ items: selectedItems.value.map(item => ({
itemCode: item.itemCode, itemCode: item.itemCode,
itemName: item.itemName, itemName: item.itemName,
@ -898,6 +944,16 @@ onMounted(async () => {
margin-bottom: 1.5rem; margin-bottom: 1.5rem;
} }
.template-input-group {
display: flex;
gap: 0.5rem;
align-items: center;
}
.clear-button {
flex-shrink: 0;
}
.field-label { .field-label {
display: block; display: block;
margin-bottom: 0.5rem; margin-bottom: 0.5rem;