mirror of
https://github.com/frappe/books.git
synced 2024-11-08 14:50:56 +00:00
fix: simplify configfile updation
This commit is contained in:
parent
21826cdd15
commit
0dccb42fb1
@ -12,6 +12,7 @@ export enum ModelNameEnum {
|
||||
UOM = 'UOM',
|
||||
JournalEntry = 'JournalEntry',
|
||||
JournalEntryAccount = 'JournalEntryAccount',
|
||||
Misc = 'Misc',
|
||||
NumberSeries = 'NumberSeries',
|
||||
Party = 'Party',
|
||||
Payment = 'Payment',
|
||||
|
13
schemas/app/Misc.json
Normal file
13
schemas/app/Misc.json
Normal file
@ -0,0 +1,13 @@
|
||||
{
|
||||
"name": "Misc",
|
||||
"label": "Misc",
|
||||
"isSingle": true,
|
||||
"isChild": false,
|
||||
"fields": [
|
||||
{
|
||||
"fieldname": "openCount",
|
||||
"label": "Open Count",
|
||||
"fieldtype": "Int"
|
||||
}
|
||||
]
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
import Account from './app/Account.json';
|
||||
import AccountingLedgerEntry from './app/AccountingLedgerEntry.json';
|
||||
import AccountingSettings from './app/AccountingSettings.json';
|
||||
import Misc from './app/Misc.json';
|
||||
import Address from './app/Address.json';
|
||||
import Color from './app/Color.json';
|
||||
import CompanySettings from './app/CompanySettings.json';
|
||||
@ -46,6 +47,7 @@ export const metaSchemas: SchemaStub[] = [
|
||||
];
|
||||
|
||||
export const appSchemas: Schema[] | SchemaStub[] = [
|
||||
Misc as Schema,
|
||||
SetupWizard as Schema,
|
||||
GetStarted as Schema,
|
||||
|
||||
|
@ -48,6 +48,7 @@ import SetupWizard from './pages/SetupWizard/SetupWizard.vue';
|
||||
import setupInstance from './setup/setupInstance';
|
||||
import './styles/index.css';
|
||||
import { checkForUpdates } from './utils/ipcCalls';
|
||||
import { updateConfigFiles } from './utils/misc';
|
||||
import { Search } from './utils/search';
|
||||
import { routeTo } from './utils/ui';
|
||||
|
||||
@ -132,6 +133,7 @@ export default {
|
||||
}
|
||||
|
||||
await initializeInstance(filePath, false, countryCode, fyo);
|
||||
await updateConfigFiles(fyo);
|
||||
await this.setDesk(filePath);
|
||||
},
|
||||
async setDeskRoute() {
|
||||
|
@ -35,13 +35,14 @@ export async function initializeInstance(
|
||||
await setVersion(fyo);
|
||||
setDeviceId(fyo);
|
||||
await setInstanceId(fyo);
|
||||
await incrementOpenCount(fyo);
|
||||
await setOpenCount(fyo);
|
||||
await setCurrencySymbols(fyo);
|
||||
}
|
||||
|
||||
async function setSingles(fyo: Fyo) {
|
||||
await fyo.doc.getDoc(ModelNameEnum.AccountingSettings);
|
||||
await fyo.doc.getDoc(ModelNameEnum.GetStarted);
|
||||
await fyo.doc.getDoc(ModelNameEnum.Misc);
|
||||
}
|
||||
|
||||
async function setCreds(fyo: Fyo) {
|
||||
@ -75,6 +76,7 @@ function setDeviceId(fyo: Fyo) {
|
||||
|
||||
fyo.store.deviceId = deviceId;
|
||||
}
|
||||
|
||||
async function setInstanceId(fyo: Fyo) {
|
||||
const systemSettings = await fyo.doc.getDoc(ModelNameEnum.SystemSettings);
|
||||
if (!systemSettings.instanceId) {
|
||||
@ -99,25 +101,29 @@ async function setCurrencySymbols(fyo: Fyo) {
|
||||
) as Record<string, string | undefined>;
|
||||
}
|
||||
|
||||
export async function incrementOpenCount(fyo: Fyo) {
|
||||
const instanceId = (await fyo.getValue(
|
||||
ModelNameEnum.SystemSettings,
|
||||
'instanceId'
|
||||
)) as string;
|
||||
async function setOpenCount(fyo: Fyo) {
|
||||
const misc = await fyo.doc.getDoc(ModelNameEnum.Misc);
|
||||
let openCount = misc.openCount as number | null;
|
||||
|
||||
let openCount = 0;
|
||||
const files = (fyo.config.get(ConfigKeys.Files) ?? []) as ConfigFile[];
|
||||
for (const file of files) {
|
||||
if (file.id !== instanceId) {
|
||||
continue;
|
||||
}
|
||||
|
||||
file.openCount ??= 0;
|
||||
file.openCount += 1;
|
||||
openCount = file.openCount;
|
||||
break;
|
||||
if (typeof openCount !== 'number') {
|
||||
openCount = getOpenCountFromFiles(fyo);
|
||||
}
|
||||
|
||||
fyo.config.set(ConfigKeys.Files, files);
|
||||
fyo.store.openCount = openCount;
|
||||
if (typeof openCount !== 'number') {
|
||||
openCount = 0;
|
||||
}
|
||||
|
||||
openCount += 1;
|
||||
await misc.setAndSync('openCount', openCount);
|
||||
}
|
||||
|
||||
function getOpenCountFromFiles(fyo: Fyo) {
|
||||
const configFile = fyo.config.get(ConfigKeys.Files, []) as ConfigFile[];
|
||||
for (const file of configFile) {
|
||||
if (file.id === fyo.singles.SystemSettings?.instanceId) {
|
||||
return file.openCount ?? 0;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
@ -214,7 +214,6 @@
|
||||
import { setupDummyInstance } from 'dummy';
|
||||
import { ipcRenderer } from 'electron';
|
||||
import { t } from 'fyo';
|
||||
import { ConfigKeys } from 'fyo/core/types';
|
||||
import { DateTime } from 'luxon';
|
||||
import Button from 'src/components/Button.vue';
|
||||
import LanguageSelector from 'src/components/Controls/LanguageSelector.vue';
|
||||
@ -223,7 +222,7 @@ import Loading from 'src/components/Loading.vue';
|
||||
import Modal from 'src/components/Modal.vue';
|
||||
import { fyo } from 'src/initFyo';
|
||||
import { deleteDb, getSavePath } from 'src/utils/ipcCalls';
|
||||
import { addNewConfigFile } from 'src/utils/misc';
|
||||
import { updateConfigFiles } from 'src/utils/misc';
|
||||
import { showMessageDialog } from 'src/utils/ui';
|
||||
import { IPC_ACTIONS } from 'utils/messages';
|
||||
|
||||
@ -288,7 +287,7 @@ export default {
|
||||
}
|
||||
|
||||
this.creatingDemo = true;
|
||||
const { companyName, instanceId } = await setupDummyInstance(
|
||||
await setupDummyInstance(
|
||||
filePath,
|
||||
fyo,
|
||||
1,
|
||||
@ -299,14 +298,7 @@ export default {
|
||||
}
|
||||
);
|
||||
|
||||
addNewConfigFile(
|
||||
companyName,
|
||||
filePath,
|
||||
instanceId,
|
||||
fyo.config.get(ConfigKeys.Files),
|
||||
fyo
|
||||
);
|
||||
|
||||
updateConfigFiles(fyo);
|
||||
fyo.purgeCache();
|
||||
await this.setFiles();
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { Fyo } from 'fyo';
|
||||
import { ConfigFile, DocValueMap } from 'fyo/core/types';
|
||||
import { DocValueMap } from 'fyo/core/types';
|
||||
import { Doc } from 'fyo/model/doc';
|
||||
import { createNumberSeries } from 'fyo/model/naming';
|
||||
import {
|
||||
@ -224,28 +224,9 @@ async function setDefaultAccounts(fyo: Fyo) {
|
||||
}
|
||||
|
||||
async function completeSetup(companyName: string, fyo: Fyo) {
|
||||
await updateInitializationConfig(companyName, fyo);
|
||||
await fyo.singles.AccountingSettings!.setAndSync('setupComplete', true);
|
||||
}
|
||||
|
||||
async function updateInitializationConfig(companyName: string, fyo: Fyo) {
|
||||
const instanceId = (await fyo.getValue(
|
||||
ModelNameEnum.SystemSettings,
|
||||
'instanceId'
|
||||
)) as string;
|
||||
const dbPath = fyo.db.dbPath;
|
||||
const files = fyo.config.get('files', []) as ConfigFile[];
|
||||
|
||||
files.forEach((file) => {
|
||||
if (file.dbPath === dbPath) {
|
||||
file.companyName = companyName;
|
||||
file.id = instanceId;
|
||||
}
|
||||
});
|
||||
|
||||
fyo.config.set('files', files);
|
||||
}
|
||||
|
||||
async function checkAndCreateDoc(
|
||||
schemaName: string,
|
||||
docObject: DocValueMap,
|
||||
|
@ -58,22 +58,27 @@ export async function getSetupWizardDoc() {
|
||||
);
|
||||
}
|
||||
|
||||
export function addNewConfigFile(
|
||||
companyName: string,
|
||||
dbPath: string,
|
||||
instanceId: string,
|
||||
files: ConfigFile[],
|
||||
fyo: Fyo
|
||||
): ConfigFile {
|
||||
const newFile: ConfigFile = {
|
||||
companyName,
|
||||
dbPath,
|
||||
id: instanceId,
|
||||
openCount: 0,
|
||||
};
|
||||
export function updateConfigFiles(fyo: Fyo): ConfigFile {
|
||||
const configFiles = fyo.config.get(ConfigKeys.Files, []) as ConfigFile[];
|
||||
|
||||
files.push(newFile);
|
||||
fyo.config.set(ConfigKeys.Files, files);
|
||||
const companyName = fyo.singles.AccountingSettings!.companyName as string;
|
||||
const id = fyo.singles.SystemSettings!.instanceId as string;
|
||||
const dbPath = fyo.db.dbPath!;
|
||||
const openCount = fyo.singles.Misc!.openCount as number;
|
||||
|
||||
const fileIndex = configFiles.findIndex((f) => f.id === id);
|
||||
let newFile = { id, companyName, dbPath, openCount } as ConfigFile;
|
||||
|
||||
if (fileIndex === -1) {
|
||||
configFiles.push(newFile);
|
||||
} else {
|
||||
configFiles[fileIndex].companyName = companyName;
|
||||
configFiles[fileIndex].dbPath = dbPath;
|
||||
configFiles[fileIndex].openCount = openCount;
|
||||
newFile = configFiles[fileIndex];
|
||||
}
|
||||
|
||||
fyo.config.set(ConfigKeys.Files, configFiles);
|
||||
return newFile;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user