mirror of
https://github.com/frappe/books.git
synced 2024-11-08 14:50:56 +00:00
refactor: rename 'frappe' to 'fyo' outside src
- cause now most of it is different from what it was
This commit is contained in:
parent
76bf6cfda5
commit
de7e5ba807
4
META.md
4
META.md
@ -18,7 +18,7 @@ requires resources from the _server_ side, it does so by making use of
|
||||
`ipcRenderer.send` or `ipcRenderer.invoke` i.e. if the front end is being run on
|
||||
electron.
|
||||
|
||||
The `ipcRenderer` calls are done only in `frappe/demux/*.ts` files. I.e. these
|
||||
The `ipcRenderer` calls are done only in `fyo/demux/*.ts` files. I.e. these
|
||||
are the only files on the _client_ side that are aware of the platform the
|
||||
_client_ is being run on i.e. `electron` or Browser. So all platform specific
|
||||
calls should go through these _demux_ files.
|
||||
@ -53,7 +53,7 @@ individual ones, check the `README.md` in those subdirectories:
|
||||
| `src` | _client_ | Code that mainly deals with the view layer (all `.vue` are stored here) |
|
||||
| `reports` | _client_ | Collection of logic code and view layer config files for displaying reports. |
|
||||
| `models` | _client\*_ | Collection of `Model.ts` files that manage the data and some business logic on the client side. |
|
||||
| `frappe` | _client\*_ | Code for the underlying library that manages the client side |
|
||||
| `fyo` | _client\*_ | Code for the underlying library that manages the client side |
|
||||
| `utils` | _agnostic_ | Collection of code used by either sides. |
|
||||
|
||||
#### _client\*_
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { NotFoundError } from 'frappe/utils/errors';
|
||||
import { NotFoundError } from 'fyo/utils/errors';
|
||||
import { DateTime } from 'luxon';
|
||||
|
||||
export async function getExchangeRate({
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { showMessageDialog } from '@/utils';
|
||||
import frappe, { t } from 'frappe';
|
||||
import frappe, { t } from 'fyo';
|
||||
import { DateTime } from 'luxon';
|
||||
import { stateCodeMap } from '../regional/in';
|
||||
import { exportCsv, saveExportData } from '../reports/commonExporter';
|
||||
|
@ -1,4 +1,4 @@
|
||||
import frappe from 'frappe';
|
||||
import frappe from 'fyo';
|
||||
import standardCOA from '../fixtures/verified/standardCOA.json';
|
||||
import { getCOAList } from '../src/utils';
|
||||
const accountFields = ['accountType', 'accountNumber', 'rootType', 'isGroup'];
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { Frappe } from 'frappe';
|
||||
import Doc from 'frappe/model/doc';
|
||||
import { ValidationError } from 'frappe/utils/errors';
|
||||
import { Fyo } from 'fyo';
|
||||
import Doc from 'fyo/model/doc';
|
||||
import { ValidationError } from 'fyo/utils/errors';
|
||||
import Money from 'pesa/dist/types/src/money';
|
||||
import {
|
||||
AccountEntry,
|
||||
@ -19,11 +19,11 @@ export class LedgerPosting {
|
||||
reverted: boolean;
|
||||
accountEntries: AccountEntry[];
|
||||
|
||||
frappe: Frappe;
|
||||
fyo: Fyo;
|
||||
|
||||
constructor(
|
||||
{ reference, party, date, description }: LedgerPostingOptions,
|
||||
frappe: Frappe
|
||||
fyo: Fyo
|
||||
) {
|
||||
this.reference = reference;
|
||||
this.party = party;
|
||||
@ -35,7 +35,7 @@ export class LedgerPosting {
|
||||
// To change balance while entering ledger entries
|
||||
this.accountEntries = [];
|
||||
|
||||
this.frappe = frappe;
|
||||
this.fyo = fyo;
|
||||
}
|
||||
|
||||
async debit(
|
||||
@ -66,7 +66,7 @@ export class LedgerPosting {
|
||||
amount: Money
|
||||
) {
|
||||
const debitAccounts = ['Asset', 'Expense'];
|
||||
const accountDoc = await this.frappe.doc.getDoc('Account', accountName);
|
||||
const accountDoc = await this.fyo.doc.getDoc('Account', accountName);
|
||||
const rootType = accountDoc.rootType as string;
|
||||
|
||||
if (debitAccounts.indexOf(rootType) === -1) {
|
||||
@ -94,8 +94,8 @@ export class LedgerPosting {
|
||||
referenceName: referenceName ?? this.reference.name!,
|
||||
description: this.description,
|
||||
reverted: this.reverted,
|
||||
debit: this.frappe.pesa(0),
|
||||
credit: this.frappe.pesa(0),
|
||||
debit: this.fyo.pesa(0),
|
||||
credit: this.fyo.pesa(0),
|
||||
};
|
||||
|
||||
this.entries.push(entry);
|
||||
@ -113,7 +113,7 @@ export class LedgerPosting {
|
||||
async postReverse() {
|
||||
this.validateEntries();
|
||||
|
||||
const data = await this.frappe.db.getAll('AccountingLedgerEntry', {
|
||||
const data = await this.fyo.db.getAll('AccountingLedgerEntry', {
|
||||
fields: ['name'],
|
||||
filters: {
|
||||
referenceName: this.reference.name!,
|
||||
@ -122,7 +122,7 @@ export class LedgerPosting {
|
||||
});
|
||||
|
||||
for (const entry of data) {
|
||||
const entryDoc = await this.frappe.doc.getDoc(
|
||||
const entryDoc = await this.fyo.doc.getDoc(
|
||||
'AccountingLedgerEntry',
|
||||
entry.name as string
|
||||
);
|
||||
@ -166,10 +166,10 @@ export class LedgerPosting {
|
||||
const { debit, credit } = this.getTotalDebitAndCredit();
|
||||
if (debit.neq(credit)) {
|
||||
throw new ValidationError(
|
||||
`Total Debit: ${this.frappe.format(
|
||||
`Total Debit: ${this.fyo.format(
|
||||
debit,
|
||||
'Currency'
|
||||
)} must be equal to Total Credit: ${this.frappe.format(
|
||||
)} must be equal to Total Credit: ${this.fyo.format(
|
||||
credit,
|
||||
'Currency'
|
||||
)}`
|
||||
@ -178,8 +178,8 @@ export class LedgerPosting {
|
||||
}
|
||||
|
||||
getTotalDebitAndCredit() {
|
||||
let debit = this.frappe.pesa(0);
|
||||
let credit = this.frappe.pesa(0);
|
||||
let debit = this.fyo.pesa(0);
|
||||
let credit = this.fyo.pesa(0);
|
||||
|
||||
for (const entry of this.entries) {
|
||||
debit = debit.add(entry.debit);
|
||||
@ -191,12 +191,12 @@ export class LedgerPosting {
|
||||
|
||||
async insertEntries() {
|
||||
for (const entry of this.entries) {
|
||||
const entryDoc = this.frappe.doc.getNewDoc('AccountingLedgerEntry');
|
||||
const entryDoc = this.fyo.doc.getNewDoc('AccountingLedgerEntry');
|
||||
Object.assign(entryDoc, entry);
|
||||
await entryDoc.insert();
|
||||
}
|
||||
for (const entry of this.accountEntries) {
|
||||
const entryDoc = await this.frappe.doc.getDoc('Account', entry.name);
|
||||
const entryDoc = await this.fyo.doc.getDoc('Account', entry.name);
|
||||
const balance = entryDoc.get('balance') as Money;
|
||||
entryDoc.balance = balance.add(entry.balanceChange);
|
||||
await entryDoc.update();
|
||||
@ -204,6 +204,6 @@ export class LedgerPosting {
|
||||
}
|
||||
|
||||
getRoundOffAccount() {
|
||||
return this.frappe.singles.AccountingSettings!.roundOffAccount as string;
|
||||
return this.fyo.singles.AccountingSettings!.roundOffAccount as string;
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
import Doc from 'frappe/model/doc';
|
||||
import Doc from 'fyo/model/doc';
|
||||
import Money from 'pesa/dist/types/src/money';
|
||||
|
||||
export interface LedgerPostingOptions {
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { t } from 'frappe';
|
||||
import { t } from 'fyo';
|
||||
|
||||
export const ledgerLink = {
|
||||
label: t`Ledger Entries`,
|
||||
|
@ -1,4 +1,3 @@
|
||||
import { knex, Knex } from 'knex';
|
||||
import {
|
||||
CannotCommitError,
|
||||
DatabaseError,
|
||||
@ -6,7 +5,8 @@ import {
|
||||
LinkValidationError,
|
||||
NotFoundError,
|
||||
ValueError,
|
||||
} from '../../frappe/utils/errors';
|
||||
} from 'fyo/utils/errors';
|
||||
import { knex, Knex } from 'knex';
|
||||
import {
|
||||
Field,
|
||||
FieldTypeEnum,
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { t } from 'frappe';
|
||||
import { t } from 'fyo';
|
||||
|
||||
export default {
|
||||
[t`Application of Funds (Assets)`]: {
|
||||
|
@ -1,116 +0,0 @@
|
||||
import { Frappe } from 'frappe';
|
||||
import { ConfigFile, ConfigKeys } from 'frappe/core/types';
|
||||
import { DEFAULT_COUNTRY_CODE } from 'frappe/utils/consts';
|
||||
import { Count, TelemetrySetting, UniqueId } from './types';
|
||||
|
||||
export function getId(): string {
|
||||
let id: string = '';
|
||||
|
||||
for (let i = 0; i < 4; i++) {
|
||||
id += Math.random().toString(36).slice(2, 9);
|
||||
}
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
export function getCountry(): string {
|
||||
// @ts-ignore
|
||||
return frappe.singles.SystemSettings?.countryCode ?? DEFAULT_COUNTRY_CODE;
|
||||
}
|
||||
|
||||
export function getLanguage(frappe: Frappe): string {
|
||||
return frappe.config.get('language') as string;
|
||||
}
|
||||
|
||||
export async function getCounts(
|
||||
interestingDocs: string[],
|
||||
frappe: Frappe
|
||||
): Promise<Count> {
|
||||
const countMap: Count = {};
|
||||
// @ts-ignore
|
||||
if (frappe.db === undefined) {
|
||||
return countMap;
|
||||
}
|
||||
|
||||
for (const name of interestingDocs) {
|
||||
const count: number = (await frappe.db.getAll(name)).length;
|
||||
countMap[name] = count;
|
||||
}
|
||||
|
||||
return countMap;
|
||||
}
|
||||
|
||||
export function getDeviceId(frappe: Frappe): UniqueId {
|
||||
let deviceId = frappe.config.get(ConfigKeys.DeviceId) as string | undefined;
|
||||
if (deviceId === undefined) {
|
||||
deviceId = getId();
|
||||
frappe.config.set(ConfigKeys.DeviceId, deviceId);
|
||||
}
|
||||
|
||||
return deviceId;
|
||||
}
|
||||
|
||||
export function getInstanceId(frappe: Frappe): UniqueId {
|
||||
const files = frappe.config.get(ConfigKeys.Files) as ConfigFile[];
|
||||
|
||||
// @ts-ignore
|
||||
const companyName = frappe.AccountingSettings?.companyName;
|
||||
if (companyName === undefined) {
|
||||
return '';
|
||||
}
|
||||
|
||||
const file = files.find((f) => f.companyName === companyName);
|
||||
|
||||
if (file === undefined) {
|
||||
return addNewFile(companyName, files, frappe);
|
||||
}
|
||||
|
||||
if (file.id === undefined) {
|
||||
return setInstanceId(companyName, files, frappe);
|
||||
}
|
||||
|
||||
return file.id;
|
||||
}
|
||||
|
||||
function addNewFile(
|
||||
companyName: string,
|
||||
files: ConfigFile[],
|
||||
frappe: Frappe
|
||||
): UniqueId {
|
||||
const newFile: ConfigFile = {
|
||||
companyName,
|
||||
filePath: frappe.config.get(ConfigKeys.LastSelectedFilePath, '') as string,
|
||||
id: getId(),
|
||||
};
|
||||
|
||||
files.push(newFile);
|
||||
frappe.config.set(ConfigKeys.Files, files);
|
||||
return newFile.id;
|
||||
}
|
||||
|
||||
function setInstanceId(
|
||||
companyName: string,
|
||||
files: ConfigFile[],
|
||||
frappe: Frappe
|
||||
): UniqueId {
|
||||
let id = '';
|
||||
for (const file of files) {
|
||||
if (file.id) {
|
||||
continue;
|
||||
}
|
||||
|
||||
file.id = getId();
|
||||
if (file.companyName === companyName) {
|
||||
id = file.id;
|
||||
}
|
||||
}
|
||||
|
||||
frappe.config.set(ConfigKeys.Files, files);
|
||||
return id;
|
||||
}
|
||||
|
||||
export const getTelemetryOptions = (frappe: Frappe) => ({
|
||||
[TelemetrySetting.allow]: frappe.t`Allow Telemetry`,
|
||||
[TelemetrySetting.dontLogUsage]: frappe.t`Don't Log Usage`,
|
||||
[TelemetrySetting.dontLogAnything]: frappe.t`Don't Log Anything`,
|
||||
});
|
@ -1,5 +1,5 @@
|
||||
import { Frappe } from 'frappe';
|
||||
import { AuthDemux } from 'frappe/demux/auth';
|
||||
import { Fyo } from 'fyo';
|
||||
import { AuthDemux } from 'fyo/demux/auth';
|
||||
import { AuthDemuxBase, TelemetryCreds } from 'utils/auth/types';
|
||||
import { AuthDemuxConstructor } from './types';
|
||||
|
||||
@ -17,11 +17,11 @@ interface Session {
|
||||
export class AuthHandler {
|
||||
#config: AuthConfig;
|
||||
#session: Session;
|
||||
frappe: Frappe;
|
||||
fyo: Fyo;
|
||||
#demux: AuthDemuxBase;
|
||||
|
||||
constructor(frappe: Frappe, Demux?: AuthDemuxConstructor) {
|
||||
this.frappe = frappe;
|
||||
constructor(fyo: Fyo, Demux?: AuthDemuxConstructor) {
|
||||
this.fyo = fyo;
|
||||
this.#config = {
|
||||
serverURL: '',
|
||||
backend: 'sqlite',
|
||||
@ -34,9 +34,9 @@ export class AuthHandler {
|
||||
};
|
||||
|
||||
if (Demux !== undefined) {
|
||||
this.#demux = new Demux(frappe.isElectron);
|
||||
this.#demux = new Demux(fyo.isElectron);
|
||||
} else {
|
||||
this.#demux = new AuthDemux(frappe.isElectron);
|
||||
this.#demux = new AuthDemux(fyo.isElectron);
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { Frappe } from 'frappe';
|
||||
import Doc from 'frappe/model/doc';
|
||||
import { Fyo } from 'fyo';
|
||||
import Doc from 'fyo/model/doc';
|
||||
import Money from 'pesa/dist/types/src/money';
|
||||
import { FieldType, FieldTypeEnum, RawValue } from 'schemas/types';
|
||||
import { DatabaseHandler } from './dbHandler';
|
||||
@ -22,11 +22,11 @@ import { DocValue, DocValueMap, RawValueMap } from './types';
|
||||
|
||||
export class Converter {
|
||||
db: DatabaseHandler;
|
||||
frappe: Frappe;
|
||||
fyo: Fyo;
|
||||
|
||||
constructor(db: DatabaseHandler, frappe: Frappe) {
|
||||
constructor(db: DatabaseHandler, fyo: Fyo) {
|
||||
this.db = db;
|
||||
this.frappe = frappe;
|
||||
this.fyo = fyo;
|
||||
}
|
||||
|
||||
toDocValueMap(
|
||||
@ -54,11 +54,11 @@ export class Converter {
|
||||
static toDocValue(
|
||||
value: RawValue,
|
||||
fieldtype: FieldType,
|
||||
frappe: Frappe
|
||||
fyo: Fyo
|
||||
): DocValue {
|
||||
switch (fieldtype) {
|
||||
case FieldTypeEnum.Currency:
|
||||
return frappe.pesa((value ?? 0) as string | number);
|
||||
return fyo.pesa((value ?? 0) as string | number);
|
||||
case FieldTypeEnum.Date:
|
||||
return new Date(value as string);
|
||||
case FieldTypeEnum.Datetime:
|
||||
@ -119,7 +119,7 @@ export class Converter {
|
||||
docValueMap[fieldname] = Converter.toDocValue(
|
||||
rawValue,
|
||||
field.fieldtype,
|
||||
this.frappe
|
||||
this.fyo
|
||||
);
|
||||
}
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
import { SingleValue } from 'backend/database/types';
|
||||
import { Frappe } from 'frappe';
|
||||
import { DatabaseDemux } from 'frappe/demux/db';
|
||||
import { Fyo } from 'fyo';
|
||||
import { DatabaseDemux } from 'fyo/demux/db';
|
||||
import { Field, RawValue, SchemaMap } from 'schemas/types';
|
||||
import { getMapFromList } from 'utils';
|
||||
import { DatabaseBase, DatabaseDemuxBase, GetAllOptions } from 'utils/db/types';
|
||||
@ -18,21 +18,21 @@ type TotalOutstanding = { total: number; outstanding: number };
|
||||
type Cashflow = { inflow: number; outflow: number; 'month-year': string }[];
|
||||
|
||||
export class DatabaseHandler extends DatabaseBase {
|
||||
#frappe: Frappe;
|
||||
#fyo: Fyo;
|
||||
converter: Converter;
|
||||
#demux: DatabaseDemuxBase;
|
||||
schemaMap: Readonly<SchemaMap> = {};
|
||||
fieldValueMap: Record<string, Record<string, Field>> = {};
|
||||
|
||||
constructor(frappe: Frappe, Demux?: DatabaseDemuxConstructor) {
|
||||
constructor(fyo: Fyo, Demux?: DatabaseDemuxConstructor) {
|
||||
super();
|
||||
this.#frappe = frappe;
|
||||
this.converter = new Converter(this, this.#frappe);
|
||||
this.#fyo = fyo;
|
||||
this.converter = new Converter(this, this.#fyo);
|
||||
|
||||
if (Demux !== undefined) {
|
||||
this.#demux = new Demux(frappe.isElectron);
|
||||
this.#demux = new Demux(fyo.isElectron);
|
||||
} else {
|
||||
this.#demux = new DatabaseDemux(frappe.isElectron);
|
||||
this.#demux = new DatabaseDemux(fyo.isElectron);
|
||||
}
|
||||
}
|
||||
|
||||
@ -117,7 +117,7 @@ export class DatabaseHandler extends DatabaseBase {
|
||||
const docSingleValue: SingleValue<DocValue> = [];
|
||||
for (const sv of rawSingleValue) {
|
||||
const fieldtype = this.fieldValueMap[sv.parent][sv.fieldname].fieldtype;
|
||||
const value = Converter.toDocValue(sv.value, fieldtype, this.#frappe);
|
||||
const value = Converter.toDocValue(sv.value, fieldtype, this.#fyo);
|
||||
|
||||
docSingleValue.push({
|
||||
value,
|
@ -1,19 +1,19 @@
|
||||
import Doc from 'frappe/model/doc';
|
||||
import { DocMap, ModelMap, SinglesMap } from 'frappe/model/types';
|
||||
import { coreModels } from 'frappe/models';
|
||||
import { getRandomString } from 'frappe/utils';
|
||||
import Observable from 'frappe/utils/observable';
|
||||
import { Frappe } from '..';
|
||||
import Doc from 'fyo/model/doc';
|
||||
import { DocMap, ModelMap, SinglesMap } from 'fyo/model/types';
|
||||
import { coreModels } from 'fyo/models';
|
||||
import { getRandomString } from 'fyo/utils';
|
||||
import Observable from 'fyo/utils/observable';
|
||||
import { Fyo } from '..';
|
||||
import { DocValue, DocValueMap } from './types';
|
||||
|
||||
export class DocHandler {
|
||||
frappe: Frappe;
|
||||
fyo: Fyo;
|
||||
singles: SinglesMap = {};
|
||||
docs: Observable<DocMap> = new Observable();
|
||||
models: ModelMap = {};
|
||||
|
||||
constructor(frappe: Frappe) {
|
||||
this.frappe = frappe;
|
||||
constructor(fyo: Fyo) {
|
||||
this.fyo = fyo;
|
||||
}
|
||||
|
||||
init() {
|
||||
@ -22,7 +22,7 @@ export class DocHandler {
|
||||
}
|
||||
|
||||
registerModels(models: ModelMap, regionalModels: ModelMap = {}) {
|
||||
for (const schemaName in this.frappe.db.schemaMap) {
|
||||
for (const schemaName in this.fyo.db.schemaMap) {
|
||||
if (coreModels[schemaName] !== undefined) {
|
||||
this.models[schemaName] = coreModels[schemaName];
|
||||
} else if (regionalModels[schemaName] !== undefined) {
|
||||
@ -159,12 +159,12 @@ export class DocHandler {
|
||||
|
||||
getNewDoc(schemaName: string, data: DocValueMap = {}): Doc {
|
||||
const Model = this.getModel(schemaName);
|
||||
const schema = this.frappe.schemaMap[schemaName];
|
||||
const schema = this.fyo.schemaMap[schemaName];
|
||||
if (schema === undefined) {
|
||||
throw new Error(`Schema not found for ${schemaName}`);
|
||||
}
|
||||
|
||||
const doc = new Model(schema, data, this.frappe);
|
||||
const doc = new Model(schema, data, this.fyo);
|
||||
doc.setDefaults();
|
||||
return doc;
|
||||
}
|
||||
@ -175,7 +175,7 @@ export class DocHandler {
|
||||
return;
|
||||
}
|
||||
|
||||
const docExists = await this.frappe.db.exists(schemaName, name);
|
||||
const docExists = await this.fyo.db.exists(schemaName, name);
|
||||
if (!docExists) {
|
||||
const doc = this.getNewDoc(schemaName, data);
|
||||
await doc.insert;
|
@ -1,4 +1,4 @@
|
||||
import Doc from 'frappe/model/doc';
|
||||
import Doc from 'fyo/model/doc';
|
||||
import Money from 'pesa/dist/types/src/money';
|
||||
import { RawValue } from 'schemas/types';
|
||||
import { AuthDemuxBase } from 'utils/auth/types';
|
@ -1,5 +1,5 @@
|
||||
import { ipcRenderer } from 'electron';
|
||||
import { DEFAULT_COUNTRY_CODE } from 'frappe/utils/consts';
|
||||
import { DEFAULT_COUNTRY_CODE } from 'fyo/utils/consts';
|
||||
import { SchemaMap } from 'schemas/types';
|
||||
import { DatabaseDemuxBase, DatabaseMethod } from 'utils/db/types';
|
||||
import { DatabaseResponse } from 'utils/ipc/types';
|
@ -19,7 +19,7 @@ import { format } from './utils/format';
|
||||
import { t, T } from './utils/translation';
|
||||
import { ErrorLog } from './utils/types';
|
||||
|
||||
export class Frappe {
|
||||
export class Fyo {
|
||||
t = t;
|
||||
T = T;
|
||||
|
@ -1,13 +1,13 @@
|
||||
import { Frappe } from 'frappe';
|
||||
import { DocValue, DocValueMap } from 'frappe/core/types';
|
||||
import { Verb } from 'frappe/telemetry/types';
|
||||
import { Fyo } from 'fyo';
|
||||
import { DocValue, DocValueMap } from 'fyo/core/types';
|
||||
import { Verb } from 'fyo/telemetry/types';
|
||||
import {
|
||||
Conflict,
|
||||
MandatoryError,
|
||||
NotFoundError,
|
||||
ValidationError,
|
||||
} from 'frappe/utils/errors';
|
||||
import Observable from 'frappe/utils/observable';
|
||||
} from 'fyo/utils/errors';
|
||||
import Observable from 'fyo/utils/observable';
|
||||
import Money from 'pesa/dist/types/src/money';
|
||||
import {
|
||||
Field,
|
||||
@ -46,7 +46,7 @@ import { validateSelect } from './validationFunction';
|
||||
export default class Doc extends Observable<DocValue | Doc[]> {
|
||||
name?: string;
|
||||
schema: Readonly<Schema>;
|
||||
frappe: Frappe;
|
||||
fyo: Fyo;
|
||||
fieldMap: Record<string, Field>;
|
||||
|
||||
/**
|
||||
@ -66,9 +66,9 @@ export default class Doc extends Observable<DocValue | Doc[]> {
|
||||
revertAction: false,
|
||||
};
|
||||
|
||||
constructor(schema: Schema, data: DocValueMap, frappe: Frappe) {
|
||||
constructor(schema: Schema, data: DocValueMap, fyo: Fyo) {
|
||||
super();
|
||||
this.frappe = frappe;
|
||||
this.fyo = fyo;
|
||||
this.schema = schema;
|
||||
this._setInitialValues(data);
|
||||
this.fieldMap = getMapFromList(schema.fields, 'fieldname');
|
||||
@ -190,7 +190,7 @@ export default class Doc extends Observable<DocValue | Doc[]> {
|
||||
|
||||
let defaultValue: DocValue | Doc[] = getPreDefaultValues(
|
||||
field.fieldtype,
|
||||
this.frappe
|
||||
this.fyo
|
||||
);
|
||||
const defaultFunction = this.defaults[field.fieldname];
|
||||
|
||||
@ -201,7 +201,7 @@ export default class Doc extends Observable<DocValue | Doc[]> {
|
||||
}
|
||||
|
||||
if (field.fieldtype === 'Currency' && !isPesa(defaultValue)) {
|
||||
defaultValue = this.frappe.pesa!(defaultValue as string | number);
|
||||
defaultValue = this.fyo.pesa!(defaultValue as string | number);
|
||||
}
|
||||
|
||||
this[field.fieldname] = defaultValue;
|
||||
@ -243,8 +243,8 @@ export default class Doc extends Observable<DocValue | Doc[]> {
|
||||
}
|
||||
|
||||
const childSchemaName = this.fieldMap[fieldname] as TargetField;
|
||||
const schema = this.frappe.db.schemaMap[childSchemaName.target] as Schema;
|
||||
const childDoc = new Doc(schema, data as DocValueMap, this.frappe);
|
||||
const schema = this.fyo.db.schemaMap[childSchemaName.target] as Schema;
|
||||
const childDoc = new Doc(schema, data as DocValueMap, this.fyo);
|
||||
childDoc.setDefaults();
|
||||
return childDoc;
|
||||
}
|
||||
@ -271,7 +271,7 @@ export default class Doc extends Observable<DocValue | Doc[]> {
|
||||
|
||||
if (missingMandatoryMessage.length > 0) {
|
||||
const fields = missingMandatoryMessage.join('\n');
|
||||
const message = this.frappe.t`Value missing for ${fields}`;
|
||||
const message = this.fyo.t`Value missing for ${fields}`;
|
||||
throw new MandatoryError(message);
|
||||
}
|
||||
}
|
||||
@ -330,7 +330,7 @@ export default class Doc extends Observable<DocValue | Doc[]> {
|
||||
}
|
||||
|
||||
if (!this.createdBy) {
|
||||
this.createdBy = this.frappe.auth.session.user;
|
||||
this.createdBy = this.fyo.auth.session.user;
|
||||
}
|
||||
|
||||
if (!this.created) {
|
||||
@ -341,7 +341,7 @@ export default class Doc extends Observable<DocValue | Doc[]> {
|
||||
}
|
||||
|
||||
updateModified() {
|
||||
this.modifiedBy = this.frappe.auth.session.user;
|
||||
this.modifiedBy = this.fyo.auth.session.user;
|
||||
this.modified = new Date();
|
||||
}
|
||||
|
||||
@ -350,7 +350,7 @@ export default class Doc extends Observable<DocValue | Doc[]> {
|
||||
return;
|
||||
}
|
||||
|
||||
const data = await this.frappe.db.get(this.schemaName, this.name);
|
||||
const data = await this.fyo.db.get(this.schemaName, this.name);
|
||||
if (this.schema.isSingle && !data?.name) {
|
||||
data.name = this.name!;
|
||||
}
|
||||
@ -387,7 +387,7 @@ export default class Doc extends Observable<DocValue | Doc[]> {
|
||||
return;
|
||||
}
|
||||
|
||||
this._links[fieldname] = await this.frappe.doc.getDoc(
|
||||
this._links[fieldname] = await this.fyo.doc.getDoc(
|
||||
field.target,
|
||||
value as string
|
||||
);
|
||||
@ -434,7 +434,7 @@ export default class Doc extends Observable<DocValue | Doc[]> {
|
||||
return;
|
||||
}
|
||||
|
||||
const currentDoc = await this.frappe.db.get(this.schemaName, this.name);
|
||||
const currentDoc = await this.fyo.db.get(this.schemaName, this.name);
|
||||
|
||||
// check for conflict
|
||||
if (
|
||||
@ -442,14 +442,14 @@ export default class Doc extends Observable<DocValue | Doc[]> {
|
||||
(this.modified as Date) !== (currentDoc.modified as Date)
|
||||
) {
|
||||
throw new Conflict(
|
||||
this.frappe
|
||||
this.fyo
|
||||
.t`Document ${this.schemaName} ${this.name} has been modified after loading`
|
||||
);
|
||||
}
|
||||
|
||||
if (this.submitted && !this.schema.isSubmittable) {
|
||||
throw new ValidationError(
|
||||
this.frappe.t`Document type ${this.schemaName} is not submittable`
|
||||
this.fyo.t`Document type ${this.schemaName} is not submittable`
|
||||
);
|
||||
}
|
||||
|
||||
@ -545,27 +545,24 @@ export default class Doc extends Observable<DocValue | Doc[]> {
|
||||
}
|
||||
|
||||
async insert() {
|
||||
await setName(this, this.frappe);
|
||||
await setName(this, this.fyo);
|
||||
this.setBaseMetaValues();
|
||||
await this.commit();
|
||||
await this.validateInsert();
|
||||
await this.trigger('beforeInsert', null);
|
||||
|
||||
const oldName = this.name!;
|
||||
const data = await this.frappe.db.insert(
|
||||
this.schemaName,
|
||||
this.getValidDict()
|
||||
);
|
||||
const data = await this.fyo.db.insert(this.schemaName, this.getValidDict());
|
||||
this.syncValues(data);
|
||||
|
||||
if (oldName !== this.name) {
|
||||
this.frappe.doc.removeFromCache(this.schemaName, oldName);
|
||||
this.fyo.doc.removeFromCache(this.schemaName, oldName);
|
||||
}
|
||||
|
||||
await this.trigger('afterInsert', null);
|
||||
await this.trigger('afterSave', null);
|
||||
|
||||
this.frappe.telemetry.log(Verb.Created, this.schemaName);
|
||||
this.fyo.telemetry.log(Verb.Created, this.schemaName);
|
||||
return this;
|
||||
}
|
||||
|
||||
@ -582,7 +579,7 @@ export default class Doc extends Observable<DocValue | Doc[]> {
|
||||
this.updateModified();
|
||||
|
||||
const data = this.getValidDict();
|
||||
await this.frappe.db.update(this.schemaName, data);
|
||||
await this.fyo.db.update(this.schemaName, data);
|
||||
this.syncValues(data);
|
||||
|
||||
await this.trigger('afterUpdate');
|
||||
@ -605,10 +602,10 @@ export default class Doc extends Observable<DocValue | Doc[]> {
|
||||
|
||||
async delete() {
|
||||
await this.trigger('beforeDelete');
|
||||
await this.frappe.db.delete(this.schemaName, this.name!);
|
||||
await this.fyo.db.delete(this.schemaName, this.name!);
|
||||
await this.trigger('afterDelete');
|
||||
|
||||
this.frappe.telemetry.log(Verb.Deleted, this.schemaName);
|
||||
this.fyo.telemetry.log(Verb.Deleted, this.schemaName);
|
||||
}
|
||||
|
||||
async submitOrRevert(isSubmit: boolean) {
|
||||
@ -633,7 +630,7 @@ export default class Doc extends Observable<DocValue | Doc[]> {
|
||||
|
||||
async rename(newName: string) {
|
||||
await this.trigger('beforeRename');
|
||||
await this.frappe.db.rename(this.schemaName, this.name!, newName);
|
||||
await this.fyo.db.rename(this.schemaName, this.name!, newName);
|
||||
this.name = newName;
|
||||
await this.trigger('afterRename');
|
||||
}
|
||||
@ -653,7 +650,7 @@ export default class Doc extends Observable<DocValue | Doc[]> {
|
||||
const value = d.get(childfield) ?? 0;
|
||||
if (!isPesa(value)) {
|
||||
try {
|
||||
return this.frappe.pesa(value as string | number);
|
||||
return this.fyo.pesa(value as string | number);
|
||||
} catch (err) {
|
||||
(
|
||||
err as Error
|
||||
@ -663,7 +660,7 @@ export default class Doc extends Observable<DocValue | Doc[]> {
|
||||
}
|
||||
return value as Money;
|
||||
})
|
||||
.reduce((a, b) => a.add(b), this.frappe.pesa(0));
|
||||
.reduce((a, b) => a.add(b), this.fyo.pesa(0));
|
||||
|
||||
if (convertToFloat) {
|
||||
return sum.float;
|
||||
@ -676,7 +673,7 @@ export default class Doc extends Observable<DocValue | Doc[]> {
|
||||
return '';
|
||||
}
|
||||
|
||||
return this.frappe.doc.getCachedValue(schemaName, name, fieldname);
|
||||
return this.fyo.doc.getCachedValue(schemaName, name, fieldname);
|
||||
}
|
||||
|
||||
async duplicate(shouldInsert: boolean = true): Promise<Doc> {
|
||||
@ -706,7 +703,7 @@ export default class Doc extends Observable<DocValue | Doc[]> {
|
||||
updateMap.name = updateMap.name + ' CPY';
|
||||
}
|
||||
|
||||
const doc = this.frappe.doc.getEmptyDoc(this.schemaName, false);
|
||||
const doc = this.fyo.doc.getEmptyDoc(this.schemaName, false);
|
||||
await doc.setMultiple(updateMap);
|
||||
|
||||
if (shouldInsert) {
|
||||
@ -738,13 +735,13 @@ export default class Doc extends Observable<DocValue | Doc[]> {
|
||||
static filters: FiltersMap = {};
|
||||
static emptyMessages: EmptyMessageMap = {};
|
||||
|
||||
static getListViewSettings(frappe: Frappe): ListViewSettings {
|
||||
static getListViewSettings(fyo: Fyo): ListViewSettings {
|
||||
return {};
|
||||
}
|
||||
|
||||
static getTreeSettings(frappe: Frappe): TreeViewSettings | void {}
|
||||
static getTreeSettings(fyo: Fyo): TreeViewSettings | void {}
|
||||
|
||||
static getActions(frappe: Frappe): Action[] {
|
||||
static getActions(fyo: Fyo): Action[] {
|
||||
return [];
|
||||
}
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
import { Frappe } from 'frappe';
|
||||
import { DocValue } from 'frappe/core/types';
|
||||
import { isPesa } from 'frappe/utils';
|
||||
import { Fyo } from 'fyo';
|
||||
import { DocValue } from 'fyo/core/types';
|
||||
import { isPesa } from 'fyo/utils';
|
||||
import { isEqual } from 'lodash';
|
||||
import Money from 'pesa/dist/types/src/money';
|
||||
import { Field, FieldType, FieldTypeEnum } from 'schemas/types';
|
||||
@ -28,13 +28,13 @@ export function areDocValuesEqual(
|
||||
|
||||
export function getPreDefaultValues(
|
||||
fieldtype: FieldType,
|
||||
frappe: Frappe
|
||||
fyo: Fyo
|
||||
): DocValue | Doc[] {
|
||||
switch (fieldtype) {
|
||||
case FieldTypeEnum.Table:
|
||||
return [] as Doc[];
|
||||
case FieldTypeEnum.Currency:
|
||||
return frappe.pesa!(0.0);
|
||||
return fyo.pesa!(0.0);
|
||||
case FieldTypeEnum.Int:
|
||||
case FieldTypeEnum.Float:
|
||||
return 0;
|
@ -1,8 +1,8 @@
|
||||
import { Frappe } from 'frappe';
|
||||
import NumberSeries from 'frappe/models/NumberSeries';
|
||||
import { getRandomString } from 'frappe/utils';
|
||||
import { DEFAULT_SERIES_START } from 'frappe/utils/consts';
|
||||
import { BaseError } from 'frappe/utils/errors';
|
||||
import { Fyo } from 'fyo';
|
||||
import NumberSeries from 'fyo/models/NumberSeries';
|
||||
import { getRandomString } from 'fyo/utils';
|
||||
import { DEFAULT_SERIES_START } from 'fyo/utils/consts';
|
||||
import { BaseError } from 'fyo/utils/errors';
|
||||
import { Field, Schema } from 'schemas/types';
|
||||
import Doc from './doc';
|
||||
|
||||
@ -13,8 +13,8 @@ export function getNumberSeries(schema: Schema): Field | undefined {
|
||||
return numberSeries;
|
||||
}
|
||||
|
||||
export function isNameAutoSet(schemaName: string, frappe: Frappe): boolean {
|
||||
const schema = frappe.schemaMap[schemaName]!;
|
||||
export function isNameAutoSet(schemaName: string, fyo: Fyo): boolean {
|
||||
const schema = fyo.schemaMap[schemaName]!;
|
||||
if (schema.naming === 'autoincrement') {
|
||||
return true;
|
||||
}
|
||||
@ -27,17 +27,17 @@ export function isNameAutoSet(schemaName: string, frappe: Frappe): boolean {
|
||||
return false;
|
||||
}
|
||||
|
||||
export async function setName(doc: Doc, frappe: Frappe) {
|
||||
export async function setName(doc: Doc, fyo: Fyo) {
|
||||
// if is server, always name again if autoincrement or other
|
||||
if (doc.schema.naming === 'autoincrement') {
|
||||
doc.name = await getNextId(doc.schemaName, frappe);
|
||||
doc.name = await getNextId(doc.schemaName, fyo);
|
||||
return;
|
||||
}
|
||||
|
||||
// Current, per doc number series
|
||||
const numberSeries = doc.numberSeries as string | undefined;
|
||||
if (numberSeries !== undefined) {
|
||||
doc.name = await getSeriesNext(numberSeries, doc.schemaName, frappe);
|
||||
doc.name = await getSeriesNext(numberSeries, doc.schemaName, fyo);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -58,9 +58,9 @@ export async function setName(doc: Doc, frappe: Frappe) {
|
||||
}
|
||||
}
|
||||
|
||||
export async function getNextId(schemaName: string, frappe: Frappe) {
|
||||
export async function getNextId(schemaName: string, fyo: Fyo) {
|
||||
// get the last inserted row
|
||||
const lastInserted = await getLastInserted(schemaName, frappe);
|
||||
const lastInserted = await getLastInserted(schemaName, fyo);
|
||||
let name = 1;
|
||||
if (lastInserted) {
|
||||
let lastNumber = parseInt(lastInserted.name as string);
|
||||
@ -70,8 +70,8 @@ export async function getNextId(schemaName: string, frappe: Frappe) {
|
||||
return (name + '').padStart(9, '0');
|
||||
}
|
||||
|
||||
export async function getLastInserted(schemaName: string, frappe: Frappe) {
|
||||
const lastInserted = await frappe.db.getAll(schemaName, {
|
||||
export async function getLastInserted(schemaName: string, fyo: Fyo) {
|
||||
const lastInserted = await fyo.db.getAll(schemaName, {
|
||||
fields: ['name'],
|
||||
limit: 1,
|
||||
orderBy: 'creation',
|
||||
@ -83,20 +83,20 @@ export async function getLastInserted(schemaName: string, frappe: Frappe) {
|
||||
export async function getSeriesNext(
|
||||
prefix: string,
|
||||
schemaName: string,
|
||||
frappe: Frappe
|
||||
fyo: Fyo
|
||||
) {
|
||||
let series: NumberSeries;
|
||||
|
||||
try {
|
||||
series = (await frappe.doc.getDoc('NumberSeries', prefix)) as NumberSeries;
|
||||
series = (await fyo.doc.getDoc('NumberSeries', prefix)) as NumberSeries;
|
||||
} catch (e) {
|
||||
const { statusCode } = e as BaseError;
|
||||
if (!statusCode || statusCode !== 404) {
|
||||
throw e;
|
||||
}
|
||||
|
||||
await createNumberSeries(prefix, schemaName, DEFAULT_SERIES_START, frappe);
|
||||
series = (await frappe.doc.getDoc('NumberSeries', prefix)) as NumberSeries;
|
||||
await createNumberSeries(prefix, schemaName, DEFAULT_SERIES_START, fyo);
|
||||
series = (await fyo.doc.getDoc('NumberSeries', prefix)) as NumberSeries;
|
||||
}
|
||||
|
||||
return await series.next(schemaName);
|
||||
@ -106,14 +106,14 @@ export async function createNumberSeries(
|
||||
prefix: string,
|
||||
referenceType: string,
|
||||
start: number,
|
||||
frappe: Frappe
|
||||
fyo: Fyo
|
||||
) {
|
||||
const exists = await frappe.db.exists('NumberSeries', prefix);
|
||||
const exists = await fyo.db.exists('NumberSeries', prefix);
|
||||
if (exists) {
|
||||
return;
|
||||
}
|
||||
|
||||
const series = frappe.doc.getNewDoc('NumberSeries', {
|
||||
const series = fyo.doc.getNewDoc('NumberSeries', {
|
||||
name: prefix,
|
||||
start,
|
||||
referenceType,
|
@ -1,6 +1,6 @@
|
||||
import { Frappe } from 'frappe';
|
||||
import { DocValue, DocValueMap } from 'frappe/core/types';
|
||||
import SystemSettings from 'frappe/models/SystemSettings';
|
||||
import { Fyo } from 'fyo';
|
||||
import { DocValue, DocValueMap } from 'fyo/core/types';
|
||||
import SystemSettings from 'fyo/models/SystemSettings';
|
||||
import { FieldType } from 'schemas/types';
|
||||
import { QueryFilter } from 'utils/db/types';
|
||||
import { Router } from 'vue-router';
|
||||
@ -51,7 +51,7 @@ export interface SinglesMap {
|
||||
export type FilterFunction = (doc: Doc) => QueryFilter;
|
||||
export type FiltersMap = Record<string, FilterFunction>;
|
||||
|
||||
export type EmptyMessageFunction = (doc: Doc, frappe: Frappe) => string;
|
||||
export type EmptyMessageFunction = (doc: Doc, fyo: Fyo) => string;
|
||||
export type EmptyMessageMap = Record<string, EmptyMessageFunction>;
|
||||
|
||||
export type ListFunction = (doc?: Doc) => string[];
|
@ -1,5 +1,5 @@
|
||||
import { ValidationError, ValueError } from 'frappe/utils/errors';
|
||||
import { t } from 'frappe/utils/translation';
|
||||
import { ValidationError, ValueError } from 'fyo/utils/errors';
|
||||
import { t } from 'fyo/utils/translation';
|
||||
import { OptionField } from 'schemas/types';
|
||||
|
||||
export function email(value: string) {
|
@ -1,4 +1,4 @@
|
||||
import Doc from 'frappe/model/doc';
|
||||
import Doc from 'fyo/model/doc';
|
||||
|
||||
function getPaddedName(prefix: string, next: number, padZeros: number): string {
|
||||
return prefix + next.toString().padStart(padZeros ?? 4, '0');
|
||||
@ -31,7 +31,7 @@ export default class NumberSeries extends Doc {
|
||||
}
|
||||
|
||||
const name = this.getPaddedName(this.current as number);
|
||||
return await this.frappe.db.exists(schemaName, name);
|
||||
return await this.fyo.db.exists(schemaName, name);
|
||||
}
|
||||
|
||||
getPaddedName(next: number): string {
|
@ -1,8 +1,8 @@
|
||||
import { DocValue } from 'frappe/core/types';
|
||||
import Doc from 'frappe/model/doc';
|
||||
import { ValidationMap } from 'frappe/model/types';
|
||||
import { ValidationError } from 'frappe/utils/errors';
|
||||
import { t } from 'frappe/utils/translation';
|
||||
import { DocValue } from 'fyo/core/types';
|
||||
import Doc from 'fyo/model/doc';
|
||||
import { ValidationMap } from 'fyo/model/types';
|
||||
import { ValidationError } from 'fyo/utils/errors';
|
||||
import { t } from 'fyo/utils/translation';
|
||||
|
||||
export default class SystemSettings extends Doc {
|
||||
validations: ValidationMap = {
|
@ -1,4 +1,4 @@
|
||||
import { ModelMap } from 'frappe/model/types';
|
||||
import { ModelMap } from 'fyo/model/types';
|
||||
import NumberSeries from './NumberSeries';
|
||||
import SystemSettings from './SystemSettings';
|
||||
|
116
fyo/telemetry/helpers.ts
Normal file
116
fyo/telemetry/helpers.ts
Normal file
@ -0,0 +1,116 @@
|
||||
import { Fyo } from 'fyo';
|
||||
import { ConfigFile, ConfigKeys } from 'fyo/core/types';
|
||||
import { DEFAULT_COUNTRY_CODE } from 'fyo/utils/consts';
|
||||
import { t } from 'fyo/utils/translation';
|
||||
import { Count, TelemetrySetting, UniqueId } from './types';
|
||||
|
||||
export function getId(): string {
|
||||
let id: string = '';
|
||||
|
||||
for (let i = 0; i < 4; i++) {
|
||||
id += Math.random().toString(36).slice(2, 9);
|
||||
}
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
export function getCountry(fyo: Fyo): string {
|
||||
return (
|
||||
(fyo.singles.SystemSettings?.countryCode as string) ?? DEFAULT_COUNTRY_CODE
|
||||
);
|
||||
}
|
||||
|
||||
export function getLanguage(fyo: Fyo): string {
|
||||
return fyo.config.get('language') as string;
|
||||
}
|
||||
|
||||
export async function getCounts(
|
||||
interestingDocs: string[],
|
||||
fyo: Fyo
|
||||
): Promise<Count> {
|
||||
const countMap: Count = {};
|
||||
if (fyo.db === undefined) {
|
||||
return countMap;
|
||||
}
|
||||
|
||||
for (const name of interestingDocs) {
|
||||
const count: number = (await fyo.db.getAll(name)).length;
|
||||
countMap[name] = count;
|
||||
}
|
||||
|
||||
return countMap;
|
||||
}
|
||||
|
||||
export function getDeviceId(fyo: Fyo): UniqueId {
|
||||
let deviceId = fyo.config.get(ConfigKeys.DeviceId) as string | undefined;
|
||||
if (deviceId === undefined) {
|
||||
deviceId = getId();
|
||||
fyo.config.set(ConfigKeys.DeviceId, deviceId);
|
||||
}
|
||||
|
||||
return deviceId;
|
||||
}
|
||||
|
||||
export function getInstanceId(fyo: Fyo): UniqueId {
|
||||
const files = fyo.config.get(ConfigKeys.Files) as ConfigFile[];
|
||||
|
||||
const companyName = fyo.singles.AccountingSettings?.companyName as string;
|
||||
if (companyName === undefined) {
|
||||
return '';
|
||||
}
|
||||
|
||||
const file = files.find((f) => f.companyName === companyName);
|
||||
|
||||
if (file === undefined) {
|
||||
return addNewFile(companyName, files, fyo);
|
||||
}
|
||||
|
||||
if (file.id === undefined) {
|
||||
return setInstanceId(companyName, files, fyo);
|
||||
}
|
||||
|
||||
return file.id;
|
||||
}
|
||||
|
||||
function addNewFile(
|
||||
companyName: string,
|
||||
files: ConfigFile[],
|
||||
fyo: Fyo
|
||||
): UniqueId {
|
||||
const newFile: ConfigFile = {
|
||||
companyName,
|
||||
filePath: fyo.config.get(ConfigKeys.LastSelectedFilePath, '') as string,
|
||||
id: getId(),
|
||||
};
|
||||
|
||||
files.push(newFile);
|
||||
fyo.config.set(ConfigKeys.Files, files);
|
||||
return newFile.id;
|
||||
}
|
||||
|
||||
function setInstanceId(
|
||||
companyName: string,
|
||||
files: ConfigFile[],
|
||||
fyo: Fyo
|
||||
): UniqueId {
|
||||
let id = '';
|
||||
for (const file of files) {
|
||||
if (file.id) {
|
||||
continue;
|
||||
}
|
||||
|
||||
file.id = getId();
|
||||
if (file.companyName === companyName) {
|
||||
id = file.id;
|
||||
}
|
||||
}
|
||||
|
||||
fyo.config.set(ConfigKeys.Files, files);
|
||||
return id;
|
||||
}
|
||||
|
||||
export const getTelemetryOptions = () => ({
|
||||
[TelemetrySetting.allow]: t`Allow Telemetry`,
|
||||
[TelemetrySetting.dontLogUsage]: t`Don't Log Usage`,
|
||||
[TelemetrySetting.dontLogAnything]: t`Don't Log Anything`,
|
||||
});
|
@ -1,5 +1,5 @@
|
||||
import { Frappe } from 'frappe';
|
||||
import { ConfigKeys } from 'frappe/core/types';
|
||||
import { Fyo } from 'fyo';
|
||||
import { ConfigKeys } from 'fyo/core/types';
|
||||
import { cloneDeep } from 'lodash';
|
||||
import {
|
||||
getCountry,
|
||||
@ -56,10 +56,10 @@ export class TelemetryManager {
|
||||
#started = false;
|
||||
#telemetryObject: Partial<Telemetry> = {};
|
||||
#interestingDocs: string[] = [];
|
||||
frappe: Frappe;
|
||||
fyo: Fyo;
|
||||
|
||||
constructor(frappe: Frappe) {
|
||||
this.frappe = frappe;
|
||||
constructor(fyo: Fyo) {
|
||||
this.fyo = fyo;
|
||||
}
|
||||
|
||||
set platform(value: Platform) {
|
||||
@ -83,10 +83,10 @@ export class TelemetryManager {
|
||||
}
|
||||
|
||||
async start() {
|
||||
this.#telemetryObject.country ||= getCountry();
|
||||
this.#telemetryObject.language ??= getLanguage(this.frappe);
|
||||
this.#telemetryObject.deviceId ||= getDeviceId(this.frappe);
|
||||
this.#telemetryObject.instanceId ||= getInstanceId(this.frappe);
|
||||
this.#telemetryObject.country ||= getCountry(this.fyo);
|
||||
this.#telemetryObject.language ??= getLanguage(this.fyo);
|
||||
this.#telemetryObject.deviceId ||= getDeviceId(this.fyo);
|
||||
this.#telemetryObject.instanceId ||= getInstanceId(this.fyo);
|
||||
this.#telemetryObject.openTime ||= new Date().valueOf();
|
||||
this.#telemetryObject.timeline ??= [];
|
||||
this.#telemetryObject.errors ??= {};
|
||||
@ -125,8 +125,7 @@ export class TelemetryManager {
|
||||
stop() {
|
||||
this.#started = false;
|
||||
|
||||
//@ts-ignore
|
||||
this.#telemetryObject.version = frappe.store.appVersion ?? '';
|
||||
this.#telemetryObject.version = this.fyo.store.appVersion ?? '';
|
||||
this.#telemetryObject.closeTime = new Date().valueOf();
|
||||
|
||||
const data = JSON.stringify({
|
||||
@ -137,7 +136,7 @@ export class TelemetryManager {
|
||||
this.#clear();
|
||||
|
||||
if (
|
||||
this.frappe.config.get(ConfigKeys.Telemetry) ===
|
||||
this.fyo.config.get(ConfigKeys.Telemetry) ===
|
||||
TelemetrySetting.dontLogAnything
|
||||
) {
|
||||
return;
|
||||
@ -162,7 +161,7 @@ export class TelemetryManager {
|
||||
|
||||
this.#telemetryObject.counts = await getCounts(
|
||||
this.#interestingDocs,
|
||||
this.frappe
|
||||
this.fyo
|
||||
);
|
||||
}
|
||||
|
||||
@ -171,13 +170,13 @@ export class TelemetryManager {
|
||||
return;
|
||||
}
|
||||
|
||||
const { url, token } = await this.frappe.auth.getTelemetryCreds();
|
||||
const { url, token } = await this.fyo.auth.getTelemetryCreds();
|
||||
this.#url = url;
|
||||
this.#token = token;
|
||||
}
|
||||
|
||||
#getCanLog(): boolean {
|
||||
const telemetrySetting = this.frappe.config.get(
|
||||
const telemetrySetting = this.fyo.config.get(
|
||||
ConfigKeys.Telemetry
|
||||
) as string;
|
||||
return telemetrySetting === TelemetrySetting.allow;
|
@ -2,12 +2,12 @@ import * as assert from 'assert';
|
||||
import 'mocha';
|
||||
import models, { getRegionalModels } from 'models';
|
||||
import { getSchemas } from 'schemas';
|
||||
import { Frappe } from '..';
|
||||
import { Fyo } from '..';
|
||||
import { DatabaseManager } from '../../backend/database/manager';
|
||||
import { DummyAuthDemux } from './helpers';
|
||||
|
||||
describe('Frappe', function () {
|
||||
const frappe = new Frappe({
|
||||
describe('Fyo Init', function () {
|
||||
const fyo = new Fyo({
|
||||
DatabaseDemux: DatabaseManager,
|
||||
AuthDemux: DummyAuthDemux,
|
||||
isTest: true,
|
||||
@ -16,49 +16,49 @@ describe('Frappe', function () {
|
||||
|
||||
specify('Init', async function () {
|
||||
assert.strictEqual(
|
||||
Object.keys(frappe.schemaMap).length,
|
||||
Object.keys(fyo.schemaMap).length,
|
||||
0,
|
||||
'zero schemas one'
|
||||
);
|
||||
|
||||
assert.strictEqual(
|
||||
Object.keys(frappe.schemaMap).length,
|
||||
Object.keys(fyo.schemaMap).length,
|
||||
0,
|
||||
'zero schemas two'
|
||||
);
|
||||
|
||||
await frappe.db.createNewDatabase(':memory:', 'in');
|
||||
await frappe.initializeAndRegister({}, {});
|
||||
await fyo.db.createNewDatabase(':memory:', 'in');
|
||||
await fyo.initializeAndRegister({}, {});
|
||||
assert.strictEqual(
|
||||
Object.keys(frappe.schemaMap).length > 0,
|
||||
Object.keys(fyo.schemaMap).length > 0,
|
||||
true,
|
||||
'non zero schemas'
|
||||
);
|
||||
await frappe.db.close();
|
||||
await fyo.db.close();
|
||||
});
|
||||
});
|
||||
|
||||
describe('Frappe', function () {
|
||||
describe('Fyo Docs', function () {
|
||||
const countryCode = 'in';
|
||||
let frappe: Frappe;
|
||||
let fyo: Fyo;
|
||||
const schemas = getSchemas(countryCode);
|
||||
this.beforeEach(async function () {
|
||||
frappe = new Frappe({
|
||||
fyo = new Fyo({
|
||||
DatabaseDemux: DatabaseManager,
|
||||
isTest: true,
|
||||
isElectron: false,
|
||||
});
|
||||
|
||||
const regionalModels = await getRegionalModels(countryCode);
|
||||
await frappe.db.createNewDatabase(':memory:', countryCode);
|
||||
await frappe.initializeAndRegister(models, regionalModels);
|
||||
await fyo.db.createNewDatabase(':memory:', countryCode);
|
||||
await fyo.initializeAndRegister(models, regionalModels);
|
||||
});
|
||||
|
||||
this.afterEach(async function () {
|
||||
await frappe.close();
|
||||
await fyo.close();
|
||||
});
|
||||
|
||||
specify('temp', async function () {
|
||||
frappe.db.schemaMap;
|
||||
fyo.db.schemaMap;
|
||||
});
|
||||
});
|
@ -1,6 +1,6 @@
|
||||
import { Frappe } from 'frappe';
|
||||
import { DocValue } from 'frappe/core/types';
|
||||
import Doc from 'frappe/model/doc';
|
||||
import { Fyo } from 'fyo';
|
||||
import { DocValue } from 'fyo/core/types';
|
||||
import Doc from 'fyo/model/doc';
|
||||
import { DateTime } from 'luxon';
|
||||
import Money from 'pesa/dist/types/src/money';
|
||||
import { Field, FieldType, FieldTypeEnum } from 'schemas/types';
|
||||
@ -16,7 +16,7 @@ export function format(
|
||||
value: DocValue,
|
||||
df: string | Field | null,
|
||||
doc: Doc | null,
|
||||
frappe: Frappe
|
||||
fyo: Fyo
|
||||
): string {
|
||||
if (!df) {
|
||||
return String(value);
|
||||
@ -25,11 +25,11 @@ export function format(
|
||||
const field: Field = getField(df);
|
||||
|
||||
if (field.fieldtype === FieldTypeEnum.Currency) {
|
||||
return formatCurrency(value, field, doc, frappe);
|
||||
return formatCurrency(value, field, doc, fyo);
|
||||
}
|
||||
|
||||
if (field.fieldtype === FieldTypeEnum.Date) {
|
||||
return formatDate(value, frappe);
|
||||
return formatDate(value, fyo);
|
||||
}
|
||||
|
||||
if (field.fieldtype === FieldTypeEnum.Check) {
|
||||
@ -43,10 +43,9 @@ export function format(
|
||||
return String(value);
|
||||
}
|
||||
|
||||
function formatDate(value: DocValue, frappe: Frappe): string {
|
||||
function formatDate(value: DocValue, fyo: Fyo): string {
|
||||
const dateFormat =
|
||||
(frappe.singles.SystemSettings?.dateFormat as string) ??
|
||||
DEFAULT_DATE_FORMAT;
|
||||
(fyo.singles.SystemSettings?.dateFormat as string) ?? DEFAULT_DATE_FORMAT;
|
||||
|
||||
let dateValue: DateTime;
|
||||
if (typeof value === 'string') {
|
||||
@ -69,19 +68,19 @@ function formatCurrency(
|
||||
value: DocValue,
|
||||
field: Field,
|
||||
doc: Doc | null,
|
||||
frappe: Frappe
|
||||
fyo: Fyo
|
||||
): string {
|
||||
const currency = getCurrency(field, doc, frappe);
|
||||
const currency = getCurrency(field, doc, fyo);
|
||||
|
||||
let valueString;
|
||||
try {
|
||||
valueString = formatNumber(value, frappe);
|
||||
valueString = formatNumber(value, fyo);
|
||||
} catch (err) {
|
||||
(err as Error).message += ` value: '${value}', type: ${typeof value}`;
|
||||
throw err;
|
||||
}
|
||||
|
||||
const currencySymbol = frappe.currencySymbols[currency];
|
||||
const currencySymbol = fyo.currencySymbols[currency];
|
||||
if (currencySymbol !== undefined) {
|
||||
return currencySymbol + ' ' + valueString;
|
||||
}
|
||||
@ -89,8 +88,8 @@ function formatCurrency(
|
||||
return valueString;
|
||||
}
|
||||
|
||||
function formatNumber(value: DocValue, frappe: Frappe): string {
|
||||
const numberFormatter = getNumberFormatter(frappe);
|
||||
function formatNumber(value: DocValue, fyo: Fyo): string {
|
||||
const numberFormatter = getNumberFormatter(fyo);
|
||||
if (typeof value === 'number') {
|
||||
return numberFormatter.format(value);
|
||||
}
|
||||
@ -112,24 +111,24 @@ function formatNumber(value: DocValue, frappe: Frappe): string {
|
||||
return formattedNumber;
|
||||
}
|
||||
|
||||
function getNumberFormatter(frappe: Frappe) {
|
||||
if (frappe.currencyFormatter) {
|
||||
return frappe.currencyFormatter;
|
||||
function getNumberFormatter(fyo: Fyo) {
|
||||
if (fyo.currencyFormatter) {
|
||||
return fyo.currencyFormatter;
|
||||
}
|
||||
|
||||
const locale =
|
||||
(frappe.singles.SystemSettings?.locale as string) ?? DEFAULT_LOCALE;
|
||||
(fyo.singles.SystemSettings?.locale as string) ?? DEFAULT_LOCALE;
|
||||
const display =
|
||||
(frappe.singles.SystemSettings?.displayPrecision as number) ??
|
||||
(fyo.singles.SystemSettings?.displayPrecision as number) ??
|
||||
DEFAULT_DISPLAY_PRECISION;
|
||||
|
||||
return (frappe.currencyFormatter = Intl.NumberFormat(locale, {
|
||||
return (fyo.currencyFormatter = Intl.NumberFormat(locale, {
|
||||
style: 'decimal',
|
||||
minimumFractionDigits: display,
|
||||
}));
|
||||
}
|
||||
|
||||
function getCurrency(field: Field, doc: Doc | null, frappe: Frappe): string {
|
||||
function getCurrency(field: Field, doc: Doc | null, fyo: Fyo): string {
|
||||
if (doc && doc.getCurrencies[field.fieldname]) {
|
||||
return doc.getCurrencies[field.fieldname]();
|
||||
}
|
||||
@ -138,9 +137,7 @@ function getCurrency(field: Field, doc: Doc | null, frappe: Frappe): string {
|
||||
return doc.parentdoc.getCurrencies[field.fieldname]();
|
||||
}
|
||||
|
||||
return (
|
||||
(frappe.singles.SystemSettings?.currency as string) ?? DEFAULT_CURRENCY
|
||||
);
|
||||
return (fyo.singles.SystemSettings?.currency as string) ?? DEFAULT_CURRENCY;
|
||||
}
|
||||
|
||||
function getField(df: string | Field): Field {
|
@ -5,8 +5,8 @@ the models. **Models** here, refers to the classes that handle the data, its
|
||||
validation and updation and a bunch of other stuff.
|
||||
|
||||
Each model directly or indirectly extends the `Doc` class from
|
||||
`frappe/model/doc.ts` so for more info check that file and the associated types
|
||||
in `frappe/model/types.ts`.
|
||||
`fyo/model/doc.ts` so for more info check that file and the associated types
|
||||
in `fyo/model/types.ts`.
|
||||
|
||||
A model class can used even if the class body has no content, for example
|
||||
`PurchaseInvoiceItem`. Else the model used will default to using `Doc`. The
|
||||
@ -31,13 +31,13 @@ constructor. Check `schemas/README.md` for info on this.
|
||||
|
||||
When adding stuff to `models/**` make sure that it isn't importing any Vue code
|
||||
or other frontend specific code globally. This is cause model file tests will
|
||||
directly use the the `Frappe` class and will be run using `mocha` on `node`.
|
||||
directly use the the `Fyo` class and will be run using `mocha` on `node`.
|
||||
|
||||
Importing frontend code will break all the tests. This also implies that one
|
||||
should be wary about transitive dependencies.
|
||||
|
||||
It should also not import the `frappe` object (singleton) from `src`, where ever
|
||||
frappe is required in models it should be passed to it.
|
||||
It should also not import the `Fyo` object (singleton) from `src`, where ever
|
||||
`fyo` is required in models it should be passed to it.
|
||||
|
||||
_Note: Frontend specific code can be imported but they should be done so, only
|
||||
using dynamic imports i.e. `await import('...')`._
|
||||
|
@ -1,10 +1,10 @@
|
||||
import { Frappe } from 'frappe';
|
||||
import Doc from 'frappe/model/doc';
|
||||
import { Fyo } from 'fyo';
|
||||
import Doc from 'fyo/model/doc';
|
||||
import {
|
||||
FiltersMap,
|
||||
ListViewSettings,
|
||||
TreeViewSettings,
|
||||
} from 'frappe/model/types';
|
||||
} from 'fyo/model/types';
|
||||
import { QueryFilter } from 'utils/db/types';
|
||||
import { AccountRootType, AccountType } from './types';
|
||||
|
||||
@ -18,7 +18,7 @@ export class Account extends Doc {
|
||||
return;
|
||||
}
|
||||
|
||||
const account = await this.frappe.db.get(
|
||||
const account = await this.fyo.db.get(
|
||||
'Account',
|
||||
this.parentAccount as string
|
||||
);
|
||||
@ -31,11 +31,11 @@ export class Account extends Doc {
|
||||
};
|
||||
}
|
||||
|
||||
static getTreeSettings(frappe: Frappe): void | TreeViewSettings {
|
||||
static getTreeSettings(fyo: Fyo): void | TreeViewSettings {
|
||||
return {
|
||||
parentField: 'parentAccount',
|
||||
async getRootLabel(): Promise<string> {
|
||||
const accountingSettings = await frappe.doc.getSingle(
|
||||
const accountingSettings = await fyo.doc.getSingle(
|
||||
'AccountingSettings'
|
||||
);
|
||||
return accountingSettings.companyName as string;
|
||||
|
@ -1,5 +1,5 @@
|
||||
import Doc from 'frappe/model/doc';
|
||||
import { ListViewSettings } from 'frappe/model/types';
|
||||
import Doc from 'fyo/model/doc';
|
||||
import { ListViewSettings } from 'fyo/model/types';
|
||||
|
||||
export class AccountingLedgerEntry extends Doc {
|
||||
static getListViewSettings(): ListViewSettings {
|
||||
|
@ -1,5 +1,5 @@
|
||||
import Doc from 'frappe/model/doc';
|
||||
import { FiltersMap, ListsMap } from 'frappe/model/types';
|
||||
import Doc from 'fyo/model/doc';
|
||||
import { FiltersMap, ListsMap } from 'fyo/model/types';
|
||||
import countryInfo from '../../../fixtures/countryInfo.json';
|
||||
|
||||
export class AccountingSettings extends Doc {
|
||||
|
@ -1,5 +1,6 @@
|
||||
import Doc from 'frappe/model/doc';
|
||||
import { EmptyMessageMap, FormulaMap, ListsMap } from 'frappe/model/types';
|
||||
import { Fyo } from 'fyo';
|
||||
import Doc from 'fyo/model/doc';
|
||||
import { EmptyMessageMap, FormulaMap, ListsMap } from 'fyo/model/types';
|
||||
import { stateCodeMap } from 'regional/in';
|
||||
import { titleCase } from 'utils';
|
||||
import countryInfo from '../../../fixtures/countryInfo.json';
|
||||
@ -36,12 +37,12 @@ export class Address extends Doc {
|
||||
};
|
||||
|
||||
static emptyMessages: EmptyMessageMap = {
|
||||
state: (doc: Doc, frappe) => {
|
||||
state: (doc: Doc, fyo: Fyo) => {
|
||||
if (doc.country) {
|
||||
return frappe.t`Enter State`;
|
||||
return fyo.t`Enter State`;
|
||||
}
|
||||
|
||||
return frappe.t`Enter Country to load States`;
|
||||
return fyo.t`Enter Country to load States`;
|
||||
},
|
||||
};
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { LedgerPosting } from 'accounting/ledgerPosting';
|
||||
import { DocValue } from 'frappe/core/types';
|
||||
import Doc from 'frappe/model/doc';
|
||||
import { DefaultMap, FiltersMap, FormulaMap } from 'frappe/model/types';
|
||||
import { DocValue } from 'fyo/core/types';
|
||||
import Doc from 'fyo/model/doc';
|
||||
import { DefaultMap, FiltersMap, FormulaMap } from 'fyo/model/types';
|
||||
import Money from 'pesa/dist/types/src/money';
|
||||
import { getExchangeRate } from '../../../accounting/exchangeRate';
|
||||
import { Party } from '../Party/Party';
|
||||
@ -27,7 +27,7 @@ export abstract class Invoice extends Doc {
|
||||
}
|
||||
|
||||
async getPayments() {
|
||||
const payments = await this.frappe.db.getAll('PaymentFor', {
|
||||
const payments = await this.fyo.db.getAll('PaymentFor', {
|
||||
fields: ['parent'],
|
||||
filters: { referenceName: this.name! },
|
||||
orderBy: 'name',
|
||||
@ -55,12 +55,12 @@ export abstract class Invoice extends Doc {
|
||||
await entries.post();
|
||||
|
||||
// update outstanding amounts
|
||||
await this.frappe.db.update(this.schemaName, {
|
||||
await this.fyo.db.update(this.schemaName, {
|
||||
name: this.name as string,
|
||||
outstandingAmount: this.baseGrandTotal!,
|
||||
});
|
||||
|
||||
const party = (await this.frappe.doc.getDoc('Party', this.party!)) as Party;
|
||||
const party = (await this.fyo.doc.getDoc('Party', this.party!)) as Party;
|
||||
await party.updateOutstandingAmount();
|
||||
}
|
||||
|
||||
@ -68,7 +68,7 @@ export abstract class Invoice extends Doc {
|
||||
const paymentRefList = await this.getPayments();
|
||||
for (const paymentFor of paymentRefList) {
|
||||
const paymentReference = paymentFor.parent;
|
||||
const payment = (await this.frappe.doc.getDoc(
|
||||
const payment = (await this.fyo.doc.getDoc(
|
||||
'Payment',
|
||||
paymentReference as string
|
||||
)) as Payment;
|
||||
@ -79,7 +79,7 @@ export abstract class Invoice extends Doc {
|
||||
}
|
||||
|
||||
// To set the payment status as unsubmitted.
|
||||
await this.frappe.db.update('Payment', {
|
||||
await this.fyo.db.update('Payment', {
|
||||
name: paymentReference,
|
||||
submitted: false,
|
||||
cancelled: true,
|
||||
@ -92,7 +92,7 @@ export abstract class Invoice extends Doc {
|
||||
async getExchangeRate() {
|
||||
if (!this.currency) return 1.0;
|
||||
|
||||
const accountingSettings = await this.frappe.doc.getSingle(
|
||||
const accountingSettings = await this.fyo.doc.getSingle(
|
||||
'AccountingSettings'
|
||||
);
|
||||
const companyCurrency = accountingSettings.currency;
|
||||
@ -130,8 +130,8 @@ export abstract class Invoice extends Doc {
|
||||
taxes[account] = taxes[account] || {
|
||||
account,
|
||||
rate,
|
||||
amount: this.frappe.pesa(0),
|
||||
baseAmount: this.frappe.pesa(0),
|
||||
amount: this.fyo.pesa(0),
|
||||
baseAmount: this.fyo.pesa(0),
|
||||
};
|
||||
|
||||
const amount = (row.amount as Money).mul(rate).div(100);
|
||||
@ -150,7 +150,7 @@ export abstract class Invoice extends Doc {
|
||||
|
||||
async getTax(tax: string) {
|
||||
if (!this._taxes![tax]) {
|
||||
this._taxes[tax] = await this.frappe.doc.getDoc('Tax', tax);
|
||||
this._taxes[tax] = await this.fyo.doc.getDoc('Tax', tax);
|
||||
}
|
||||
|
||||
return this._taxes[tax];
|
||||
@ -167,7 +167,7 @@ export abstract class Invoice extends Doc {
|
||||
this.getFrom('Party', this.party!, 'defaultAccount') as string,
|
||||
currency: async () =>
|
||||
(this.getFrom('Party', this.party!, 'currency') as string) ||
|
||||
(this.frappe.singles.AccountingSettings!.currency as string),
|
||||
(this.fyo.singles.AccountingSettings!.currency as string),
|
||||
exchangeRate: async () => await this.getExchangeRate(),
|
||||
netTotal: async () => this.getSum('items', 'amount', false),
|
||||
baseNetTotal: async () => this.netTotal!.mul(this.exchangeRate!),
|
||||
|
@ -1,12 +1,12 @@
|
||||
import { DocValue } from 'frappe/core/types';
|
||||
import Doc from 'frappe/model/doc';
|
||||
import { DocValue } from 'fyo/core/types';
|
||||
import Doc from 'fyo/model/doc';
|
||||
import {
|
||||
DependsOnMap,
|
||||
FiltersMap,
|
||||
FormulaMap,
|
||||
ValidationMap,
|
||||
} from 'frappe/model/types';
|
||||
import { ValidationError } from 'frappe/utils/errors';
|
||||
} from 'fyo/model/types';
|
||||
import { ValidationError } from 'fyo/utils/errors';
|
||||
import Money from 'pesa/dist/types/src/money';
|
||||
import { Invoice } from '../Invoice/Invoice';
|
||||
|
||||
@ -32,7 +32,7 @@ export abstract class InvoiceItem extends Doc {
|
||||
'Item',
|
||||
this.item as string,
|
||||
'rate'
|
||||
)) || this.frappe.pesa(0)) as Money;
|
||||
)) || this.fyo.pesa(0)) as Money;
|
||||
|
||||
return baseRate.div(this.exchangeRate!);
|
||||
},
|
||||
@ -74,7 +74,7 @@ export abstract class InvoiceItem extends Doc {
|
||||
}
|
||||
|
||||
throw new ValidationError(
|
||||
this.frappe.t`Rate (${this.frappe.format(
|
||||
this.fyo.t`Rate (${this.fyo.format(
|
||||
value,
|
||||
'Currency'
|
||||
)}) cannot be less zero.`
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { Frappe } from 'frappe';
|
||||
import { DocValue } from 'frappe/core/types';
|
||||
import Doc from 'frappe/model/doc';
|
||||
import { Fyo } from 'fyo';
|
||||
import { DocValue } from 'fyo/core/types';
|
||||
import Doc from 'fyo/model/doc';
|
||||
import {
|
||||
Action,
|
||||
DependsOnMap,
|
||||
@ -8,8 +8,8 @@ import {
|
||||
FormulaMap,
|
||||
ListViewSettings,
|
||||
ValidationMap,
|
||||
} from 'frappe/model/types';
|
||||
import { ValidationError } from 'frappe/utils/errors';
|
||||
} from 'fyo/model/types';
|
||||
import { ValidationError } from 'fyo/utils/errors';
|
||||
import Money from 'pesa/dist/types/src/money';
|
||||
|
||||
export class Item extends Doc {
|
||||
@ -20,11 +20,11 @@ export class Item extends Doc {
|
||||
accountName = 'Sales';
|
||||
}
|
||||
|
||||
const accountExists = await this.frappe.db.exists('Account', accountName);
|
||||
const accountExists = await this.fyo.db.exists('Account', accountName);
|
||||
return accountExists ? accountName : '';
|
||||
},
|
||||
expenseAccount: async () => {
|
||||
const cogs = await this.frappe.db.getAllRaw('Account', {
|
||||
const cogs = await this.fyo.db.getAllRaw('Account', {
|
||||
filters: {
|
||||
accountType: 'Cost of Goods Sold',
|
||||
},
|
||||
@ -57,18 +57,18 @@ export class Item extends Doc {
|
||||
validations: ValidationMap = {
|
||||
rate: async (value: DocValue) => {
|
||||
if ((value as Money).isNegative()) {
|
||||
throw new ValidationError(this.frappe.t`Rate can't be negative.`);
|
||||
throw new ValidationError(this.fyo.t`Rate can't be negative.`);
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
static getActions(frappe: Frappe): Action[] {
|
||||
static getActions(fyo: Fyo): Action[] {
|
||||
return [
|
||||
{
|
||||
label: frappe.t`New Invoice`,
|
||||
label: fyo.t`New Invoice`,
|
||||
condition: (doc) => !doc.isNew,
|
||||
action: async (doc, router) => {
|
||||
const invoice = await frappe.doc.getEmptyDoc('SalesInvoice');
|
||||
const invoice = await fyo.doc.getEmptyDoc('SalesInvoice');
|
||||
invoice.append('items', {
|
||||
item: doc.name as string,
|
||||
rate: doc.rate as Money,
|
||||
@ -78,10 +78,10 @@ export class Item extends Doc {
|
||||
},
|
||||
},
|
||||
{
|
||||
label: frappe.t`New Bill`,
|
||||
label: fyo.t`New Bill`,
|
||||
condition: (doc) => !doc.isNew,
|
||||
action: async (doc, router) => {
|
||||
const invoice = await frappe.doc.getEmptyDoc('PurchaseInvoice');
|
||||
const invoice = await fyo.doc.getEmptyDoc('PurchaseInvoice');
|
||||
invoice.append('items', {
|
||||
item: doc.name as string,
|
||||
rate: doc.rate as Money,
|
||||
|
@ -1,11 +1,11 @@
|
||||
import { Frappe } from 'frappe';
|
||||
import Doc from 'frappe/model/doc';
|
||||
import { Fyo } from 'fyo';
|
||||
import Doc from 'fyo/model/doc';
|
||||
import {
|
||||
Action,
|
||||
DefaultMap,
|
||||
FiltersMap,
|
||||
ListViewSettings,
|
||||
} from 'frappe/model/types';
|
||||
} from 'fyo/model/types';
|
||||
import { DateTime } from 'luxon';
|
||||
import { getLedgerLinkAction } from 'models/helpers';
|
||||
import Money from 'pesa/dist/types/src/money';
|
||||
@ -15,7 +15,7 @@ export class JournalEntry extends Doc {
|
||||
accounts: Doc[] = [];
|
||||
|
||||
getPosting() {
|
||||
const entries = new LedgerPosting({ reference: this }, this.frappe);
|
||||
const entries = new LedgerPosting({ reference: this }, this.fyo);
|
||||
|
||||
for (const row of this.accounts) {
|
||||
const debit = row.debit as Money;
|
||||
@ -56,17 +56,17 @@ export class JournalEntry extends Doc {
|
||||
numberSeries: () => ({ referenceType: 'JournalEntry' }),
|
||||
};
|
||||
|
||||
static getActions(frappe: Frappe): Action[] {
|
||||
return [getLedgerLinkAction(frappe)];
|
||||
static getActions(fyo: Fyo): Action[] {
|
||||
return [getLedgerLinkAction(fyo)];
|
||||
}
|
||||
|
||||
static getListViewSettings(frappe: Frappe): ListViewSettings {
|
||||
static getListViewSettings(fyo: Fyo): ListViewSettings {
|
||||
return {
|
||||
formRoute: (name) => `/edit/JournalEntry/${name}`,
|
||||
columns: [
|
||||
'date',
|
||||
{
|
||||
label: frappe.t`Status`,
|
||||
label: fyo.t`Status`,
|
||||
fieldtype: 'Select',
|
||||
size: 'small',
|
||||
render(doc) {
|
||||
@ -88,7 +88,7 @@ export class JournalEntry extends Doc {
|
||||
},
|
||||
},
|
||||
{
|
||||
label: frappe.t`Entry ID`,
|
||||
label: fyo.t`Entry ID`,
|
||||
fieldtype: 'Data',
|
||||
fieldname: 'name',
|
||||
getValue(doc) {
|
||||
|
@ -1,5 +1,5 @@
|
||||
import Doc from 'frappe/model/doc';
|
||||
import { FiltersMap, FormulaMap } from 'frappe/model/types';
|
||||
import Doc from 'fyo/model/doc';
|
||||
import { FiltersMap, FormulaMap } from 'fyo/model/types';
|
||||
import Money from 'pesa/dist/types/src/money';
|
||||
|
||||
export class JournalEntryAccount extends Doc {
|
||||
@ -8,7 +8,7 @@ export class JournalEntryAccount extends Doc {
|
||||
|
||||
const otherTypeValue = this.get(otherType) as Money;
|
||||
if (!otherTypeValue.isZero()) {
|
||||
return this.frappe.pesa(0);
|
||||
return this.fyo.pesa(0);
|
||||
}
|
||||
|
||||
const totalType = this.parentdoc!.getSum('accounts', type, false) as Money;
|
||||
|
@ -1,11 +1,11 @@
|
||||
import { Frappe } from 'frappe';
|
||||
import Doc from 'frappe/model/doc';
|
||||
import { Fyo } from 'fyo';
|
||||
import Doc from 'fyo/model/doc';
|
||||
import {
|
||||
Action,
|
||||
FiltersMap,
|
||||
FormulaMap,
|
||||
ListViewSettings,
|
||||
} from 'frappe/model/types';
|
||||
} from 'fyo/model/types';
|
||||
import { PartyRole } from './types';
|
||||
|
||||
export class Party extends Doc {
|
||||
@ -29,7 +29,7 @@ export class Party extends Doc {
|
||||
schemaName: 'SalesInvoice' | 'PurchaseInvoice'
|
||||
) {
|
||||
const outstandingAmounts = (
|
||||
await this.frappe.db.getAllRaw(schemaName, {
|
||||
await this.fyo.db.getAllRaw(schemaName, {
|
||||
fields: ['outstandingAmount', 'party'],
|
||||
filters: { submitted: true },
|
||||
})
|
||||
@ -37,9 +37,9 @@ export class Party extends Doc {
|
||||
|
||||
const totalOutstanding = outstandingAmounts
|
||||
.map(({ outstandingAmount }) =>
|
||||
this.frappe.pesa(outstandingAmount as number)
|
||||
this.fyo.pesa(outstandingAmount as number)
|
||||
)
|
||||
.reduce((a, b) => a.add(b), this.frappe.pesa(0));
|
||||
.reduce((a, b) => a.add(b), this.fyo.pesa(0));
|
||||
|
||||
await this.set('outstandingAmount', totalOutstanding);
|
||||
await this.update();
|
||||
@ -57,11 +57,11 @@ export class Party extends Doc {
|
||||
accountName = 'Creditors';
|
||||
}
|
||||
|
||||
const accountExists = await this.frappe.db.exists('Account', accountName);
|
||||
const accountExists = await this.fyo.db.exists('Account', accountName);
|
||||
return accountExists ? accountName : '';
|
||||
},
|
||||
currency: async () =>
|
||||
this.frappe.singles.AccountingSettings!.currency as string,
|
||||
this.fyo.singles.AccountingSettings!.currency as string,
|
||||
addressDisplay: async () => {
|
||||
const address = this.address as string | undefined;
|
||||
if (address) {
|
||||
@ -94,14 +94,14 @@ export class Party extends Doc {
|
||||
};
|
||||
}
|
||||
|
||||
static getActions(frappe: Frappe): Action[] {
|
||||
static getActions(fyo: Fyo): Action[] {
|
||||
return [
|
||||
{
|
||||
label: frappe.t`Create Bill`,
|
||||
label: fyo.t`Create Bill`,
|
||||
condition: (doc: Doc) =>
|
||||
!doc.isNew && (doc.role as PartyRole) !== 'Customer',
|
||||
action: async (partyDoc, router) => {
|
||||
const doc = await frappe.doc.getEmptyDoc('PurchaseInvoice');
|
||||
const doc = await fyo.doc.getEmptyDoc('PurchaseInvoice');
|
||||
router.push({
|
||||
path: `/edit/PurchaseInvoice/${doc.name}`,
|
||||
query: {
|
||||
@ -115,7 +115,7 @@ export class Party extends Doc {
|
||||
},
|
||||
},
|
||||
{
|
||||
label: frappe.t`View Bills`,
|
||||
label: fyo.t`View Bills`,
|
||||
condition: (doc: Doc) =>
|
||||
!doc.isNew && (doc.role as PartyRole) !== 'Customer',
|
||||
action: async (partyDoc, router) => {
|
||||
@ -132,11 +132,11 @@ export class Party extends Doc {
|
||||
},
|
||||
},
|
||||
{
|
||||
label: frappe.t`Create Invoice`,
|
||||
label: fyo.t`Create Invoice`,
|
||||
condition: (doc: Doc) =>
|
||||
!doc.isNew && (doc.role as PartyRole) !== 'Supplier',
|
||||
action: async (partyDoc, router) => {
|
||||
const doc = await frappe.doc.getEmptyDoc('SalesInvoice');
|
||||
const doc = await fyo.doc.getEmptyDoc('SalesInvoice');
|
||||
router.push({
|
||||
path: `/edit/SalesInvoice/${doc.name}`,
|
||||
query: {
|
||||
@ -150,7 +150,7 @@ export class Party extends Doc {
|
||||
},
|
||||
},
|
||||
{
|
||||
label: frappe.t`View Invoices`,
|
||||
label: fyo.t`View Invoices`,
|
||||
condition: (doc: Doc) =>
|
||||
!doc.isNew && (doc.role as PartyRole) !== 'Supplier',
|
||||
action: async (partyDoc, router) => {
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { LedgerPosting } from 'accounting/ledgerPosting';
|
||||
import { Frappe } from 'frappe';
|
||||
import { DocValue } from 'frappe/core/types';
|
||||
import Doc from 'frappe/model/doc';
|
||||
import { Fyo } from 'fyo';
|
||||
import { DocValue } from 'fyo/core/types';
|
||||
import Doc from 'fyo/model/doc';
|
||||
import {
|
||||
Action,
|
||||
DefaultMap,
|
||||
@ -11,8 +11,8 @@ import {
|
||||
ListViewSettings,
|
||||
RequiredMap,
|
||||
ValidationMap,
|
||||
} from 'frappe/model/types';
|
||||
import { ValidationError } from 'frappe/utils/errors';
|
||||
} from 'fyo/model/types';
|
||||
import { ValidationError } from 'fyo/utils/errors';
|
||||
import { getLedgerLinkAction } from 'models/helpers';
|
||||
import Money from 'pesa/dist/types/src/money';
|
||||
import { getIsNullOrUndef } from 'utils';
|
||||
@ -50,10 +50,7 @@ export class Payment extends Doc {
|
||||
}
|
||||
|
||||
const schemaName = referenceType as string;
|
||||
const doc = await this.frappe.doc.getDoc(
|
||||
schemaName,
|
||||
referenceName as string
|
||||
);
|
||||
const doc = await this.fyo.doc.getDoc(schemaName, referenceName as string);
|
||||
|
||||
let party;
|
||||
let paymentType: PaymentType;
|
||||
@ -71,7 +68,7 @@ export class Payment extends Doc {
|
||||
}
|
||||
|
||||
updateAmountOnReferenceUpdate() {
|
||||
this.amount = this.frappe.pesa(0);
|
||||
this.amount = this.fyo.pesa(0);
|
||||
for (const paymentReference of this.for as Doc[]) {
|
||||
this.amount = (this.amount as Money).add(
|
||||
paymentReference.amount as Money
|
||||
@ -98,7 +95,7 @@ export class Payment extends Doc {
|
||||
if (this.paymentAccount !== this.account || !this.account) {
|
||||
return;
|
||||
}
|
||||
throw new this.frappe.errors.ValidationError(
|
||||
throw new this.fyo.errors.ValidationError(
|
||||
`To Account and From Account can't be the same: ${this.account}`
|
||||
);
|
||||
}
|
||||
@ -111,7 +108,7 @@ export class Payment extends Doc {
|
||||
|
||||
const referenceAmountTotal = forReferences
|
||||
.map(({ amount }) => amount as Money)
|
||||
.reduce((a, b) => a.add(b), this.frappe.pesa(0));
|
||||
.reduce((a, b) => a.add(b), this.fyo.pesa(0));
|
||||
|
||||
if (
|
||||
(this.amount as Money)
|
||||
@ -121,20 +118,20 @@ export class Payment extends Doc {
|
||||
return;
|
||||
}
|
||||
|
||||
const writeoff = this.frappe.format(this.writeoff!, 'Currency');
|
||||
const payment = this.frappe.format(this.amount!, 'Currency');
|
||||
const refAmount = this.frappe.format(referenceAmountTotal, 'Currency');
|
||||
const writeoff = this.fyo.format(this.writeoff!, 'Currency');
|
||||
const payment = this.fyo.format(this.amount!, 'Currency');
|
||||
const refAmount = this.fyo.format(referenceAmountTotal, 'Currency');
|
||||
|
||||
if ((this.writeoff as Money).gt(0)) {
|
||||
throw new ValidationError(
|
||||
this.frappe.t`Amount: ${payment} and writeoff: ${writeoff}
|
||||
this.fyo.t`Amount: ${payment} and writeoff: ${writeoff}
|
||||
is less than the total amount allocated to
|
||||
references: ${refAmount}.`
|
||||
);
|
||||
}
|
||||
|
||||
throw new ValidationError(
|
||||
this.frappe.t`Amount: ${payment} is less than the total
|
||||
this.fyo.t`Amount: ${payment} is less than the total
|
||||
amount allocated to references: ${refAmount}.`
|
||||
);
|
||||
}
|
||||
@ -144,9 +141,9 @@ export class Payment extends Doc {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!this.frappe.singles.AccountingSettings!.writeOffAccount) {
|
||||
if (!this.fyo.singles.AccountingSettings!.writeOffAccount) {
|
||||
throw new ValidationError(
|
||||
this.frappe.t`Write Off Account not set.
|
||||
this.fyo.t`Write Off Account not set.
|
||||
Please set Write Off Account in General Settings`
|
||||
);
|
||||
}
|
||||
@ -162,7 +159,7 @@ export class Payment extends Doc {
|
||||
reference: this,
|
||||
party: this.party!,
|
||||
},
|
||||
this.frappe
|
||||
this.fyo
|
||||
);
|
||||
|
||||
await entries.debit(paymentAccount as string, amount.sub(writeoff));
|
||||
@ -177,9 +174,9 @@ export class Payment extends Doc {
|
||||
reference: this,
|
||||
party: this.party!,
|
||||
},
|
||||
this.frappe
|
||||
this.fyo
|
||||
);
|
||||
const writeOffAccount = this.frappe.singles.AccountingSettings!
|
||||
const writeOffAccount = this.fyo.singles.AccountingSettings!
|
||||
.writeOffAccount as string;
|
||||
|
||||
if (this.paymentType === 'Pay') {
|
||||
@ -207,7 +204,7 @@ export class Payment extends Doc {
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
const referenceDoc = await this.frappe.doc.getDoc(
|
||||
const referenceDoc = await this.fyo.doc.getDoc(
|
||||
row.referenceType as string,
|
||||
row.referenceName as string
|
||||
);
|
||||
@ -221,17 +218,17 @@ export class Payment extends Doc {
|
||||
}
|
||||
|
||||
if (amount.lte(0) || amount.gt(outstandingAmount)) {
|
||||
let message = this.frappe.t`Payment amount: ${this.frappe.format(
|
||||
let message = this.fyo.t`Payment amount: ${this.fyo.format(
|
||||
this.amount!,
|
||||
'Currency'
|
||||
)} should be less than Outstanding amount: ${this.frappe.format(
|
||||
)} should be less than Outstanding amount: ${this.fyo.format(
|
||||
outstandingAmount,
|
||||
'Currency'
|
||||
)}.`;
|
||||
|
||||
if (amount.lte(0)) {
|
||||
const amt = this.frappe.format(this.amount!, 'Currency');
|
||||
message = this.frappe
|
||||
const amt = this.fyo.format(this.amount!, 'Currency');
|
||||
message = this.fyo
|
||||
.t`Payment amount: ${amt} should be greater than 0.`;
|
||||
}
|
||||
|
||||
@ -241,7 +238,7 @@ export class Payment extends Doc {
|
||||
const newOutstanding = outstandingAmount.sub(amount);
|
||||
await referenceDoc.set('outstandingAmount', newOutstanding);
|
||||
await referenceDoc.update();
|
||||
const party = (await this.frappe.doc.getDoc(
|
||||
const party = (await this.fyo.doc.getDoc(
|
||||
'Party',
|
||||
this.party!
|
||||
)) as Party;
|
||||
@ -269,7 +266,7 @@ export class Payment extends Doc {
|
||||
async updateReferenceOutstandingAmount() {
|
||||
await (this.for as Doc[]).forEach(
|
||||
async ({ amount, referenceType, referenceName }) => {
|
||||
const refDoc = await this.frappe.doc.getDoc(
|
||||
const refDoc = await this.fyo.doc.getDoc(
|
||||
referenceType as string,
|
||||
referenceName as string
|
||||
);
|
||||
@ -304,7 +301,7 @@ export class Payment extends Doc {
|
||||
amount: async (value: DocValue) => {
|
||||
if ((value as Money).isNegative()) {
|
||||
throw new ValidationError(
|
||||
this.frappe.t`Payment amount cannot be less than zero.`
|
||||
this.fyo.t`Payment amount cannot be less than zero.`
|
||||
);
|
||||
}
|
||||
|
||||
@ -313,13 +310,13 @@ export class Payment extends Doc {
|
||||
|
||||
if ((value as Money).gt(amount)) {
|
||||
throw new ValidationError(
|
||||
this.frappe.t`Payment amount cannot
|
||||
exceed ${this.frappe.format(amount, 'Currency')}.`
|
||||
this.fyo.t`Payment amount cannot
|
||||
exceed ${this.fyo.format(amount, 'Currency')}.`
|
||||
);
|
||||
} else if ((value as Money).isZero()) {
|
||||
throw new ValidationError(
|
||||
this.frappe.t`Payment amount cannot
|
||||
be ${this.frappe.format(value, 'Currency')}.`
|
||||
this.fyo.t`Payment amount cannot
|
||||
be ${this.fyo.format(value, 'Currency')}.`
|
||||
);
|
||||
}
|
||||
},
|
||||
@ -368,16 +365,16 @@ export class Payment extends Doc {
|
||||
},
|
||||
};
|
||||
|
||||
static getActions(frappe: Frappe): Action[] {
|
||||
return [getLedgerLinkAction(frappe)];
|
||||
static getActions(fyo: Fyo): Action[] {
|
||||
return [getLedgerLinkAction(fyo)];
|
||||
}
|
||||
|
||||
static getListViewSettings(frappe: Frappe): ListViewSettings {
|
||||
static getListViewSettings(fyo: Fyo): ListViewSettings {
|
||||
return {
|
||||
columns: [
|
||||
'party',
|
||||
{
|
||||
label: frappe.t`Status`,
|
||||
label: fyo.t`Status`,
|
||||
fieldname: 'status',
|
||||
fieldtype: 'Select',
|
||||
size: 'small',
|
||||
|
@ -1,5 +1,5 @@
|
||||
import Doc from 'frappe/model/doc';
|
||||
import { FiltersMap, FormulaMap } from 'frappe/model/types';
|
||||
import Doc from 'fyo/model/doc';
|
||||
import { FiltersMap, FormulaMap } from 'fyo/model/types';
|
||||
import Money from 'pesa/dist/types/src/money';
|
||||
|
||||
export class PaymentFor extends Doc {
|
||||
@ -15,7 +15,7 @@ export class PaymentFor extends Doc {
|
||||
return outstandingAmount;
|
||||
}
|
||||
|
||||
return this.frappe.pesa(0);
|
||||
return this.fyo.pesa(0);
|
||||
},
|
||||
};
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { LedgerPosting } from 'accounting/ledgerPosting';
|
||||
import { Frappe } from 'frappe';
|
||||
import { Action, ListViewSettings } from 'frappe/model/types';
|
||||
import { Fyo } from 'fyo';
|
||||
import { Action, ListViewSettings } from 'fyo/model/types';
|
||||
import {
|
||||
getTransactionActions,
|
||||
getTransactionStatusColumn,
|
||||
@ -17,7 +17,7 @@ export class PurchaseInvoice extends Invoice {
|
||||
reference: this,
|
||||
party: this.party,
|
||||
},
|
||||
this.frappe
|
||||
this.fyo
|
||||
);
|
||||
|
||||
await entries.credit(this.account!, this.baseGrandTotal!);
|
||||
@ -36,17 +36,17 @@ export class PurchaseInvoice extends Invoice {
|
||||
return entries;
|
||||
}
|
||||
|
||||
static getActions(frappe: Frappe): Action[] {
|
||||
return getTransactionActions('PurchaseInvoice', frappe);
|
||||
static getActions(fyo: Fyo): Action[] {
|
||||
return getTransactionActions('PurchaseInvoice', fyo);
|
||||
}
|
||||
|
||||
static getListViewSettings(frappe: Frappe): ListViewSettings {
|
||||
static getListViewSettings(fyo: Fyo): ListViewSettings {
|
||||
return {
|
||||
formRoute: (name) => `/edit/PurchaseInvoice/${name}`,
|
||||
columns: [
|
||||
'party',
|
||||
'name',
|
||||
getTransactionStatusColumn(frappe),
|
||||
getTransactionStatusColumn(fyo),
|
||||
'date',
|
||||
'grandTotal',
|
||||
'outstandingAmount',
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { LedgerPosting } from 'accounting/ledgerPosting';
|
||||
import { Frappe } from 'frappe';
|
||||
import { Action, ListViewSettings } from 'frappe/model/types';
|
||||
import { Fyo } from 'fyo';
|
||||
import { Action, ListViewSettings } from 'fyo/model/types';
|
||||
import {
|
||||
getTransactionActions,
|
||||
getTransactionStatusColumn,
|
||||
@ -17,7 +17,7 @@ export class SalesInvoice extends Invoice {
|
||||
reference: this,
|
||||
party: this.party,
|
||||
},
|
||||
this.frappe
|
||||
this.fyo
|
||||
);
|
||||
await entries.debit(this.account!, this.baseGrandTotal!);
|
||||
|
||||
@ -34,17 +34,17 @@ export class SalesInvoice extends Invoice {
|
||||
return entries;
|
||||
}
|
||||
|
||||
static getActions(frappe: Frappe): Action[] {
|
||||
return getTransactionActions('SalesInvoice', frappe);
|
||||
static getActions(fyo: Fyo): Action[] {
|
||||
return getTransactionActions('SalesInvoice', fyo);
|
||||
}
|
||||
|
||||
static getListViewSettings(frappe: Frappe): ListViewSettings {
|
||||
static getListViewSettings(fyo: Fyo): ListViewSettings {
|
||||
return {
|
||||
formRoute: (name) => `/edit/SalesInvoice/${name}`,
|
||||
columns: [
|
||||
'party',
|
||||
'name',
|
||||
getTransactionStatusColumn(frappe),
|
||||
getTransactionStatusColumn(fyo),
|
||||
'date',
|
||||
'grandTotal',
|
||||
'outstandingAmount',
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { t } from 'frappe';
|
||||
import Doc from 'frappe/model/doc';
|
||||
import { FormulaMap, ListsMap } from 'frappe/model/types';
|
||||
import { t } from 'fyo';
|
||||
import Doc from 'fyo/model/doc';
|
||||
import { FormulaMap, ListsMap } from 'fyo/model/types';
|
||||
import { DateTime } from 'luxon';
|
||||
import countryInfo from '../../../fixtures/countryInfo.json';
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
import Doc from 'frappe/model/doc';
|
||||
import { ListViewSettings } from 'frappe/model/types';
|
||||
import Doc from 'fyo/model/doc';
|
||||
import { ListViewSettings } from 'fyo/model/types';
|
||||
|
||||
export class Tax extends Doc {
|
||||
static getListViewSettings(): ListViewSettings {
|
||||
|
@ -1,5 +1,5 @@
|
||||
import Doc from 'frappe/model/doc';
|
||||
import { FormulaMap } from 'frappe/model/types';
|
||||
import Doc from 'fyo/model/doc';
|
||||
import { FormulaMap } from 'fyo/model/types';
|
||||
import Money from 'pesa/dist/types/src/money';
|
||||
|
||||
export class TaxSummary extends Doc {
|
||||
|
@ -1,13 +1,13 @@
|
||||
import { Frappe } from 'frappe';
|
||||
import Doc from 'frappe/model/doc';
|
||||
import { Action, ColumnConfig } from 'frappe/model/types';
|
||||
import { Fyo } from 'fyo';
|
||||
import Doc from 'fyo/model/doc';
|
||||
import { Action, ColumnConfig } from 'fyo/model/types';
|
||||
import Money from 'pesa/dist/types/src/money';
|
||||
import { Router } from 'vue-router';
|
||||
import { InvoiceStatus } from './types';
|
||||
|
||||
export function getLedgerLinkAction(frappe: Frappe): Action {
|
||||
export function getLedgerLinkAction(fyo: Fyo): Action {
|
||||
return {
|
||||
label: frappe.t`Ledger Entries`,
|
||||
label: fyo.t`Ledger Entries`,
|
||||
condition: (doc: Doc) => !!doc.submitted,
|
||||
action: async (doc: Doc, router: Router) => {
|
||||
router.push({
|
||||
@ -27,15 +27,15 @@ export function getLedgerLinkAction(frappe: Frappe): Action {
|
||||
|
||||
export function getTransactionActions(
|
||||
schemaName: string,
|
||||
frappe: Frappe
|
||||
fyo: Fyo
|
||||
): Action[] {
|
||||
return [
|
||||
{
|
||||
label: frappe.t`Make Payment`,
|
||||
label: fyo.t`Make Payment`,
|
||||
condition: (doc: Doc) =>
|
||||
(doc.submitted as boolean) && (doc.outstandingAmount as Money).gt(0),
|
||||
action: async function makePayment(doc: Doc) {
|
||||
const payment = await frappe.doc.getEmptyDoc('Payment');
|
||||
const payment = await fyo.doc.getEmptyDoc('Payment');
|
||||
payment.once('afterInsert', async () => {
|
||||
await payment.submit();
|
||||
});
|
||||
@ -66,26 +66,26 @@ export function getTransactionActions(
|
||||
},
|
||||
},
|
||||
{
|
||||
label: frappe.t`Print`,
|
||||
label: fyo.t`Print`,
|
||||
condition: (doc: Doc) => doc.submitted as boolean,
|
||||
action: async (doc: Doc, router: Router) => {
|
||||
router.push({ path: `/print/${doc.doctype}/${doc.name}` });
|
||||
},
|
||||
},
|
||||
getLedgerLinkAction(frappe),
|
||||
getLedgerLinkAction(fyo),
|
||||
];
|
||||
}
|
||||
|
||||
export function getTransactionStatusColumn(frappe: Frappe): ColumnConfig {
|
||||
export function getTransactionStatusColumn(fyo: Fyo): ColumnConfig {
|
||||
const statusMap = {
|
||||
Unpaid: frappe.t`Unpaid`,
|
||||
Paid: frappe.t`Paid`,
|
||||
Draft: frappe.t`Draft`,
|
||||
Cancelled: frappe.t`Cancelled`,
|
||||
Unpaid: fyo.t`Unpaid`,
|
||||
Paid: fyo.t`Paid`,
|
||||
Draft: fyo.t`Draft`,
|
||||
Cancelled: fyo.t`Cancelled`,
|
||||
};
|
||||
|
||||
return {
|
||||
label: frappe.t`Status`,
|
||||
label: fyo.t`Status`,
|
||||
fieldname: 'status',
|
||||
fieldtype: 'Select',
|
||||
render(doc: Doc) {
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { ModelMap } from 'frappe/model/types';
|
||||
import { ModelMap } from 'fyo/model/types';
|
||||
import { Account } from './baseModels/Account/Account';
|
||||
import { AccountingLedgerEntry } from './baseModels/AccountingLedgerEntry/AccountingLedgerEntry';
|
||||
import { AccountingSettings } from './baseModels/AccountingSettings/AccountingSettings';
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { FormulaMap, ListsMap } from 'frappe/model/types';
|
||||
import { FormulaMap, ListsMap } from 'fyo/model/types';
|
||||
import { Address as BaseAddress } from 'models/baseModels/Address/Address';
|
||||
import { stateCodeMap } from 'regional/in';
|
||||
import { titleCase } from 'utils';
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { HiddenMap } from 'frappe/model/types';
|
||||
import { HiddenMap } from 'fyo/model/types';
|
||||
import { Party as BaseParty } from 'models/baseModels/Party/Party';
|
||||
import { GSTType } from './types';
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
import frappe from 'frappe';
|
||||
import frappe from 'fyo';
|
||||
|
||||
export default class AccountsReceivablePayable {
|
||||
async run(reportType, { date }) {
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { unique } from 'frappe/utils';
|
||||
import { unique } from 'fyo/utils';
|
||||
import { getData } from '../FinancialStatements/FinancialStatements';
|
||||
|
||||
class BalanceSheet {
|
||||
|
@ -1,4 +1,4 @@
|
||||
import frappe, { t } from 'frappe';
|
||||
import frappe, { t } from 'fyo';
|
||||
import getCommonExportActions from '../commonExporter';
|
||||
|
||||
const periodicityMap = {
|
||||
|
@ -1,4 +1,4 @@
|
||||
import frappe from 'frappe';
|
||||
import frappe from 'fyo';
|
||||
|
||||
class BankReconciliation {
|
||||
async run(params) {
|
||||
|
@ -1,5 +1,5 @@
|
||||
import csv2json from 'csvjson-csv2json';
|
||||
import frappe from 'frappe';
|
||||
import frappe from 'fyo';
|
||||
import ReconciliationValidation from '../../src/components/ReconciliationValidation';
|
||||
|
||||
export const fileImportHandler = (file, report) => {
|
||||
|
@ -1,5 +1,5 @@
|
||||
const title = 'Bank Reconciliation';
|
||||
import { t } from 'frappe';
|
||||
import { t } from 'fyo';
|
||||
import ImportWizard from '../../src/components/ImportWizart';
|
||||
import BankReconciliationImport from './BankReconciliationImport';
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
import frappe from 'frappe';
|
||||
import frappe from 'fyo';
|
||||
import { DateTime } from 'luxon';
|
||||
import {
|
||||
getFiscalYear,
|
||||
|
@ -1,4 +1,4 @@
|
||||
import frappe from 'frappe';
|
||||
import frappe from 'fyo';
|
||||
import { DateTime } from 'luxon';
|
||||
import { convertPesaValuesToFloat } from '../../src/utils';
|
||||
|
||||
@ -185,27 +185,36 @@ function getPeriodKey(date, periodicity, fiscalYear) {
|
||||
let getKey = {
|
||||
Monthly: () => `${dateObj.monthShort} ${year}`,
|
||||
Quarterly: () => {
|
||||
const key = month < fisacalStart.month ? `${year-1} - ${year}` : `${year} - ${year+1}`;
|
||||
const key =
|
||||
month < fisacalStart.month
|
||||
? `${year - 1} - ${year}`
|
||||
: `${year} - ${year + 1}`;
|
||||
let strYear = isSplit ? key : `${year}`;
|
||||
return {
|
||||
1: `Q1 ${strYear}`,
|
||||
2: `Q2 ${strYear}`,
|
||||
3: `Q3 ${strYear}`,
|
||||
4: `Q4 ${strYear}`,
|
||||
}[quarters[month-1]];
|
||||
}[quarters[month - 1]];
|
||||
},
|
||||
'Half Yearly': () => {
|
||||
const key = month < fisacalStart.month ? `${year-1} - ${year}` : `${year} - ${year+1}`;
|
||||
const key =
|
||||
month < fisacalStart.month
|
||||
? `${year - 1} - ${year}`
|
||||
: `${year} - ${year + 1}`;
|
||||
let strYear = isSplit ? key : `${year}`;
|
||||
return {
|
||||
return {
|
||||
1: `1st Half ${strYear}`,
|
||||
2: `1st Half ${strYear}`,
|
||||
3: `2nd Half ${strYear}`,
|
||||
4: `2nd Half ${strYear}`,
|
||||
}[quarters[month-1]];
|
||||
}[quarters[month - 1]];
|
||||
},
|
||||
Yearly: () => {
|
||||
const key = month < fisacalStart.month ? `${year-1} - ${year}` : `${year} - ${year+1}`;
|
||||
const key =
|
||||
month < fisacalStart.month
|
||||
? `${year - 1} - ${year}`
|
||||
: `${year} - ${year + 1}`;
|
||||
let strYear = isSplit ? key : `${year}`;
|
||||
return `FY ${strYear}`;
|
||||
},
|
||||
@ -304,11 +313,11 @@ export async function getFiscalYear() {
|
||||
//moving the financial quarters, according to of start of fiscal year month
|
||||
let quarters = [1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4];
|
||||
let start = DateTime.fromISO(fiscalYearStart);
|
||||
quarters.unshift(...quarters.splice(13-start.month, 11));
|
||||
quarters.unshift(...quarters.splice(13 - start.month, 11));
|
||||
|
||||
//check if fiscal year ends in next year
|
||||
//check if fiscal year ends in next year
|
||||
let end = DateTime.fromISO(fiscalYearEnd);
|
||||
let isFiscalSplit = start.year - end.year ;
|
||||
let isFiscalSplit = start.year - end.year;
|
||||
|
||||
return {
|
||||
start: fiscalYearStart,
|
||||
|
@ -1,4 +1,4 @@
|
||||
import frappe from 'frappe';
|
||||
import frappe from 'fyo';
|
||||
|
||||
class GeneralLedger {
|
||||
async run(params) {
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { partyWithAvatar } from '@/utils';
|
||||
import { t } from 'frappe';
|
||||
import { t } from 'fyo';
|
||||
import getCommonExportActions from '../commonExporter';
|
||||
|
||||
let title = t`General Ledger`;
|
||||
|
@ -1,4 +1,4 @@
|
||||
import frappe from 'frappe';
|
||||
import frappe from 'fyo';
|
||||
import { stateCodeMap } from '../../accounting/gst';
|
||||
import { convertPesaValuesToFloat } from '../../src/utils';
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { t } from 'frappe';
|
||||
import { t } from 'fyo';
|
||||
import { DateTime } from 'luxon';
|
||||
import { stateCodeMap } from '../../accounting/gst';
|
||||
import { titleCase } from '../../src/utils';
|
||||
|
@ -1,5 +1,5 @@
|
||||
const title = 'GSTR 1';
|
||||
import { t } from 'frappe';
|
||||
import { t } from 'fyo';
|
||||
import { generateGstr1Csv, generateGstr1Json } from '../../accounting/gst';
|
||||
import baseConfig from './BaseViewConfig';
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
const title = 'GSTR 2';
|
||||
import { t } from 'frappe';
|
||||
import { t } from 'fyo';
|
||||
import { generateGstr2Csv } from '../../accounting/gst';
|
||||
import baseConfig from './BaseViewConfig';
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { unique } from 'frappe/utils';
|
||||
import { unique } from 'fyo/utils';
|
||||
import { getData } from '../FinancialStatements/FinancialStatements';
|
||||
|
||||
class ProfitAndLoss {
|
||||
|
@ -1,4 +1,4 @@
|
||||
import frappe, { t } from 'frappe';
|
||||
import frappe, { t } from 'fyo';
|
||||
import getCommonExportActions from '../commonExporter';
|
||||
|
||||
const title = t`Profit and Loss`;
|
||||
|
@ -1,4 +1,4 @@
|
||||
import frappe from 'frappe';
|
||||
import frappe from 'fyo';
|
||||
|
||||
class PurchaseRegister {
|
||||
async run({ fromDate, toDate, supplier }) {
|
||||
|
@ -1,5 +1,5 @@
|
||||
const title = 'Purchase Register';
|
||||
import { t } from 'frappe';
|
||||
import { t } from 'fyo';
|
||||
|
||||
export default {
|
||||
title: title,
|
||||
|
@ -1,4 +1,4 @@
|
||||
import frappe from 'frappe';
|
||||
import frappe from 'fyo';
|
||||
|
||||
class SalesRegister {
|
||||
async run({ fromDate, toDate, customer }) {
|
||||
|
@ -1,5 +1,5 @@
|
||||
const title = 'Sales Register';
|
||||
import { t } from 'frappe';
|
||||
import { t } from 'fyo';
|
||||
|
||||
export default {
|
||||
title: title,
|
||||
|
@ -1,4 +1,4 @@
|
||||
import frappe, { t } from 'frappe';
|
||||
import frappe, { t } from 'fyo';
|
||||
import getCommonExportActions from '../commonExporter';
|
||||
|
||||
const title = t`Trial Balance`;
|
||||
|
@ -1,4 +1,4 @@
|
||||
import frappe from 'frappe';
|
||||
import frappe from 'fyo';
|
||||
import telemetry from '../src/telemetry/telemetry';
|
||||
import { Verb } from '../src/telemetry/types';
|
||||
import { getSavePath, saveData, showExportInFolder } from '../src/utils';
|
||||
|
10
src/App.vue
10
src/App.vue
@ -33,14 +33,14 @@
|
||||
import WindowsTitleBar from '@/components/WindowsTitleBar';
|
||||
import config from '@/config';
|
||||
import {
|
||||
connectToLocalDatabase,
|
||||
postSetup,
|
||||
purgeCache,
|
||||
connectToLocalDatabase,
|
||||
postSetup,
|
||||
purgeCache
|
||||
} from '@/initialization';
|
||||
import { IPC_ACTIONS, IPC_MESSAGES } from 'utils/messages';
|
||||
import { ipcRenderer } from 'electron';
|
||||
import frappe from 'frappe';
|
||||
import fs from 'fs/promises';
|
||||
import frappe from 'fyo';
|
||||
import { IPC_ACTIONS, IPC_MESSAGES } from 'utils/messages';
|
||||
import TelemetryModal from './components/once/TelemetryModal.vue';
|
||||
import { showErrorDialog } from './errorHandling';
|
||||
import DatabaseSelector from './pages/DatabaseSelector';
|
||||
|
@ -1,11 +1,11 @@
|
||||
import frappe from 'frappe';
|
||||
import { DocValueMap } from 'frappe/core/types';
|
||||
import Doc from 'frappe/model/doc';
|
||||
import { isNameAutoSet } from 'frappe/model/naming';
|
||||
import frappe from 'fyo';
|
||||
import { DocValueMap } from 'fyo/core/types';
|
||||
import Doc from 'fyo/model/doc';
|
||||
import { isNameAutoSet } from 'fyo/model/naming';
|
||||
import { FieldType, FieldTypeEnum } from 'schemas/types';
|
||||
import { parseCSV } from '../utils/csvParser';
|
||||
import telemetry from '../frappe/telemetry/telemetry';
|
||||
import { Noun, Verb } from '../frappe/telemetry/types';
|
||||
import { parseCSV } from '../utils/csvParser';
|
||||
|
||||
export const importable = [
|
||||
'SalesInvoice',
|
||||
|
@ -1,13 +1,13 @@
|
||||
import { ipcRenderer } from 'electron';
|
||||
import frappe, { t } from 'frappe';
|
||||
import Doc from 'frappe/model/doc';
|
||||
import frappe, { t } from 'fyo';
|
||||
import Doc from 'fyo/model/doc';
|
||||
import {
|
||||
DuplicateEntryError,
|
||||
LinkValidationError,
|
||||
MandatoryError,
|
||||
ValidationError,
|
||||
} from 'frappe/utils/errors';
|
||||
import { ErrorLog } from 'frappe/utils/types';
|
||||
} from 'fyo/utils/errors';
|
||||
import { ErrorLog } from 'fyo/utils/types';
|
||||
import { IPC_ACTIONS, IPC_MESSAGES } from 'utils/messages';
|
||||
import telemetry from '../frappe/telemetry/telemetry';
|
||||
import config, { ConfigKeys, TelemetrySetting } from '../utils/config';
|
||||
|
@ -1,3 +1,3 @@
|
||||
import { Frappe } from 'frappe';
|
||||
import { Fyo } from 'fyo';
|
||||
|
||||
export const fyo = new Frappe({ isTest: false, isElectron: true });
|
||||
export const fyo = new Fyo({ isTest: false, isElectron: true });
|
||||
|
@ -1,11 +1,3 @@
|
||||
import Button from '@/components/Button';
|
||||
import FilterDropdown from '@/components/FilterDropdown';
|
||||
import PageHeader from '@/components/PageHeader';
|
||||
import SearchBar from '@/components/SearchBar';
|
||||
import { routeTo } from '@/utils';
|
||||
import frappe from 'frappe';
|
||||
import List from './List';
|
||||
import listConfigs from './listConfig';
|
||||
<template>
|
||||
<div class="flex flex-col">
|
||||
<PageHeader>
|
||||
@ -43,7 +35,7 @@ import FilterDropdown from '@/components/FilterDropdown';
|
||||
import PageHeader from '@/components/PageHeader';
|
||||
import SearchBar from '@/components/SearchBar';
|
||||
import { routeTo } from '@/utils';
|
||||
import frappe from 'frappe';
|
||||
import frappe from 'fyo';
|
||||
import List from './List';
|
||||
|
||||
export default {
|
||||
|
@ -60,7 +60,7 @@ import telemetry from '@/telemetry/telemetry';
|
||||
import { Verb } from '@/telemetry/types';
|
||||
import { makePDF } from '@/utils';
|
||||
import { ipcRenderer } from 'electron';
|
||||
import frappe from 'frappe';
|
||||
import frappe from 'fyo';
|
||||
import { IPC_ACTIONS } from 'utils/messages';
|
||||
|
||||
export default {
|
||||
|
@ -51,22 +51,20 @@
|
||||
</div>
|
||||
</template>
|
||||
<script>
|
||||
import { t } from 'frappe';
|
||||
import frappe from 'frappe';
|
||||
import WindowControls from '@/components/WindowControls';
|
||||
import TabGeneral from './TabGeneral.vue';
|
||||
import TabSystem from './TabSystem.vue';
|
||||
import TabInvoice from './TabInvoice.vue';
|
||||
import Button from '@/components/Button';
|
||||
import Row from '@/components/Row';
|
||||
import Icon from '@/components/Icon';
|
||||
import PageHeader from '@/components/PageHeader';
|
||||
import Row from '@/components/Row';
|
||||
import StatusBadge from '@/components/StatusBadge';
|
||||
import { callInitializeMoneyMaker } from '../../utils';
|
||||
import { showToast } from '../../utils';
|
||||
import { h, markRaw } from 'vue';
|
||||
import WindowControls from '@/components/WindowControls';
|
||||
import { ipcRenderer } from 'electron';
|
||||
import frappe, { t } from 'fyo';
|
||||
import { IPC_MESSAGES } from 'utils/messages';
|
||||
import { h, markRaw } from 'vue';
|
||||
import { callInitializeMoneyMaker, showToast } from '../../utils';
|
||||
import TabGeneral from './TabGeneral.vue';
|
||||
import TabInvoice from './TabInvoice.vue';
|
||||
import TabSystem from './TabSystem.vue';
|
||||
|
||||
export default {
|
||||
name: 'Settings',
|
||||
|
@ -13,7 +13,7 @@
|
||||
|
||||
<script>
|
||||
import TwoColumnForm from '@/components/TwoColumnForm';
|
||||
import frappe from 'frappe';
|
||||
import frappe from 'fyo';
|
||||
|
||||
export default {
|
||||
name: 'TabGeneral',
|
||||
|
@ -46,10 +46,10 @@
|
||||
</div>
|
||||
</template>
|
||||
<script>
|
||||
import frappe from 'frappe';
|
||||
import { ipcRenderer } from 'electron';
|
||||
import TwoColumnForm from '@/components/TwoColumnForm';
|
||||
import FormControl from '@/components/Controls/FormControl';
|
||||
import TwoColumnForm from '@/components/TwoColumnForm';
|
||||
import { ipcRenderer } from 'electron';
|
||||
import frappe from 'fyo';
|
||||
import { IPC_ACTIONS } from 'utils/messages';
|
||||
|
||||
export default {
|
||||
|
@ -48,7 +48,7 @@ TelemetrySetting
|
||||
import { getTelemetryOptions } from '@/telemetry/helpers';
|
||||
import telemetry from '@/telemetry/telemetry';
|
||||
import { checkForUpdates } from '@/utils';
|
||||
import frappe from 'frappe';
|
||||
import frappe from 'fyo';
|
||||
|
||||
export default {
|
||||
name: 'TabSystem',
|
||||
|
@ -97,8 +97,8 @@ import config from '@/config';
|
||||
import { connectToLocalDatabase, purgeCache } from '@/initialization';
|
||||
import { setLanguageMap, showMessageDialog } from '@/utils';
|
||||
import { ipcRenderer } from 'electron';
|
||||
import frappe from 'frappe';
|
||||
import fs from 'fs';
|
||||
import frappe from 'fyo';
|
||||
import path from 'path';
|
||||
import { IPC_MESSAGES } from 'utils/messages';
|
||||
import {
|
||||
|
@ -1,6 +1,6 @@
|
||||
import config from '@/config';
|
||||
import frappe from 'frappe';
|
||||
import { DEFAULT_LOCALE } from 'frappe/utils/consts';
|
||||
import frappe from 'fyo';
|
||||
import { DEFAULT_LOCALE } from 'fyo/utils/consts';
|
||||
import countryList from '~/fixtures/countryInfo.json';
|
||||
import importCharts from '../../../accounting/importCOA';
|
||||
import generateTaxes from '../../../models/doctype/Tax/RegionalEntries';
|
||||
|
@ -1,4 +1,4 @@
|
||||
import frappe from 'frappe';
|
||||
import { fyo } from '@/initFyo';
|
||||
|
||||
export type TaxType = 'GST' | 'IGST' | 'Exempt-GST' | 'Exempt-IGST';
|
||||
|
||||
@ -10,14 +10,14 @@ export default async function generateTaxes(country: string) {
|
||||
'Exempt-GST': [0],
|
||||
'Exempt-IGST': [0],
|
||||
};
|
||||
const newTax = await frappe.doc.getEmptyDoc('Tax');
|
||||
const newTax = await fyo.doc.getEmptyDoc('Tax');
|
||||
|
||||
for (const type of Object.keys(GSTs)) {
|
||||
for (const percent of GSTs[type as TaxType]) {
|
||||
const name = `${type}-${percent}`;
|
||||
|
||||
// Not cross checking cause hardcoded values.
|
||||
await frappe.db.delete('Tax', name);
|
||||
await fyo.db.delete('Tax', name);
|
||||
|
||||
const details = getTaxDetails(type as TaxType, percent);
|
||||
await newTax.set({ name, details });
|
||||
|
@ -1,13 +1,13 @@
|
||||
import frappe from 'frappe';
|
||||
import { ConfigKeys } from 'frappe/core/types';
|
||||
import { fyo } from '@/initFyo';
|
||||
import { ConfigKeys } from 'fyo/core/types';
|
||||
|
||||
export function incrementOpenCount() {
|
||||
let openCount = frappe.config.get(ConfigKeys.OpenCount);
|
||||
let openCount = fyo.config.get(ConfigKeys.OpenCount);
|
||||
if (typeof openCount !== 'number') {
|
||||
openCount = 1;
|
||||
} else {
|
||||
openCount += 1;
|
||||
}
|
||||
|
||||
frappe.config.set(ConfigKeys.OpenCount, openCount);
|
||||
fyo.config.set(ConfigKeys.OpenCount, openCount);
|
||||
}
|
||||
|
@ -1,39 +1,38 @@
|
||||
import { handleError } from '@/errorHandling';
|
||||
import { IPC_CHANNELS, IPC_MESSAGES } from 'utils/messages';
|
||||
import telemetry from 'frappe/telemetry/telemetry';
|
||||
import { fyo } from '@/initFyo';
|
||||
import { showToast } from '@/utils';
|
||||
import { ipcRenderer } from 'electron';
|
||||
import frappe from 'frappe';
|
||||
import { IPC_CHANNELS, IPC_MESSAGES } from 'utils/messages';
|
||||
|
||||
export default function registerIpcRendererListeners() {
|
||||
ipcRenderer.on(IPC_CHANNELS.STORE_ON_WINDOW, (event, message) => {
|
||||
Object.assign(frappe.store, message);
|
||||
Object.assign(fyo.store, message);
|
||||
});
|
||||
|
||||
ipcRenderer.on(IPC_CHANNELS.CHECKING_FOR_UPDATE, (_) => {
|
||||
showToast({ message: frappe.t`Checking for updates` });
|
||||
showToast({ message: fyo.t`Checking for updates` });
|
||||
});
|
||||
|
||||
ipcRenderer.on(IPC_CHANNELS.UPDATE_AVAILABLE, (_, version) => {
|
||||
const message = version
|
||||
? frappe.t`Version ${version} available`
|
||||
: frappe.t`New version available`;
|
||||
? fyo.t`Version ${version} available`
|
||||
: fyo.t`New version available`;
|
||||
const action = () => {
|
||||
ipcRenderer.send(IPC_MESSAGES.DOWNLOAD_UPDATE);
|
||||
showToast({ message: frappe.t`Downloading update` });
|
||||
showToast({ message: fyo.t`Downloading update` });
|
||||
};
|
||||
|
||||
showToast({
|
||||
message,
|
||||
action,
|
||||
actionText: frappe.t`Download Update`,
|
||||
actionText: fyo.t`Download Update`,
|
||||
duration: 10000,
|
||||
type: 'success',
|
||||
});
|
||||
});
|
||||
|
||||
ipcRenderer.on(IPC_CHANNELS.UPDATE_NOT_AVAILABLE, (_) => {
|
||||
showToast({ message: frappe.t`No updates available` });
|
||||
showToast({ message: fyo.t`No updates available` });
|
||||
});
|
||||
|
||||
ipcRenderer.on(IPC_CHANNELS.UPDATE_DOWNLOADED, (_) => {
|
||||
@ -41,9 +40,9 @@ export default function registerIpcRendererListeners() {
|
||||
ipcRenderer.send(IPC_MESSAGES.INSTALL_UPDATE);
|
||||
};
|
||||
showToast({
|
||||
message: frappe.t`Update downloaded`,
|
||||
message: fyo.t`Update downloaded`,
|
||||
action,
|
||||
actionText: frappe.t`Install Update`,
|
||||
actionText: fyo.t`Install Update`,
|
||||
duration: 10000,
|
||||
type: 'success',
|
||||
});
|
||||
@ -53,17 +52,17 @@ export default function registerIpcRendererListeners() {
|
||||
error.name = 'Updation Error';
|
||||
handleError(true, error);
|
||||
});
|
||||
|
||||
|
||||
document.addEventListener('visibilitychange', function () {
|
||||
const { visibilityState } = document;
|
||||
if (visibilityState === 'visible' && !telemetry.started) {
|
||||
telemetry.start();
|
||||
if (visibilityState === 'visible' && !fyo.telemetry.started) {
|
||||
fyo.telemetry.start();
|
||||
}
|
||||
|
||||
if (visibilityState !== 'hidden') {
|
||||
return;
|
||||
}
|
||||
|
||||
telemetry.stop();
|
||||
fyo.telemetry.stop();
|
||||
});
|
||||
}
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user