mirror of
https://github.com/frappe/books.git
synced 2025-01-03 07:12:21 +00:00
incr: add button to create a demo instance
This commit is contained in:
parent
0701c56429
commit
22b90cd424
@ -22,11 +22,11 @@ export const purchaseItemPartyMap: Record<string, string> = Object.keys(
|
|||||||
return acc;
|
return acc;
|
||||||
}, {} as Record<string, string>);
|
}, {} as Record<string, string>);
|
||||||
|
|
||||||
|
export const flow = [
|
||||||
|
0.15, 0.1, 0.25, 0.1, 0.01, 0.01, 0.01, 0.05, 0, 0.15, 0.2, 0.4,
|
||||||
|
];
|
||||||
export function getFlowConstant(months: number) {
|
export function getFlowConstant(months: number) {
|
||||||
// Jan to December
|
// Jan to December
|
||||||
const flow = [
|
|
||||||
0.15, 0.1, 0.25, 0.1, 0.01, 0.01, 0.01, 0.05, 0, 0.15, 0.2, 0.4,
|
|
||||||
];
|
|
||||||
|
|
||||||
const d = DateTime.now().minus({ months });
|
const d = DateTime.now().minus({ months });
|
||||||
return flow[d.month - 1];
|
return flow[d.month - 1];
|
||||||
|
190
dummy/index.ts
190
dummy/index.ts
@ -1,4 +1,4 @@
|
|||||||
import { Fyo } from 'fyo';
|
import { Fyo, t } from 'fyo';
|
||||||
import { Doc } from 'fyo/model/doc';
|
import { Doc } from 'fyo/model/doc';
|
||||||
import { range, sample } from 'lodash';
|
import { range, sample } from 'lodash';
|
||||||
import { DateTime } from 'luxon';
|
import { DateTime } from 'luxon';
|
||||||
@ -11,6 +11,7 @@ import setupInstance from 'src/setup/setupInstance';
|
|||||||
import { getMapFromList } from 'utils';
|
import { getMapFromList } from 'utils';
|
||||||
import { getFiscalYear } from 'utils/misc';
|
import { getFiscalYear } from 'utils/misc';
|
||||||
import {
|
import {
|
||||||
|
flow,
|
||||||
getFlowConstant,
|
getFlowConstant,
|
||||||
getRandomDates,
|
getRandomDates,
|
||||||
purchaseItemPartyMap,
|
purchaseItemPartyMap,
|
||||||
@ -18,7 +19,7 @@ import {
|
|||||||
import items from './items.json';
|
import items from './items.json';
|
||||||
import parties from './parties.json';
|
import parties from './parties.json';
|
||||||
|
|
||||||
type Notifier = (stage: string, count: number, total: number) => void;
|
type Notifier = (stage: string, percent: number) => void;
|
||||||
|
|
||||||
export async function setupDummyInstance(
|
export async function setupDummyInstance(
|
||||||
dbPath: string,
|
dbPath: string,
|
||||||
@ -27,28 +28,26 @@ export async function setupDummyInstance(
|
|||||||
baseCount: number = 1000,
|
baseCount: number = 1000,
|
||||||
notifier?: Notifier
|
notifier?: Notifier
|
||||||
) {
|
) {
|
||||||
notifier?.(fyo.t`Setting Up Instance`, 0, 0);
|
notifier?.(fyo.t`Setting Up Instance`, -1);
|
||||||
await setupInstance(
|
const options = {
|
||||||
dbPath,
|
logo: null,
|
||||||
{
|
companyName: "Flo's Clothes",
|
||||||
logo: null,
|
country: 'India',
|
||||||
companyName: "Flo's Clothes",
|
fullname: 'Lin Florentine',
|
||||||
country: 'India',
|
email: 'lin@flosclothes.com',
|
||||||
fullname: 'Lin Florentine',
|
bankName: 'Supreme Bank',
|
||||||
email: 'lin@flosclothes.com',
|
currency: 'INR',
|
||||||
bankName: 'Supreme Bank',
|
fiscalYearStart: getFiscalYear('04-01', true),
|
||||||
currency: 'INR',
|
fiscalYearEnd: getFiscalYear('04-01', false),
|
||||||
fiscalYearStart: getFiscalYear('04-01', true),
|
chartOfAccounts: 'India - Chart of Accounts',
|
||||||
fiscalYearEnd: getFiscalYear('04-01', false),
|
};
|
||||||
chartOfAccounts: 'India - Chart of Accounts',
|
await setupInstance(dbPath, options, fyo);
|
||||||
},
|
|
||||||
fyo
|
|
||||||
);
|
|
||||||
|
|
||||||
years = Math.floor(years);
|
years = Math.floor(years);
|
||||||
notifier?.(fyo.t`Creating Items and Parties`, 0, 0);
|
notifier?.(fyo.t`Creating Items and Parties`, -1);
|
||||||
await generateStaticEntries(fyo);
|
await generateStaticEntries(fyo);
|
||||||
await generateDynamicEntries(fyo, years, baseCount, notifier);
|
await generateDynamicEntries(fyo, years, baseCount, notifier);
|
||||||
|
return options.companyName;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -61,29 +60,22 @@ async function generateDynamicEntries(
|
|||||||
baseCount: number,
|
baseCount: number,
|
||||||
notifier?: Notifier
|
notifier?: Notifier
|
||||||
) {
|
) {
|
||||||
notifier?.(fyo.t`Getting Sales Invoices`, 0, 0);
|
const salesInvoices = await getSalesInvoices(fyo, years, baseCount, notifier);
|
||||||
const salesInvoices = await getSalesInvoices(fyo, years, baseCount);
|
|
||||||
|
|
||||||
notifier?.(fyo.t`Getting Purchase Invoices`, 0, 0);
|
notifier?.(fyo.t`Creating Purchase Invoices`, -1);
|
||||||
const purchaseInvoices = await getPurchaseInvoices(fyo, years, salesInvoices);
|
const purchaseInvoices = await getPurchaseInvoices(fyo, years, salesInvoices);
|
||||||
|
|
||||||
notifier?.(fyo.t`Getting Journal Entries`, 0, 0);
|
notifier?.(fyo.t`Creating Journal Entries`, -1);
|
||||||
const journalEntries = await getJournalEntries(fyo, salesInvoices);
|
const journalEntries = await getJournalEntries(fyo, salesInvoices);
|
||||||
await syncAndSubmit(journalEntries, (count: number, total: number) =>
|
await syncAndSubmit(journalEntries, notifier);
|
||||||
notifier?.(fyo.t`Syncing Journal Entries`, count, total)
|
|
||||||
);
|
|
||||||
|
|
||||||
const invoices = ([salesInvoices, purchaseInvoices].flat() as Invoice[]).sort(
|
const invoices = ([salesInvoices, purchaseInvoices].flat() as Invoice[]).sort(
|
||||||
(a, b) => +(a.date as Date) - +(b.date as Date)
|
(a, b) => +(a.date as Date) - +(b.date as Date)
|
||||||
);
|
);
|
||||||
await syncAndSubmit(invoices, (count: number, total: number) =>
|
await syncAndSubmit(invoices, notifier);
|
||||||
notifier?.(fyo.t`Syncing Invoices`, count, total)
|
|
||||||
);
|
|
||||||
|
|
||||||
const payments = await getPayments(fyo, invoices);
|
const payments = await getPayments(fyo, invoices);
|
||||||
await syncAndSubmit(payments, (count: number, total: number) =>
|
await syncAndSubmit(payments, notifier);
|
||||||
notifier?.(fyo.t`Syncing Payments`, count, total)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getJournalEntries(fyo: Fyo, salesInvoices: SalesInvoice[]) {
|
async function getJournalEntries(fyo: Fyo, salesInvoices: SalesInvoice[]) {
|
||||||
@ -178,7 +170,12 @@ async function getPayments(fyo: Fyo, invoices: Invoice[]) {
|
|||||||
return payments;
|
return payments;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getSalesInvoices(fyo: Fyo, years: number, baseCount: number) {
|
async function getSalesInvoices(
|
||||||
|
fyo: Fyo,
|
||||||
|
years: number,
|
||||||
|
baseCount: number,
|
||||||
|
notifier?: Notifier
|
||||||
|
) {
|
||||||
const invoices: SalesInvoice[] = [];
|
const invoices: SalesInvoice[] = [];
|
||||||
const salesItems = items.filter((i) => i.for !== 'Purchases');
|
const salesItems = items.filter((i) => i.for !== 'Purchases');
|
||||||
const customers = parties.filter((i) => i.role !== 'Supplier');
|
const customers = parties.filter((i) => i.role !== 'Supplier');
|
||||||
@ -187,65 +184,73 @@ async function getSalesInvoices(fyo: Fyo, years: number, baseCount: number) {
|
|||||||
* Get certain number of entries for each month of the count
|
* Get certain number of entries for each month of the count
|
||||||
* of years.
|
* of years.
|
||||||
*/
|
*/
|
||||||
|
let dates: Date[] = [];
|
||||||
for (const months of range(0, years * 12)) {
|
for (const months of range(0, years * 12)) {
|
||||||
const flow = getFlowConstant(months);
|
const flow = getFlowConstant(months);
|
||||||
const count = Math.ceil(flow * baseCount * (Math.random() * 0.25 + 0.75));
|
const count = Math.ceil(flow * baseCount * (Math.random() * 0.25 + 0.75));
|
||||||
const dates = getRandomDates(count, months);
|
dates = dates.concat(getRandomDates(count, months));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* For each date create a Sales Invoice.
|
* For each date create a Sales Invoice.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
for (const date of dates) {
|
for (const d in dates) {
|
||||||
const customer = sample(customers);
|
const date = dates[d];
|
||||||
|
|
||||||
const doc = fyo.doc.getNewDoc(ModelNameEnum.SalesInvoice, {
|
notifier?.(
|
||||||
date,
|
`Creating Sales Invoices, ${d} out of ${dates.length}`,
|
||||||
}) as SalesInvoice;
|
parseInt(d) / dates.length
|
||||||
|
);
|
||||||
|
const customer = sample(customers);
|
||||||
|
|
||||||
await doc.set('party', customer!.name);
|
const doc = fyo.doc.getNewDoc(ModelNameEnum.SalesInvoice, {
|
||||||
if (!doc.account) {
|
date,
|
||||||
doc.account = 'Debtors';
|
}) as SalesInvoice;
|
||||||
}
|
|
||||||
/**
|
|
||||||
* Add `numItems` number of items to the invoice.
|
|
||||||
*/
|
|
||||||
const numItems = Math.ceil(Math.random() * 5);
|
|
||||||
for (let i = 0; i < numItems; i++) {
|
|
||||||
const item = sample(salesItems);
|
|
||||||
if ((doc.items ?? []).find((i) => i.item === item)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
let quantity = 1;
|
await doc.set('party', customer!.name);
|
||||||
|
if (!doc.account) {
|
||||||
/**
|
doc.account = 'Debtors';
|
||||||
* Increase quantity depending on the rate.
|
|
||||||
*/
|
|
||||||
if (item!.rate < 100 && Math.random() < 0.4) {
|
|
||||||
quantity = Math.ceil(Math.random() * 10);
|
|
||||||
} else if (item!.rate < 1000 && Math.random() < 0.2) {
|
|
||||||
quantity = Math.ceil(Math.random() * 4);
|
|
||||||
} else if (Math.random() < 0.01) {
|
|
||||||
quantity = Math.ceil(Math.random() * 3);
|
|
||||||
}
|
|
||||||
|
|
||||||
const rate = fyo.pesa(item!.rate * flow + 1).clip(0);
|
|
||||||
await doc.append('items', {});
|
|
||||||
await doc.items!.at(-1)!.set({
|
|
||||||
item: item!.name,
|
|
||||||
rate,
|
|
||||||
quantity,
|
|
||||||
account: item!.incomeAccount,
|
|
||||||
amount: rate.mul(quantity),
|
|
||||||
tax: item!.tax,
|
|
||||||
description: item!.description,
|
|
||||||
hsnCode: item!.hsnCode,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
invoices.push(doc);
|
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* Add `numItems` number of items to the invoice.
|
||||||
|
*/
|
||||||
|
const numItems = Math.ceil(Math.random() * 5);
|
||||||
|
for (let i = 0; i < numItems; i++) {
|
||||||
|
const item = sample(salesItems);
|
||||||
|
if ((doc.items ?? []).find((i) => i.item === item)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
let quantity = 1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Increase quantity depending on the rate.
|
||||||
|
*/
|
||||||
|
if (item!.rate < 100 && Math.random() < 0.4) {
|
||||||
|
quantity = Math.ceil(Math.random() * 10);
|
||||||
|
} else if (item!.rate < 1000 && Math.random() < 0.2) {
|
||||||
|
quantity = Math.ceil(Math.random() * 4);
|
||||||
|
} else if (Math.random() < 0.01) {
|
||||||
|
quantity = Math.ceil(Math.random() * 3);
|
||||||
|
}
|
||||||
|
|
||||||
|
const fc = flow[date.getMonth()];
|
||||||
|
const rate = fyo.pesa(item!.rate * (fc + 1)).clip(0);
|
||||||
|
await doc.append('items', {});
|
||||||
|
await doc.items!.at(-1)!.set({
|
||||||
|
item: item!.name,
|
||||||
|
rate,
|
||||||
|
quantity,
|
||||||
|
account: item!.incomeAccount,
|
||||||
|
amount: rate.mul(quantity),
|
||||||
|
tax: item!.tax,
|
||||||
|
description: item!.description,
|
||||||
|
hsnCode: item!.hsnCode,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
invoices.push(doc);
|
||||||
}
|
}
|
||||||
|
|
||||||
return invoices;
|
return invoices;
|
||||||
@ -442,14 +447,21 @@ async function generateParties(fyo: Fyo) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function syncAndSubmit(
|
async function syncAndSubmit(docs: Doc[], notifier?: Notifier) {
|
||||||
docs: Doc[],
|
const nameMap: Record<string, string> = {
|
||||||
notifier: (count: number, total: number) => void
|
[ModelNameEnum.PurchaseInvoice]: t`Invoices`,
|
||||||
) {
|
[ModelNameEnum.SalesInvoice]: t`Invoices`,
|
||||||
|
[ModelNameEnum.Payment]: t`Payments`,
|
||||||
|
[ModelNameEnum.JournalEntry]: t`Journal Entries`,
|
||||||
|
};
|
||||||
|
|
||||||
const total = docs.length;
|
const total = docs.length;
|
||||||
for (const i in docs) {
|
for (const i in docs) {
|
||||||
notifier(parseInt(i) + 1, total);
|
|
||||||
const doc = docs[i];
|
const doc = docs[i];
|
||||||
|
notifier?.(
|
||||||
|
`Syncing ${nameMap[doc.schemaName]}, ${i} out of ${total}`,
|
||||||
|
parseInt(i) / total
|
||||||
|
);
|
||||||
await doc.sync();
|
await doc.sync();
|
||||||
await doc.submit();
|
await doc.submit();
|
||||||
}
|
}
|
||||||
|
@ -523,7 +523,7 @@ export class Doc extends Observable<DocValue | Doc[]> {
|
|||||||
if (dbValues && docModified !== dbModified) {
|
if (dbValues && docModified !== dbModified) {
|
||||||
throw new ConflictError(
|
throw new ConflictError(
|
||||||
this.fyo
|
this.fyo
|
||||||
.t`Document ${this.schemaName} ${this.name} has been modified after loading` +
|
.t`${this.schema.label} ${this.name} has been modified after loading` +
|
||||||
` ${dbModified}, ${docModified}`
|
` ${dbModified}, ${docModified}`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -62,7 +62,7 @@ export function getInstanceId(fyo: Fyo): UniqueId {
|
|||||||
const file = files.find((f) => f.companyName === companyName);
|
const file = files.find((f) => f.companyName === companyName);
|
||||||
|
|
||||||
if (file === undefined) {
|
if (file === undefined) {
|
||||||
return addNewFile(companyName, files, fyo);
|
return addNewFile(companyName, fyo, files);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (file.id === undefined) {
|
if (file.id === undefined) {
|
||||||
@ -72,14 +72,18 @@ export function getInstanceId(fyo: Fyo): UniqueId {
|
|||||||
return file.id;
|
return file.id;
|
||||||
}
|
}
|
||||||
|
|
||||||
function addNewFile(
|
export function addNewFile(
|
||||||
companyName: string,
|
companyName: string,
|
||||||
files: ConfigFile[],
|
fyo: Fyo,
|
||||||
fyo: Fyo
|
files?: ConfigFile[],
|
||||||
|
dbPath?: string
|
||||||
): UniqueId {
|
): UniqueId {
|
||||||
|
files ??= fyo.config.get(ConfigKeys.Files, []) as ConfigFile[];
|
||||||
|
dbPath ??= fyo.config.get(ConfigKeys.LastSelectedFilePath, '') as string;
|
||||||
|
|
||||||
const newFile: ConfigFile = {
|
const newFile: ConfigFile = {
|
||||||
companyName,
|
companyName,
|
||||||
dbPath: fyo.config.get(ConfigKeys.LastSelectedFilePath, '') as string,
|
dbPath,
|
||||||
id: getId(),
|
id: getId(),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1,9 +1,10 @@
|
|||||||
<template>
|
<template>
|
||||||
<div
|
<div
|
||||||
class="absolute bottom-0 flex justify-end pb-6 pr-6"
|
class="absolute bottom-0 flex justify-end pb-6 pr-6"
|
||||||
style="width: calc(100% - 12rem)"
|
:style="{ width: fullWidth ? '100%' : 'calc(100% - 12rem)' }"
|
||||||
v-if="open && !close"
|
v-if="open && !close"
|
||||||
>
|
>
|
||||||
|
<!-- Loading Continer -->
|
||||||
<div
|
<div
|
||||||
class="
|
class="
|
||||||
text-gray-900
|
text-gray-900
|
||||||
@ -16,16 +17,28 @@
|
|||||||
bg-white
|
bg-white
|
||||||
rounded-lg
|
rounded-lg
|
||||||
"
|
"
|
||||||
v-if="true"
|
|
||||||
>
|
>
|
||||||
<p class="text-base text-gray-600 pb-2" v-if="message.length">{{ message }}</p>
|
<!-- Message -->
|
||||||
|
<p class="text-base text-gray-600 pb-2" v-if="message?.length">
|
||||||
|
{{ message }}
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<!-- Loading Bar Container -->
|
||||||
<div class="w-full flex flex-row items-center">
|
<div class="w-full flex flex-row items-center">
|
||||||
<div class="w-full bg-gray-200 h-3 mr-2 rounded">
|
<!-- Loading Bar BG -->
|
||||||
|
<div
|
||||||
|
class="w-full h-3 mr-2 rounded"
|
||||||
|
:class="percent >= 0 ? 'bg-gray-200' : 'bg-gray-300'"
|
||||||
|
>
|
||||||
|
<!-- Loading Bar -->
|
||||||
<div
|
<div
|
||||||
|
v-if="percent >= 0"
|
||||||
class="h-3 rounded bg-blue-400"
|
class="h-3 rounded bg-blue-400"
|
||||||
:style="{ width: `${percent * 100}%` }"
|
:style="{ width: `${percent * 100}%` }"
|
||||||
></div>
|
></div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<!-- Close Icon -->
|
||||||
<feather-icon
|
<feather-icon
|
||||||
name="x"
|
name="x"
|
||||||
class="
|
class="
|
||||||
@ -48,12 +61,16 @@ export default {
|
|||||||
open: { type: Boolean, default: false },
|
open: { type: Boolean, default: false },
|
||||||
percent: { type: Number, default: 0.5 },
|
percent: { type: Number, default: 0.5 },
|
||||||
message: { type: String, default: '' },
|
message: { type: String, default: '' },
|
||||||
|
fullWidth: { type: Boolean, default: false },
|
||||||
},
|
},
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
close: false,
|
close: false,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
mounted() {
|
||||||
|
window.l = this;
|
||||||
|
},
|
||||||
methods: {
|
methods: {
|
||||||
closeToast() {
|
closeToast() {
|
||||||
this.close = true;
|
this.close = true;
|
||||||
|
@ -28,16 +28,8 @@
|
|||||||
<!-- New File (Blue Icon) -->
|
<!-- New File (Blue Icon) -->
|
||||||
<div
|
<div
|
||||||
@click="newDatabase"
|
@click="newDatabase"
|
||||||
class="
|
class="px-6 h-18 flex flex-row items-center gap-4 p-2"
|
||||||
px-6
|
:class="creatingDemo ? '' : 'hover:bg-gray-100 cursor-pointer'"
|
||||||
h-18
|
|
||||||
flex flex-row
|
|
||||||
items-center
|
|
||||||
cursor-pointer
|
|
||||||
gap-4
|
|
||||||
p-2
|
|
||||||
hover:bg-gray-100
|
|
||||||
"
|
|
||||||
>
|
>
|
||||||
<div class="w-8 h-8 rounded-full bg-blue-500 relative flex-center">
|
<div class="w-8 h-8 rounded-full bg-blue-500 relative flex-center">
|
||||||
<feather-icon name="plus" class="text-white w-5 h-5" />
|
<feather-icon name="plus" class="text-white w-5 h-5" />
|
||||||
@ -56,16 +48,8 @@
|
|||||||
<!-- Existing File (Green Icon) -->
|
<!-- Existing File (Green Icon) -->
|
||||||
<div
|
<div
|
||||||
@click="existingDatabase"
|
@click="existingDatabase"
|
||||||
class="
|
class="px-6 h-18 flex flex-row items-center gap-4 p-2"
|
||||||
px-6
|
:class="creatingDemo ? '' : 'hover:bg-gray-100 cursor-pointer'"
|
||||||
h-18
|
|
||||||
flex flex-row
|
|
||||||
items-center
|
|
||||||
cursor-pointer
|
|
||||||
gap-4
|
|
||||||
p-2
|
|
||||||
hover:bg-gray-100
|
|
||||||
"
|
|
||||||
>
|
>
|
||||||
<div class="w-8 h-8 rounded-full bg-green-500 relative flex-center">
|
<div class="w-8 h-8 rounded-full bg-green-500 relative flex-center">
|
||||||
<feather-icon name="upload" class="w-4 h-4 text-white" />
|
<feather-icon name="upload" class="w-4 h-4 text-white" />
|
||||||
@ -84,15 +68,8 @@
|
|||||||
<!-- File List -->
|
<!-- File List -->
|
||||||
<div class="overflow-scroll" style="max-height: 340px">
|
<div class="overflow-scroll" style="max-height: 340px">
|
||||||
<div
|
<div
|
||||||
class="
|
class="h-18 px-6 flex gap-4 items-center"
|
||||||
h-18
|
:class="creatingDemo ? '' : 'hover:bg-gray-100 cursor-pointer'"
|
||||||
px-6
|
|
||||||
flex
|
|
||||||
gap-4
|
|
||||||
items-center
|
|
||||||
hover:bg-gray-100
|
|
||||||
cursor-pointer
|
|
||||||
"
|
|
||||||
v-for="(file, i) in files"
|
v-for="(file, i) in files"
|
||||||
:key="file.dbPath"
|
:key="file.dbPath"
|
||||||
@click="selectFile(file)"
|
@click="selectFile(file)"
|
||||||
@ -127,20 +104,43 @@
|
|||||||
|
|
||||||
<!-- Language Selector -->
|
<!-- Language Selector -->
|
||||||
<div
|
<div
|
||||||
class="w-full flex justify-end absolute px-6 py-6"
|
class="w-full flex justify-between items-center absolute px-6 py-6"
|
||||||
style="top: 100%; transform: translateY(-100%)"
|
style="top: 100%; transform: translateY(-100%)"
|
||||||
>
|
>
|
||||||
<LanguageSelector class="w-40" />
|
<Button
|
||||||
|
class="text-sm w-40"
|
||||||
|
@click="createDemo"
|
||||||
|
:disabled="creatingDemo"
|
||||||
|
>{{ creatingDemo ? t`Please Wait` : t`Create Demo` }}</Button
|
||||||
|
>
|
||||||
|
|
||||||
|
<LanguageSelector
|
||||||
|
v-show="!creatingDemo"
|
||||||
|
class="w-40 bg-gray-100 rounded-md"
|
||||||
|
input-class="text-sm bg-transparent"
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<Loading
|
||||||
|
v-if="creatingDemo"
|
||||||
|
:open="creatingDemo"
|
||||||
|
:full-width="true"
|
||||||
|
:percent="creationPercent"
|
||||||
|
:message="creationMessage"
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
<script>
|
<script>
|
||||||
|
import { setupDummyInstance } from 'dummy';
|
||||||
import { ipcRenderer } from 'electron';
|
import { ipcRenderer } from 'electron';
|
||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
|
import { ConfigKeys } from 'fyo/core/types';
|
||||||
|
import { addNewFile } from 'fyo/telemetry/helpers';
|
||||||
import { cloneDeep } from 'lodash';
|
import { cloneDeep } from 'lodash';
|
||||||
import { DateTime } from 'luxon';
|
import { DateTime } from 'luxon';
|
||||||
|
import Button from 'src/components/Button.vue';
|
||||||
import LanguageSelector from 'src/components/Controls/LanguageSelector.vue';
|
import LanguageSelector from 'src/components/Controls/LanguageSelector.vue';
|
||||||
|
import Loading from 'src/components/Loading.vue';
|
||||||
import WindowControls from 'src/components/WindowControls.vue';
|
import WindowControls from 'src/components/WindowControls.vue';
|
||||||
import { fyo } from 'src/initFyo';
|
import { fyo } from 'src/initFyo';
|
||||||
import { getSavePath } from 'src/utils/ipcCalls';
|
import { getSavePath } from 'src/utils/ipcCalls';
|
||||||
@ -151,16 +151,51 @@ export default {
|
|||||||
emits: ['file-selected'],
|
emits: ['file-selected'],
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
|
creationMessage: '',
|
||||||
|
creationPercent: 0,
|
||||||
|
creatingDemo: false,
|
||||||
loadingDatabase: false,
|
loadingDatabase: false,
|
||||||
fileSelectedFrom: null,
|
|
||||||
files: [],
|
files: [],
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
mounted() {
|
mounted() {
|
||||||
this.setFiles();
|
this.setFiles();
|
||||||
window.ds = this;
|
|
||||||
|
if (fyo.store.isDevelopment) {
|
||||||
|
window.ds = this;
|
||||||
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
async createDemo() {
|
||||||
|
const { filePath, canceled } = await getSavePath('demo', 'db');
|
||||||
|
if (canceled || !filePath) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.creatingDemo = true;
|
||||||
|
|
||||||
|
const companyName = await setupDummyInstance(
|
||||||
|
filePath,
|
||||||
|
fyo,
|
||||||
|
1,
|
||||||
|
1000,
|
||||||
|
(message, percent) => {
|
||||||
|
this.creationMessage = message;
|
||||||
|
this.creationPercent = percent;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
addNewFile(
|
||||||
|
companyName,
|
||||||
|
fyo,
|
||||||
|
fyo.config.get(ConfigKeys.Files, []),
|
||||||
|
filePath
|
||||||
|
);
|
||||||
|
fyo.purgeCache();
|
||||||
|
this.setFiles();
|
||||||
|
|
||||||
|
this.creatingDemo = false;
|
||||||
|
},
|
||||||
setFiles() {
|
setFiles() {
|
||||||
const files = cloneDeep(fyo.config.get('files', []));
|
const files = cloneDeep(fyo.config.get('files', []));
|
||||||
this.files = files.filter(({ dbPath }) => fs.existsSync(dbPath));
|
this.files = files.filter(({ dbPath }) => fs.existsSync(dbPath));
|
||||||
@ -171,7 +206,10 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
async newDatabase() {
|
async newDatabase() {
|
||||||
this.fileSelectedFrom = 'New File';
|
if (this.creatingDemo) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const { filePath, canceled } = await getSavePath('books', 'db');
|
const { filePath, canceled } = await getSavePath('books', 'db');
|
||||||
if (canceled || !filePath) {
|
if (canceled || !filePath) {
|
||||||
return;
|
return;
|
||||||
@ -180,7 +218,10 @@ export default {
|
|||||||
this.connectToDatabase(filePath, true);
|
this.connectToDatabase(filePath, true);
|
||||||
},
|
},
|
||||||
async existingDatabase() {
|
async existingDatabase() {
|
||||||
this.fileSelectedFrom = 'Existing File';
|
if (this.creatingDemo) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const filePath = (
|
const filePath = (
|
||||||
await ipcRenderer.invoke(IPC_ACTIONS.GET_OPEN_FILEPATH, {
|
await ipcRenderer.invoke(IPC_ACTIONS.GET_OPEN_FILEPATH, {
|
||||||
title: this.t`Select file`,
|
title: this.t`Select file`,
|
||||||
@ -191,7 +232,10 @@ export default {
|
|||||||
this.connectToDatabase(filePath);
|
this.connectToDatabase(filePath);
|
||||||
},
|
},
|
||||||
async selectFile(file) {
|
async selectFile(file) {
|
||||||
this.fileSelectedFrom = file;
|
if (this.creatingDemo) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
await this.connectToDatabase(file.dbPath);
|
await this.connectToDatabase(file.dbPath);
|
||||||
},
|
},
|
||||||
async connectToDatabase(filePath, isNew) {
|
async connectToDatabase(filePath, isNew) {
|
||||||
@ -207,6 +251,6 @@ export default {
|
|||||||
this.$emit('file-selected', filePath, !!isNew);
|
this.$emit('file-selected', filePath, !!isNew);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
components: { LanguageSelector, WindowControls },
|
components: { LanguageSelector, WindowControls, Button, Loading },
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
@ -68,16 +68,11 @@ export function incrementOpenCount() {
|
|||||||
export async function startTelemetry() {
|
export async function startTelemetry() {
|
||||||
fyo.telemetry.interestingDocs = [
|
fyo.telemetry.interestingDocs = [
|
||||||
ModelNameEnum.Payment,
|
ModelNameEnum.Payment,
|
||||||
ModelNameEnum.PaymentFor,
|
|
||||||
ModelNameEnum.SalesInvoice,
|
ModelNameEnum.SalesInvoice,
|
||||||
ModelNameEnum.SalesInvoiceItem,
|
|
||||||
ModelNameEnum.PurchaseInvoice,
|
ModelNameEnum.PurchaseInvoice,
|
||||||
ModelNameEnum.PurchaseInvoiceItem,
|
|
||||||
ModelNameEnum.JournalEntry,
|
ModelNameEnum.JournalEntry,
|
||||||
ModelNameEnum.JournalEntryAccount,
|
|
||||||
ModelNameEnum.Party,
|
ModelNameEnum.Party,
|
||||||
ModelNameEnum.Account,
|
ModelNameEnum.Item,
|
||||||
ModelNameEnum.Tax,
|
|
||||||
];
|
];
|
||||||
await fyo.telemetry.start();
|
await fyo.telemetry.start();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user