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

fix: pass posPrintWidth through params

This commit is contained in:
AbleKSaju 2025-01-03 11:30:07 +05:30
parent aeeebc3b4f
commit c318e81e72
4 changed files with 14 additions and 11 deletions

View File

@ -1,9 +1,8 @@
import fs from 'fs/promises';
import path from 'path';
import { fyo } from 'src/initFyo';
import { TemplateFile } from 'utils/types';
export async function getTemplates() {
export async function getTemplates(posTemplateWidth: number) {
const paths = await getPrintTemplatePaths();
if (!paths) {
return [];
@ -15,9 +14,7 @@ export async function getTemplates() {
const template = await fs.readFile(filePath, 'utf-8');
const { mtime } = await fs.stat(filePath);
const width =
file?.split('-')[1]?.split('.')[0] === 'POS'
? (fyo.singles.PrintSettings?.posPrintWidth as number)
: 0;
file?.split('-')[1]?.split('.')[0] === 'POS' ? posTemplateWidth : 0;
const height = file?.split('-')[1]?.split('.')[0] === 'POS' ? 22 : 0;
templates.push({

View File

@ -75,9 +75,10 @@ const ipc = {
};
},
async getTemplates(): Promise<TemplateFile[]> {
async getTemplates(posTemplateWidth: number): Promise<TemplateFile[]> {
return (await ipcRenderer.invoke(
IPC_ACTIONS.GET_TEMPLATES
IPC_ACTIONS.GET_TEMPLATES,
posTemplateWidth
)) as TemplateFile[];
},

View File

@ -205,9 +205,12 @@ export default function registerIpcMainActionListeners(main: Main) {
};
});
ipcMain.handle(IPC_ACTIONS.GET_TEMPLATES, async () => {
return getTemplates();
});
ipcMain.handle(
IPC_ACTIONS.GET_TEMPLATES,
async (_, posPrintWidth: number) => {
return getTemplates(posPrintWidth);
}
);
/**
* Database Related Actions

View File

@ -442,7 +442,9 @@ function getAllCSSAsStyleElem() {
}
export async function updatePrintTemplates(fyo: Fyo) {
const templateFiles = await ipc.getTemplates();
const templateFiles = await ipc.getTemplates(
fyo.singles.PrintSettings?.posPrintWidth as number
);
const existingTemplates = (await fyo.db.getAll(ModelNameEnum.PrintTemplate, {
fields: ['name', 'modified'],
filters: { isCustom: false },