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