project template in quotation
This commit is contained in:
parent
89bdbcfdcb
commit
909dab62b5
3 changed files with 111 additions and 53 deletions
|
|
@ -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():
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
@ -59,6 +59,41 @@
|
|||
</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 -->
|
||||
<div class="project-template-section">
|
||||
<label for="projectTemplate" class="field-label">
|
||||
|
|
@ -71,37 +106,11 @@
|
|||
optionLabel="name"
|
||||
optionValue="name"
|
||||
placeholder="Select a project template"
|
||||
:disabled="!isEditable"
|
||||
:disabled="!isEditable || isProjectTemplateDisabled"
|
||||
fluid
|
||||
/>
|
||||
</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>
|
||||
|
|
@ -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,24 +457,49 @@ const fetchTemplates = async () => {
|
|||
};
|
||||
|
||||
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);
|
||||
}
|
||||
});
|
||||
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);
|
||||
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 = () => {
|
||||
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue