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

View file

@ -1,5 +1,5 @@
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
pass

View file

@ -59,30 +59,14 @@
</div>
</div>
<!-- Project Template Section -->
<div class="project-template-section">
<label for="projectTemplate" class="field-label">
Project Template
<span class="required">*</span>
</label>
<Select
v-model="formData.projectTemplate"
:options="projectTemplates"
optionLabel="name"
optionValue="name"
placeholder="Select a project template"
:disabled="!isEditable"
fluid
/>
</div>
<!-- Template Section -->
<div class="template-section">
<div v-if="isNew">
<label for="template" class="field-label">Template</label>
<label for="template" class="field-label">From Template</label>
<div class="template-input-group">
<Select
v-model="selectedTemplate"
:options="templates"
:options="templateOptions"
optionLabel="templateName"
optionValue="name"
placeholder="Select a template"
@ -96,12 +80,37 @@
</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 -->
<div class="project-template-section">
<label for="projectTemplate" class="field-label">
Project Template
<span class="required">*</span>
</label>
<Select
v-model="formData.projectTemplate"
:options="projectTemplates"
optionLabel="name"
optionValue="name"
placeholder="Select a project template"
:disabled="!isEditable || isProjectTemplateDisabled"
fluid
/>
</div>
<!-- Items Section -->
<div class="items-section">
<h3>Items</h3>
@ -408,6 +417,17 @@ const isEditable = computed(() => {
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 = [
{ label: "Item Code", fieldName: "itemCode", type: "text" },
{ label: "Item Name", fieldName: "itemName", type: "text" },
@ -437,8 +457,26 @@ const fetchTemplates = async () => {
};
const onTemplateChange = () => {
if (!selectedTemplate.value) {
// None selected - clear items and project template
selectedItems.value = [];
formData.projectTemplate = null;
return;
}
const template = templates.value.find(t => t.name === selectedTemplate.value);
if (template && template.items) {
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,
@ -455,6 +493,13 @@ const onTemplateChange = () => {
}
});
}
}
};
const clearTemplate = () => {
selectedTemplate.value = null;
selectedItems.value = [];
formData.projectTemplate = null;
};
const openSaveTemplateModal = () => {
@ -468,6 +513,7 @@ const confirmSaveTemplate = async (templateData) => {
description: templateData.description,
company: company.currentCompany,
sourceQuotation: estimate.value.name,
projectTemplate: formData.projectTemplate,
items: selectedItems.value.map(item => ({
itemCode: item.itemCode,
itemName: item.itemName,
@ -898,6 +944,16 @@ onMounted(async () => {
margin-bottom: 1.5rem;
}
.template-input-group {
display: flex;
gap: 0.5rem;
align-items: center;
}
.clear-button {
flex-shrink: 0;
}
.field-label {
display: block;
margin-bottom: 0.5rem;