2
0
mirror of https://github.com/frappe/books.git synced 2025-02-03 20:48:29 +00:00
books/models/baseModels/PrintTemplate.ts
18alantom 28aa0f135e incr: update routing
- update PrintTemplate UI code
2023-03-06 10:40:02 +05:30

55 lines
1.3 KiB
TypeScript

import { Doc } from 'fyo/model/doc';
import { SchemaMap } from 'schemas/types';
import { ListsMap, ListViewSettings, ReadOnlyMap } from 'fyo/model/types';
import { ModelNameEnum } from 'models/types';
export class PrintTemplate extends Doc {
name?: string;
type?: string;
template?: string;
isCustom?: boolean;
static getListViewSettings(): ListViewSettings {
return {
formRoute: ({ name }) => `/template-builder/${name}`,
columns: ['name', 'type', 'isCustom'],
};
}
readOnly: ReadOnlyMap = {
name: () => !!this.isCustom,
type: () => !!this.isCustom,
template: () => !!this.isCustom,
};
static lists: ListsMap = {
type(doc?: Doc) {
let enableInventory: boolean = false;
let schemaMap: SchemaMap = {};
if (doc) {
enableInventory = !!doc.fyo.singles.AccountingSettings?.enableInventory;
schemaMap = doc.fyo.schemaMap;
}
const models = [
ModelNameEnum.SalesInvoice,
ModelNameEnum.PurchaseInvoice,
ModelNameEnum.Payment,
];
if (enableInventory) {
models.push(
ModelNameEnum.Shipment,
ModelNameEnum.PurchaseReceipt,
ModelNameEnum.StockMovement
);
}
return models.map((value) => ({
value,
label: schemaMap[value]?.label ?? value,
}));
},
};
}