2
0
mirror of https://github.com/frappe/books.git synced 2025-01-22 14:48:25 +00:00

incr: add Print button to common form

- remove template setting from print settings
- allow setting default templates
This commit is contained in:
18alantom 2023-03-06 15:13:54 +05:30
parent 0d3541fcb7
commit f9fbefad0e
6 changed files with 111 additions and 36 deletions

View File

@ -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(),
};
}

View File

@ -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"
}
]
}

View File

@ -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"
]
}

View File

@ -4,6 +4,13 @@
<StatusBadge :status="status" class="h-8" />
</template>
<template #header v-if="hasDoc">
<Button
v-if="!doc.isCancelled && !doc.dirty && isPrintable"
:icon="true"
@click="routeTo(`/print/${doc.schemaName}/${doc.name}`)"
>
{{ t`Print` }}
</Button>
<DropdownWithActions
v-for="group of groupedActions"
:key="group.label"
@ -121,6 +128,8 @@ import {
getDocFromNameIfExistsElseNew,
getFieldsGroupedByTabAndSection,
getGroupedActionsForDoc,
isPrintable,
routeTo,
} from 'src/utils/ui';
import { computed, defineComponent, nextTick } from 'vue';
import QuickEditForm from '../QuickEditForm.vue';
@ -145,12 +154,14 @@ export default defineComponent({
activeTab: 'Default',
groupedFields: null,
quickEditDoc: null,
isPrintable: false,
} as {
errors: Record<string, string>;
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;

View File

@ -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);
},
},
});
</script>

View File

@ -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;
}