From f9fbefad0e2bedaa806d46a9707f2ed639cd8ed8 Mon Sep 17 00:00:00 2001
From: 18alantom <2.alan.tom@gmail.com>
Date: Mon, 6 Mar 2023 15:13:54 +0530
Subject: [PATCH] incr: add Print button to common form - remove template
setting from print settings - allow setting default templates
---
models/baseModels/Defaults/Defaults.ts | 27 ++++++++++++++
schemas/app/Defaults.json | 49 ++++++++++++++++++++++++++
schemas/app/PrintSettings.json | 34 ------------------
src/pages/CommonForm/CommonForm.vue | 13 +++++++
src/pages/PrintView/PrintView.vue | 17 +++++++--
src/utils/ui.ts | 7 ++++
6 files changed, 111 insertions(+), 36 deletions(-)
diff --git a/models/baseModels/Defaults/Defaults.ts b/models/baseModels/Defaults/Defaults.ts
index e78c7f28..e6436a2b 100644
--- a/models/baseModels/Defaults/Defaults.ts
+++ b/models/baseModels/Defaults/Defaults.ts
@@ -3,6 +3,7 @@ import { FiltersMap, HiddenMap } from 'fyo/model/types';
import { ModelNameEnum } from 'models/types';
export class Defaults extends Doc {
+ // Number Series
salesInvoiceNumberSeries?: string;
purchaseInvoiceNumberSeries?: string;
journalEntryNumberSeries?: string;
@@ -11,12 +12,23 @@ export class Defaults extends Doc {
shipmentNumberSeries?: string;
purchaseReceiptNumberSeries?: string;
+ // Terms
salesInvoiceTerms?: string;
purchaseInvoiceTerms?: string;
shipmentTerms?: string;
purchaseReceiptTerms?: string;
+ // Print Templates
+ salesInvoicePrintTemplate?: string;
+ purchaseInvoicePrintTemplate?: string;
+ journalEntryPrintTemplate?: string;
+ paymentPrintTemplate?: string;
+ shipmentPrintTemplate?: string;
+ purchaseReceiptPrintTemplate?: string;
+ stockMovementPrintTemplate?: string;
+
static commonFilters = {
+ // Number Series
salesInvoiceNumberSeries: () => ({
referenceType: ModelNameEnum.SalesInvoice,
}),
@@ -38,6 +50,18 @@ export class Defaults extends Doc {
purchaseReceiptNumberSeries: () => ({
referenceType: ModelNameEnum.PurchaseReceipt,
}),
+ // Print Templates
+ salesInvoicePrintTemplate: () => ({ type: ModelNameEnum.SalesInvoice }),
+ purchaseInvoicePrintTemplate: () => ({
+ type: ModelNameEnum.PurchaseInvoice,
+ }),
+ journalEntryPrintTemplate: () => ({ type: ModelNameEnum.JournalEntry }),
+ paymentPrintTemplate: () => ({ type: ModelNameEnum.Payment }),
+ shipmentPrintTemplate: () => ({ type: ModelNameEnum.Shipment }),
+ purchaseReceiptPrintTemplate: () => ({
+ type: ModelNameEnum.PurchaseReceipt,
+ }),
+ stockMovementPrintTemplate: () => ({ type: ModelNameEnum.StockMovement }),
};
static filters: FiltersMap = this.commonFilters;
@@ -53,6 +77,9 @@ export class Defaults extends Doc {
purchaseReceiptNumberSeries: this.getInventoryHidden(),
shipmentTerms: this.getInventoryHidden(),
purchaseReceiptTerms: this.getInventoryHidden(),
+ shipmentPrintTemplate: this.getInventoryHidden(),
+ purchaseReceiptPrintTemplate: this.getInventoryHidden(),
+ stockMovementPrintTemplate: this.getInventoryHidden(),
};
}
diff --git a/schemas/app/Defaults.json b/schemas/app/Defaults.json
index d68c6c79..6bd9d1c3 100644
--- a/schemas/app/Defaults.json
+++ b/schemas/app/Defaults.json
@@ -83,6 +83,55 @@
"label": "Purchase Receipt Terms",
"fieldtype": "Text",
"section": "Terms"
+ },
+ {
+ "fieldname": "salesInvoicePrintTemplate",
+ "label": "Sales Invoice Print Template",
+ "fieldtype": "Link",
+ "target": "PrintTemplate",
+ "section": "Print Templates"
+ },
+ {
+ "fieldname": "purchaseInvoicePrintTemplate",
+ "label": "Purchase Invoice Print Template",
+ "fieldtype": "Link",
+ "target": "PrintTemplate",
+ "section": "Print Templates"
+ },
+ {
+ "fieldname": "journalEntryPrintTemplate",
+ "label": "Journal Entry Print Template",
+ "fieldtype": "Link",
+ "target": "PrintTemplate",
+ "section": "Print Templates"
+ },
+ {
+ "fieldname": "paymentPrintTemplate",
+ "label": "Payment Print Template",
+ "fieldtype": "Link",
+ "target": "PrintTemplate",
+ "section": "Print Templates"
+ },
+ {
+ "fieldname": "shipmentPrintTemplate",
+ "label": "Shipment Print Template",
+ "fieldtype": "Link",
+ "target": "PrintTemplate",
+ "section": "Print Templates"
+ },
+ {
+ "fieldname": "purchaseReceiptPrintTemplate",
+ "label": "Purchase Receipt Print Template",
+ "fieldtype": "Link",
+ "target": "PrintTemplate",
+ "section": "Print Templates"
+ },
+ {
+ "fieldname": "stockMovementPrintTemplate",
+ "label": "Stock Movement Print Template",
+ "fieldtype": "Link",
+ "target": "PrintTemplate",
+ "section": "Print Templates"
}
]
}
diff --git a/schemas/app/PrintSettings.json b/schemas/app/PrintSettings.json
index c65cebdc..8bfbc25f 100644
--- a/schemas/app/PrintSettings.json
+++ b/schemas/app/PrintSettings.json
@@ -37,28 +37,6 @@
"create": true,
"section": "Contacts"
},
- {
- "fieldname": "template",
- "label": "Template",
- "placeholder": "Template",
- "fieldtype": "Select",
- "options": [
- {
- "value": "Basic",
- "label": "Basic"
- },
- {
- "value": "Minimal",
- "label": "Minimal"
- },
- {
- "value": "Business",
- "label": "Business"
- }
- ],
- "default": "Basic",
- "section": "Customizations"
- },
{
"fieldname": "color",
"label": "Color",
@@ -149,17 +127,5 @@
"fieldtype": "Check",
"section": "Customizations"
}
- ],
- "quickEditFields": [
- "logo",
- "displayLogo",
- "displayTaxInvoice",
- "displayBatch",
- "template",
- "color",
- "font",
- "email",
- "phone",
- "address"
]
}
diff --git a/src/pages/CommonForm/CommonForm.vue b/src/pages/CommonForm/CommonForm.vue
index c14ecfdf..cbfb2434 100644
--- a/src/pages/CommonForm/CommonForm.vue
+++ b/src/pages/CommonForm/CommonForm.vue
@@ -4,6 +4,13 @@
+
;
docOrNull: null | Doc;
activeTab: string;
groupedFields: null | UIGroupedFields;
quickEditDoc: null | Doc;
+ isPrintable: boolean;
};
},
async mounted() {
@@ -162,6 +173,7 @@ export default defineComponent({
await this.setDoc();
focusedDocsRef.add(this.docOrNull);
this.updateGroupedFields();
+ this.isPrintable = await isPrintable(this.schemaName);
},
activated(): void {
docsPathRef.value = docsPathMap[this.schemaName] ?? '';
@@ -241,6 +253,7 @@ export default defineComponent({
},
},
methods: {
+ routeTo,
updateGroupedFields(): void {
if (!this.hasDoc) {
return;
diff --git a/src/pages/PrintView/PrintView.vue b/src/pages/PrintView/PrintView.vue
index 8c5aeaac..2df565b3 100644
--- a/src/pages/PrintView/PrintView.vue
+++ b/src/pages/PrintView/PrintView.vue
@@ -98,8 +98,9 @@ export default defineComponent({
window.pv = this;
}
- if (this.templateList.length) {
- this.onTemplateNameChange(this.templateList[0]);
+ await this.setTemplateFromDefault();
+ if (!this.templateDoc && this.templateList.length) {
+ await this.onTemplateNameChange(this.templateList[0]);
}
if (this.doc) {
@@ -224,6 +225,18 @@ export default defineComponent({
printContainer.savePDF(this.doc?.name);
},
+ async setTemplateFromDefault() {
+ const defaultName =
+ this.schemaName[0].toLowerCase() +
+ this.schemaName.slice(1) +
+ ModelNameEnum.PrintTemplate;
+ const name = this.fyo.singles.Defaults?.get(defaultName);
+ if (typeof name !== 'string') {
+ return;
+ }
+
+ await this.onTemplateNameChange(name);
+ },
},
});
diff --git a/src/utils/ui.ts b/src/utils/ui.ts
index 38ba96f0..614bf146 100644
--- a/src/utils/ui.ts
+++ b/src/utils/ui.ts
@@ -490,3 +490,10 @@ export async function getDocFromNameIfExistsElseNew(
return fyo.doc.getNewDoc(schemaName);
}
}
+
+export async function isPrintable(schemaName: string) {
+ const numTemplates = await fyo.db.count(ModelNameEnum.PrintTemplate, {
+ filters: { type: schemaName },
+ });
+ return numTemplates > 0;
+}