mirror of
https://github.com/frappe/books.git
synced 2025-01-26 16:48:28 +00:00
fix: pass posPrintWidth through params
This commit is contained in:
parent
aeeebc3b4f
commit
c318e81e72
@ -1,9 +1,8 @@
|
|||||||
import fs from 'fs/promises';
|
import fs from 'fs/promises';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import { fyo } from 'src/initFyo';
|
|
||||||
import { TemplateFile } from 'utils/types';
|
import { TemplateFile } from 'utils/types';
|
||||||
|
|
||||||
export async function getTemplates() {
|
export async function getTemplates(posTemplateWidth: number) {
|
||||||
const paths = await getPrintTemplatePaths();
|
const paths = await getPrintTemplatePaths();
|
||||||
if (!paths) {
|
if (!paths) {
|
||||||
return [];
|
return [];
|
||||||
@ -15,9 +14,7 @@ export async function getTemplates() {
|
|||||||
const template = await fs.readFile(filePath, 'utf-8');
|
const template = await fs.readFile(filePath, 'utf-8');
|
||||||
const { mtime } = await fs.stat(filePath);
|
const { mtime } = await fs.stat(filePath);
|
||||||
const width =
|
const width =
|
||||||
file?.split('-')[1]?.split('.')[0] === 'POS'
|
file?.split('-')[1]?.split('.')[0] === 'POS' ? posTemplateWidth : 0;
|
||||||
? (fyo.singles.PrintSettings?.posPrintWidth as number)
|
|
||||||
: 0;
|
|
||||||
const height = file?.split('-')[1]?.split('.')[0] === 'POS' ? 22 : 0;
|
const height = file?.split('-')[1]?.split('.')[0] === 'POS' ? 22 : 0;
|
||||||
|
|
||||||
templates.push({
|
templates.push({
|
||||||
|
@ -75,9 +75,10 @@ const ipc = {
|
|||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
async getTemplates(): Promise<TemplateFile[]> {
|
async getTemplates(posTemplateWidth: number): Promise<TemplateFile[]> {
|
||||||
return (await ipcRenderer.invoke(
|
return (await ipcRenderer.invoke(
|
||||||
IPC_ACTIONS.GET_TEMPLATES
|
IPC_ACTIONS.GET_TEMPLATES,
|
||||||
|
posTemplateWidth
|
||||||
)) as TemplateFile[];
|
)) as TemplateFile[];
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -205,9 +205,12 @@ export default function registerIpcMainActionListeners(main: Main) {
|
|||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
ipcMain.handle(IPC_ACTIONS.GET_TEMPLATES, async () => {
|
ipcMain.handle(
|
||||||
return getTemplates();
|
IPC_ACTIONS.GET_TEMPLATES,
|
||||||
});
|
async (_, posPrintWidth: number) => {
|
||||||
|
return getTemplates(posPrintWidth);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Database Related Actions
|
* Database Related Actions
|
||||||
|
@ -442,7 +442,9 @@ function getAllCSSAsStyleElem() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function updatePrintTemplates(fyo: Fyo) {
|
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, {
|
const existingTemplates = (await fyo.db.getAll(ModelNameEnum.PrintTemplate, {
|
||||||
fields: ['name', 'modified'],
|
fields: ['name', 'modified'],
|
||||||
filters: { isCustom: false },
|
filters: { isCustom: false },
|
||||||
|
Loading…
x
Reference in New Issue
Block a user