From deefcd08f91feeaeca868c3862298e994627dfc8 Mon Sep 17 00:00:00 2001 From: 18alantom <2.alan.tom@gmail.com> Date: Mon, 23 May 2022 11:51:06 +0530 Subject: [PATCH] incr: updates to dummy creation --- dummy/helpers.ts | 16 ++++++++++++++-- dummy/index.ts | 6 +++++- fyo/core/types.ts | 2 +- fyo/telemetry/helpers.ts | 1 + main/helpers.ts | 3 ++- src/App.vue | 22 +++++++++++----------- src/components/Loading.vue | 2 ++ src/components/once/TelemetryModal.vue | 5 ++++- src/pages/DatabaseSelector.vue | 4 +++- src/utils/ipcCalls.ts | 2 +- src/utils/misc.ts | 24 ++++++++++++++++-------- 11 files changed, 60 insertions(+), 27 deletions(-) diff --git a/dummy/helpers.ts b/dummy/helpers.ts index a6e837a1..b9f7a084 100644 --- a/dummy/helpers.ts +++ b/dummy/helpers.ts @@ -22,10 +22,22 @@ export const purchaseItemPartyMap: Record = Object.keys( return acc; }, {} as Record); -export const flow = [0.25, 0.2, 0.35, 0.2, 0.1, 0.01, 0.01, 0.15, 0, 0.25, 0.3, 0.5]; +export const flow = [ + 0.35, // Jan + 0.25, // Feb + 0.15, // Mar + 0.15, // Apr + 0.25, // May + 0.05, // Jun + 0.05, // Jul + 0.15, // Aug + 0.25, // Sep + 0.35, // Oct + 0.45, // Nov + 0.55, // Dec +]; export function getFlowConstant(months: number) { // Jan to December - const d = DateTime.now().minus({ months }); return flow[d.month - 1]; } diff --git a/dummy/index.ts b/dummy/index.ts index 17077a67..45294324 100644 --- a/dummy/index.ts +++ b/dummy/index.ts @@ -28,6 +28,7 @@ export async function setupDummyInstance( baseCount: number = 1000, notifier?: Notifier ) { + fyo.purgeCache(); notifier?.(fyo.t`Setting Up Instance`, -1); const options = { logo: null, @@ -245,7 +246,10 @@ async function getSalesInvoices( quantity = Math.ceil(Math.random() * 3); } - const fc = flow[date.getMonth()]; + let fc = flow[date.getMonth()]; + if (baseCount < 500) { + fc += 1; + } const rate = fyo.pesa(item!.rate * (fc + 1)).clip(0); await doc.append('items', {}); await doc.items!.at(-1)!.set({ diff --git a/fyo/core/types.ts b/fyo/core/types.ts index 6afa05fa..c2ed757d 100644 --- a/fyo/core/types.ts +++ b/fyo/core/types.ts @@ -35,13 +35,13 @@ export enum ConfigKeys { Language = 'language', DeviceId = 'deviceId', Telemetry = 'telemetry', - OpenCount = 'openCount', } export interface ConfigFile { id: string; companyName: string; dbPath: string; + openCount: number; } export interface FyoConfig { diff --git a/fyo/telemetry/helpers.ts b/fyo/telemetry/helpers.ts index 967bf522..d834f151 100644 --- a/fyo/telemetry/helpers.ts +++ b/fyo/telemetry/helpers.ts @@ -85,6 +85,7 @@ export function addNewFile( companyName, dbPath, id: getId(), + openCount: 0, }; files.push(newFile); diff --git a/main/helpers.ts b/main/helpers.ts index 34dda83b..461233d7 100644 --- a/main/helpers.ts +++ b/main/helpers.ts @@ -33,13 +33,14 @@ export async function setAndGetCleanedConfigFiles() { export async function getConfigFilesWithModified(files: ConfigFile[]) { const filesWithModified: ConfigFilesWithModified[] = []; - for (const { dbPath, id, companyName } of files) { + for (const { dbPath, id, companyName, openCount } of files) { const { mtime } = await fs.stat(dbPath); filesWithModified.push({ id, dbPath, companyName, modified: mtime.toISOString(), + openCount, }); } diff --git a/src/App.vue b/src/App.vue index 9cdcbb8e..a79c5118 100644 --- a/src/App.vue +++ b/src/App.vue @@ -4,12 +4,12 @@ class="h-screen flex flex-col font-sans overflow-hidden antialiased" > - + - +
- +
@@ -83,12 +83,12 @@ export default { this.activeScreen = 'DatabaseSelector'; }, methods: { - async setDesk() { + async setDesk(filePath) { this.activeScreen = 'Desk'; - incrementOpenCount(); + await this.setDeskRoute(); + await incrementOpenCount(filePath); await startTelemetry(); await checkForUpdates(false); - await this.setDeskRoute(); }, async fileSelected(filePath, isNew) { fyo.config.set(ConfigKeys.LastSelectedFilePath, filePath); @@ -101,7 +101,7 @@ export default { async setupComplete(setupWizardOptions) { const filePath = fyo.config.get(ConfigKeys.LastSelectedFilePath); await setupInstance(filePath, setupWizardOptions, fyo); - await this.setDesk(); + await this.setDesk(filePath); }, async showSetupWizardOrDesk(filePath) { const countryCode = await fyo.db.connectToDatabase(filePath); @@ -113,7 +113,7 @@ export default { } await initializeInstance(filePath, false, countryCode, fyo); - await this.setDesk(); + await this.setDesk(filePath); }, async setDeskRoute() { const { onboardingComplete } = await fyo.doc.getSingle('GetStarted'); @@ -125,7 +125,7 @@ export default { routeTo('/get-started'); } }, - async changeDbFile() { + async showDbSelector() { fyo.config.set('lastSelectedFilePath', null); fyo.telemetry.stop(); fyo.purgeCache(); diff --git a/src/components/Loading.vue b/src/components/Loading.vue index 0daa46cc..135fec9d 100644 --- a/src/components/Loading.vue +++ b/src/components/Loading.vue @@ -40,6 +40,7 @@ { this.creationMessage = message; this.creationPercent = percent; diff --git a/src/utils/ipcCalls.ts b/src/utils/ipcCalls.ts index eeedca72..a045ebec 100644 --- a/src/utils/ipcCalls.ts +++ b/src/utils/ipcCalls.ts @@ -80,7 +80,7 @@ export async function getSavePath(name: string, extention: string) { let filePath = response.filePath; if (filePath && !filePath.endsWith(extention)) { - filePath = filePath + extention; + filePath = `${filePath}.${extention}`; } return { canceled, filePath }; diff --git a/src/utils/misc.ts b/src/utils/misc.ts index 00100317..daafd67a 100644 --- a/src/utils/misc.ts +++ b/src/utils/misc.ts @@ -1,4 +1,4 @@ -import { ConfigKeys } from 'fyo/core/types'; +import { ConfigFile, ConfigKeys } from 'fyo/core/types'; import { getSingleValue } from 'fyo/utils'; import { DateTime } from 'luxon'; import { SetupWizard } from 'models/baseModels/SetupWizard/SetupWizard'; @@ -66,15 +66,23 @@ export async function getSetupComplete(): Promise { )); } -export function incrementOpenCount() { - let openCount = fyo.config.get(ConfigKeys.OpenCount); - if (typeof openCount !== 'number') { - openCount = 1; - } else { - openCount += 1; +export async function incrementOpenCount(dbPath: string) { + const companyName = (await fyo.getValue( + ModelNameEnum.AccountingSettings, + 'companyName' + )) as string; + const files = fyo.config.get(ConfigKeys.Files) as ConfigFile[]; + for (const file of files) { + if (file.companyName !== companyName || file.dbPath !== dbPath) { + continue; + } + + file.openCount ??= 0; + file.openCount += 1; + break; } - fyo.config.set(ConfigKeys.OpenCount, openCount); + fyo.config.set(ConfigKeys.Files, files); } export async function startTelemetry() {