mirror of
https://github.com/frappe/books.git
synced 2024-11-08 14:50:56 +00:00
incr: updates to dummy creation
This commit is contained in:
parent
401a86eeeb
commit
deefcd08f9
@ -22,10 +22,22 @@ export const purchaseItemPartyMap: Record<string, string> = Object.keys(
|
||||
return acc;
|
||||
}, {} as Record<string, string>);
|
||||
|
||||
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];
|
||||
}
|
||||
|
@ -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({
|
||||
|
@ -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 {
|
||||
|
@ -85,6 +85,7 @@ export function addNewFile(
|
||||
companyName,
|
||||
dbPath,
|
||||
id: getId(),
|
||||
openCount: 0,
|
||||
};
|
||||
|
||||
files.push(newFile);
|
||||
|
@ -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,
|
||||
});
|
||||
}
|
||||
|
||||
|
16
src/App.vue
16
src/App.vue
@ -9,7 +9,7 @@
|
||||
<Desk
|
||||
class="flex-1"
|
||||
v-if="activeScreen === 'Desk'"
|
||||
@change-db-file="changeDbFile"
|
||||
@change-db-file="showDbSelector"
|
||||
/>
|
||||
<DatabaseSelector
|
||||
v-if="activeScreen === 'DatabaseSelector'"
|
||||
@ -18,7 +18,7 @@
|
||||
<SetupWizard
|
||||
v-if="activeScreen === 'SetupWizard'"
|
||||
@setup-complete="setupComplete"
|
||||
@setup-canceled="changeDbFile"
|
||||
@setup-canceled="showDbSelector"
|
||||
/>
|
||||
|
||||
<!-- Render target for toasts -->
|
||||
@ -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();
|
||||
|
@ -40,6 +40,7 @@
|
||||
|
||||
<!-- Close Icon -->
|
||||
<feather-icon
|
||||
v-if="showX"
|
||||
name="x"
|
||||
class="
|
||||
w-4
|
||||
@ -62,6 +63,7 @@ export default {
|
||||
percent: { type: Number, default: 0.5 },
|
||||
message: { type: String, default: '' },
|
||||
fullWidth: { type: Boolean, default: false },
|
||||
showX: { type: Boolean, default: true },
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
|
@ -119,7 +119,10 @@ export default {
|
||||
},
|
||||
|
||||
setOpen(telemetry) {
|
||||
const openCount = fyo.config.get(ConfigKeys.OpenCount);
|
||||
const openCount = fyo.config
|
||||
.get(ConfigKeys.Files)
|
||||
.map((f) => f.openCount)
|
||||
.reduce((a, b) => (a ?? 0) + (b ?? 0));
|
||||
this.shouldOpen = !this.getIsSet(telemetry) && openCount >= 4;
|
||||
},
|
||||
},
|
||||
|
@ -139,6 +139,7 @@
|
||||
<Loading
|
||||
v-if="creatingDemo"
|
||||
:open="creatingDemo"
|
||||
:show-x="false"
|
||||
:full-width="true"
|
||||
:percent="creationPercent"
|
||||
:message="creationMessage"
|
||||
@ -214,12 +215,13 @@ export default {
|
||||
}
|
||||
|
||||
this.creatingDemo = true;
|
||||
const baseCount = fyo.store.isDevelopment ? 1000 : 150;
|
||||
|
||||
const companyName = await setupDummyInstance(
|
||||
filePath,
|
||||
fyo,
|
||||
1,
|
||||
1000,
|
||||
baseCount,
|
||||
(message, percent) => {
|
||||
this.creationMessage = message;
|
||||
this.creationPercent = percent;
|
||||
|
@ -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 };
|
||||
|
@ -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<boolean> {
|
||||
));
|
||||
}
|
||||
|
||||
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() {
|
||||
|
Loading…
Reference in New Issue
Block a user