diff --git a/META.md b/META.md index 24b1b570..3a73a0eb 100644 --- a/META.md +++ b/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\*_ diff --git a/accounting/exchangeRate.ts b/accounting/exchangeRate.ts index e40ca95c..445af0a2 100644 --- a/accounting/exchangeRate.ts +++ b/accounting/exchangeRate.ts @@ -1,4 +1,4 @@ -import { NotFoundError } from 'frappe/utils/errors'; +import { NotFoundError } from 'fyo/utils/errors'; import { DateTime } from 'luxon'; export async function getExchangeRate({ diff --git a/accounting/gst.js b/accounting/gst.js index 3635ae5d..d4c3ed60 100644 --- a/accounting/gst.js +++ b/accounting/gst.js @@ -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'; diff --git a/accounting/importCOA.js b/accounting/importCOA.js index d55fac7c..c4315e42 100644 --- a/accounting/importCOA.js +++ b/accounting/importCOA.js @@ -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']; diff --git a/accounting/ledgerPosting.ts b/accounting/ledgerPosting.ts index 5868620b..4e2d6f38 100644 --- a/accounting/ledgerPosting.ts +++ b/accounting/ledgerPosting.ts @@ -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; } } diff --git a/accounting/types.ts b/accounting/types.ts index be5d091c..9423ef0a 100644 --- a/accounting/types.ts +++ b/accounting/types.ts @@ -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 { diff --git a/accounting/utils.js b/accounting/utils.js index 5ad2fbb9..091fd8bf 100644 --- a/accounting/utils.js +++ b/accounting/utils.js @@ -1,4 +1,4 @@ -import { t } from 'frappe'; +import { t } from 'fyo'; export const ledgerLink = { label: t`Ledger Entries`, diff --git a/backend/database/core.ts b/backend/database/core.ts index 14dab13f..9e5f8e94 100644 --- a/backend/database/core.ts +++ b/backend/database/core.ts @@ -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, diff --git a/fixtures/standardCOA.js b/fixtures/standardCOA.js index ecb85c85..2a1c481b 100644 --- a/fixtures/standardCOA.js +++ b/fixtures/standardCOA.js @@ -1,4 +1,4 @@ -import { t } from 'frappe'; +import { t } from 'fyo'; export default { [t`Application of Funds (Assets)`]: { diff --git a/frappe/telemetry/helpers.ts b/frappe/telemetry/helpers.ts deleted file mode 100644 index 6c0fa15f..00000000 --- a/frappe/telemetry/helpers.ts +++ /dev/null @@ -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 { - 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`, -}); diff --git a/frappe/README.md b/fyo/README.md similarity index 100% rename from frappe/README.md rename to fyo/README.md diff --git a/frappe/core/authHandler.ts b/fyo/core/authHandler.ts similarity index 87% rename from frappe/core/authHandler.ts rename to fyo/core/authHandler.ts index 5bd6f1fb..c0bb4e94 100644 --- a/frappe/core/authHandler.ts +++ b/fyo/core/authHandler.ts @@ -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); } } diff --git a/frappe/core/converter.ts b/fyo/core/converter.ts similarity index 93% rename from frappe/core/converter.ts rename to fyo/core/converter.ts index 0d70c042..41135f3b 100644 --- a/frappe/core/converter.ts +++ b/fyo/core/converter.ts @@ -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 ); } } diff --git a/frappe/core/dbHandler.ts b/fyo/core/dbHandler.ts similarity index 93% rename from frappe/core/dbHandler.ts rename to fyo/core/dbHandler.ts index 7014e486..d1c0cd2b 100644 --- a/frappe/core/dbHandler.ts +++ b/fyo/core/dbHandler.ts @@ -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 = {}; fieldValueMap: Record> = {}; - 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 = []; 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, diff --git a/frappe/core/docHandler.ts b/fyo/core/docHandler.ts similarity index 86% rename from frappe/core/docHandler.ts rename to fyo/core/docHandler.ts index 8db4e1e2..84b4e395 100644 --- a/frappe/core/docHandler.ts +++ b/fyo/core/docHandler.ts @@ -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 = 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; diff --git a/frappe/core/types.ts b/fyo/core/types.ts similarity index 97% rename from frappe/core/types.ts rename to fyo/core/types.ts index 8b7ae7ba..4f22790d 100644 --- a/frappe/core/types.ts +++ b/fyo/core/types.ts @@ -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'; diff --git a/frappe/demux/auth.ts b/fyo/demux/auth.ts similarity index 100% rename from frappe/demux/auth.ts rename to fyo/demux/auth.ts diff --git a/frappe/demux/config.ts b/fyo/demux/config.ts similarity index 100% rename from frappe/demux/config.ts rename to fyo/demux/config.ts diff --git a/frappe/demux/db.ts b/fyo/demux/db.ts similarity index 97% rename from frappe/demux/db.ts rename to fyo/demux/db.ts index 9cb5eae9..d583c9ca 100644 --- a/frappe/demux/db.ts +++ b/fyo/demux/db.ts @@ -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'; diff --git a/frappe/index.ts b/fyo/index.ts similarity index 99% rename from frappe/index.ts rename to fyo/index.ts index c14d705f..eef20690 100644 --- a/frappe/index.ts +++ b/fyo/index.ts @@ -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; diff --git a/frappe/model/doc.ts b/fyo/model/doc.ts similarity index 89% rename from frappe/model/doc.ts rename to fyo/model/doc.ts index 1451c4ca..4e2f4f21 100644 --- a/frappe/model/doc.ts +++ b/fyo/model/doc.ts @@ -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 { name?: string; schema: Readonly; - frappe: Frappe; + fyo: Fyo; fieldMap: Record; /** @@ -66,9 +66,9 @@ export default class Doc extends Observable { 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 { 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 { } 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 { } 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 { 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 { } 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 { } 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 { 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 { 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 { 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 { (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 { } 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 { 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 { 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 { 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 { 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 { } 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 { return ''; } - return this.frappe.doc.getCachedValue(schemaName, name, fieldname); + return this.fyo.doc.getCachedValue(schemaName, name, fieldname); } async duplicate(shouldInsert: boolean = true): Promise { @@ -706,7 +703,7 @@ export default class Doc extends Observable { 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 { 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 []; } } diff --git a/frappe/model/helpers.ts b/fyo/model/helpers.ts similarity index 93% rename from frappe/model/helpers.ts rename to fyo/model/helpers.ts index 4cb73afd..ffd4d6c2 100644 --- a/frappe/model/helpers.ts +++ b/fyo/model/helpers.ts @@ -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; diff --git a/frappe/model/naming.ts b/fyo/model/naming.ts similarity index 64% rename from frappe/model/naming.ts rename to fyo/model/naming.ts index 9e3f399e..75c86279 100644 --- a/frappe/model/naming.ts +++ b/fyo/model/naming.ts @@ -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, diff --git a/frappe/model/types.ts b/fyo/model/types.ts similarity index 92% rename from frappe/model/types.ts rename to fyo/model/types.ts index 33e5032a..55c8a5d6 100644 --- a/frappe/model/types.ts +++ b/fyo/model/types.ts @@ -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; -export type EmptyMessageFunction = (doc: Doc, frappe: Frappe) => string; +export type EmptyMessageFunction = (doc: Doc, fyo: Fyo) => string; export type EmptyMessageMap = Record; export type ListFunction = (doc?: Doc) => string[]; diff --git a/frappe/model/validationFunction.ts b/fyo/model/validationFunction.ts similarity index 88% rename from frappe/model/validationFunction.ts rename to fyo/model/validationFunction.ts index 91703d32..3676eb25 100644 --- a/frappe/model/validationFunction.ts +++ b/fyo/model/validationFunction.ts @@ -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) { diff --git a/frappe/models/NumberSeries.ts b/fyo/models/NumberSeries.ts similarity index 91% rename from frappe/models/NumberSeries.ts rename to fyo/models/NumberSeries.ts index 351ed8b1..60088c92 100644 --- a/frappe/models/NumberSeries.ts +++ b/fyo/models/NumberSeries.ts @@ -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 { diff --git a/frappe/models/SystemSettings.ts b/fyo/models/SystemSettings.ts similarity index 59% rename from frappe/models/SystemSettings.ts rename to fyo/models/SystemSettings.ts index dd164bdc..0f7f9dfa 100644 --- a/frappe/models/SystemSettings.ts +++ b/fyo/models/SystemSettings.ts @@ -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 = { diff --git a/frappe/models/index.ts b/fyo/models/index.ts similarity index 78% rename from frappe/models/index.ts rename to fyo/models/index.ts index e19cb795..e67582aa 100644 --- a/frappe/models/index.ts +++ b/fyo/models/index.ts @@ -1,4 +1,4 @@ -import { ModelMap } from 'frappe/model/types'; +import { ModelMap } from 'fyo/model/types'; import NumberSeries from './NumberSeries'; import SystemSettings from './SystemSettings'; diff --git a/fyo/telemetry/helpers.ts b/fyo/telemetry/helpers.ts new file mode 100644 index 00000000..93a8ef96 --- /dev/null +++ b/fyo/telemetry/helpers.ts @@ -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 { + 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`, +}); diff --git a/frappe/telemetry/telemetry.ts b/fyo/telemetry/telemetry.ts similarity index 85% rename from frappe/telemetry/telemetry.ts rename to fyo/telemetry/telemetry.ts index 7fe517c4..5c8e958e 100644 --- a/frappe/telemetry/telemetry.ts +++ b/fyo/telemetry/telemetry.ts @@ -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 = {}; #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; diff --git a/frappe/telemetry/types.ts b/fyo/telemetry/types.ts similarity index 100% rename from frappe/telemetry/types.ts rename to fyo/telemetry/types.ts diff --git a/frappe/tests/helpers.ts b/fyo/tests/helpers.ts similarity index 100% rename from frappe/tests/helpers.ts rename to fyo/tests/helpers.ts diff --git a/frappe/tests/testFrappe.spec.ts b/fyo/tests/testFyo.spec.ts similarity index 61% rename from frappe/tests/testFrappe.spec.ts rename to fyo/tests/testFyo.spec.ts index 156035a2..bee00aaf 100644 --- a/frappe/tests/testFrappe.spec.ts +++ b/fyo/tests/testFyo.spec.ts @@ -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; }); }); diff --git a/frappe/utils/cacheManager.ts b/fyo/utils/cacheManager.ts similarity index 100% rename from frappe/utils/cacheManager.ts rename to fyo/utils/cacheManager.ts diff --git a/frappe/utils/consts.ts b/fyo/utils/consts.ts similarity index 100% rename from frappe/utils/consts.ts rename to fyo/utils/consts.ts diff --git a/frappe/utils/errors.ts b/fyo/utils/errors.ts similarity index 100% rename from frappe/utils/errors.ts rename to fyo/utils/errors.ts diff --git a/frappe/utils/format.ts b/fyo/utils/format.ts similarity index 69% rename from frappe/utils/format.ts rename to fyo/utils/format.ts index 6fefcfc7..9395e737 100644 --- a/frappe/utils/format.ts +++ b/fyo/utils/format.ts @@ -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 { diff --git a/frappe/utils/index.ts b/fyo/utils/index.ts similarity index 100% rename from frappe/utils/index.ts rename to fyo/utils/index.ts diff --git a/frappe/utils/observable.ts b/fyo/utils/observable.ts similarity index 100% rename from frappe/utils/observable.ts rename to fyo/utils/observable.ts diff --git a/frappe/utils/translation.ts b/fyo/utils/translation.ts similarity index 100% rename from frappe/utils/translation.ts rename to fyo/utils/translation.ts diff --git a/frappe/utils/types.ts b/fyo/utils/types.ts similarity index 100% rename from frappe/utils/types.ts rename to fyo/utils/types.ts diff --git a/models/README.md b/models/README.md index f7bc95b1..6abad063 100644 --- a/models/README.md +++ b/models/README.md @@ -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('...')`._ diff --git a/models/baseModels/Account/Account.ts b/models/baseModels/Account/Account.ts index 49fb9366..5a64b6ab 100644 --- a/models/baseModels/Account/Account.ts +++ b/models/baseModels/Account/Account.ts @@ -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 { - const accountingSettings = await frappe.doc.getSingle( + const accountingSettings = await fyo.doc.getSingle( 'AccountingSettings' ); return accountingSettings.companyName as string; diff --git a/models/baseModels/AccountingLedgerEntry/AccountingLedgerEntry.ts b/models/baseModels/AccountingLedgerEntry/AccountingLedgerEntry.ts index 00851407..2bd32b1c 100644 --- a/models/baseModels/AccountingLedgerEntry/AccountingLedgerEntry.ts +++ b/models/baseModels/AccountingLedgerEntry/AccountingLedgerEntry.ts @@ -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 { diff --git a/models/baseModels/AccountingSettings/AccountingSettings.ts b/models/baseModels/AccountingSettings/AccountingSettings.ts index f6128e45..ea2c4562 100644 --- a/models/baseModels/AccountingSettings/AccountingSettings.ts +++ b/models/baseModels/AccountingSettings/AccountingSettings.ts @@ -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 { diff --git a/models/baseModels/Address/Address.ts b/models/baseModels/Address/Address.ts index 6c26d116..3829c309 100644 --- a/models/baseModels/Address/Address.ts +++ b/models/baseModels/Address/Address.ts @@ -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`; }, }; } diff --git a/models/baseModels/Invoice/Invoice.ts b/models/baseModels/Invoice/Invoice.ts index 30ef65a7..8eed94b4 100644 --- a/models/baseModels/Invoice/Invoice.ts +++ b/models/baseModels/Invoice/Invoice.ts @@ -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!), diff --git a/models/baseModels/InvoiceItem/InvoiceItem.ts b/models/baseModels/InvoiceItem/InvoiceItem.ts index ceee496f..5b6aa581 100644 --- a/models/baseModels/InvoiceItem/InvoiceItem.ts +++ b/models/baseModels/InvoiceItem/InvoiceItem.ts @@ -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.` diff --git a/models/baseModels/Item/Item.ts b/models/baseModels/Item/Item.ts index 02d899f0..891d8205 100644 --- a/models/baseModels/Item/Item.ts +++ b/models/baseModels/Item/Item.ts @@ -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, diff --git a/models/baseModels/JournalEntry/JournalEntry.ts b/models/baseModels/JournalEntry/JournalEntry.ts index be27b387..04621747 100644 --- a/models/baseModels/JournalEntry/JournalEntry.ts +++ b/models/baseModels/JournalEntry/JournalEntry.ts @@ -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) { diff --git a/models/baseModels/JournalEntryAccount/JournalEntryAccount.ts b/models/baseModels/JournalEntryAccount/JournalEntryAccount.ts index dd947885..0768a0ba 100644 --- a/models/baseModels/JournalEntryAccount/JournalEntryAccount.ts +++ b/models/baseModels/JournalEntryAccount/JournalEntryAccount.ts @@ -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; diff --git a/models/baseModels/Party/Party.ts b/models/baseModels/Party/Party.ts index 2c89d3c2..3507f4b4 100644 --- a/models/baseModels/Party/Party.ts +++ b/models/baseModels/Party/Party.ts @@ -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) => { diff --git a/models/baseModels/Payment/Payment.ts b/models/baseModels/Payment/Payment.ts index fd9412f3..e8f89dfa 100644 --- a/models/baseModels/Payment/Payment.ts +++ b/models/baseModels/Payment/Payment.ts @@ -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', diff --git a/models/baseModels/PaymentFor/PaymentFor.ts b/models/baseModels/PaymentFor/PaymentFor.ts index 01ebc445..eb0730ee 100644 --- a/models/baseModels/PaymentFor/PaymentFor.ts +++ b/models/baseModels/PaymentFor/PaymentFor.ts @@ -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); }, }; diff --git a/models/baseModels/PurchaseInvoice/PurchaseInvoice.ts b/models/baseModels/PurchaseInvoice/PurchaseInvoice.ts index 1a68794b..1cc09a10 100644 --- a/models/baseModels/PurchaseInvoice/PurchaseInvoice.ts +++ b/models/baseModels/PurchaseInvoice/PurchaseInvoice.ts @@ -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', diff --git a/models/baseModels/SalesInvoice/SalesInvoice.ts b/models/baseModels/SalesInvoice/SalesInvoice.ts index 260150ff..4c7d66b7 100644 --- a/models/baseModels/SalesInvoice/SalesInvoice.ts +++ b/models/baseModels/SalesInvoice/SalesInvoice.ts @@ -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', diff --git a/models/baseModels/SetupWizard/SetupWizard.ts b/models/baseModels/SetupWizard/SetupWizard.ts index baf1ef70..17e7fcbe 100644 --- a/models/baseModels/SetupWizard/SetupWizard.ts +++ b/models/baseModels/SetupWizard/SetupWizard.ts @@ -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'; diff --git a/models/baseModels/Tax/Tax.ts b/models/baseModels/Tax/Tax.ts index 40dad8bb..4f125a2f 100644 --- a/models/baseModels/Tax/Tax.ts +++ b/models/baseModels/Tax/Tax.ts @@ -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 { diff --git a/models/baseModels/TaxSummary/TaxSummary.ts b/models/baseModels/TaxSummary/TaxSummary.ts index 7e0cf01d..86e9dc4a 100644 --- a/models/baseModels/TaxSummary/TaxSummary.ts +++ b/models/baseModels/TaxSummary/TaxSummary.ts @@ -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 { diff --git a/models/helpers.ts b/models/helpers.ts index 5f226b1d..d3315fed 100644 --- a/models/helpers.ts +++ b/models/helpers.ts @@ -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) { diff --git a/models/index.ts b/models/index.ts index e129ebad..139ae4a4 100644 --- a/models/index.ts +++ b/models/index.ts @@ -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'; diff --git a/models/regionalModels/in/Address.ts b/models/regionalModels/in/Address.ts index 5b554654..6a708f14 100644 --- a/models/regionalModels/in/Address.ts +++ b/models/regionalModels/in/Address.ts @@ -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'; diff --git a/models/regionalModels/in/Party.ts b/models/regionalModels/in/Party.ts index ac49b067..c35d6f0c 100644 --- a/models/regionalModels/in/Party.ts +++ b/models/regionalModels/in/Party.ts @@ -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'; diff --git a/reports/AccountsReceivablePayable/AccountsReceivablePayable.js b/reports/AccountsReceivablePayable/AccountsReceivablePayable.js index 56d14889..11658ac0 100644 --- a/reports/AccountsReceivablePayable/AccountsReceivablePayable.js +++ b/reports/AccountsReceivablePayable/AccountsReceivablePayable.js @@ -1,4 +1,4 @@ -import frappe from 'frappe'; +import frappe from 'fyo'; export default class AccountsReceivablePayable { async run(reportType, { date }) { diff --git a/reports/BalanceSheet/BalanceSheet.js b/reports/BalanceSheet/BalanceSheet.js index cd862d06..9daf6430 100644 --- a/reports/BalanceSheet/BalanceSheet.js +++ b/reports/BalanceSheet/BalanceSheet.js @@ -1,4 +1,4 @@ -import { unique } from 'frappe/utils'; +import { unique } from 'fyo/utils'; import { getData } from '../FinancialStatements/FinancialStatements'; class BalanceSheet { diff --git a/reports/BalanceSheet/viewConfig.js b/reports/BalanceSheet/viewConfig.js index 14cb96b6..a0a6b669 100644 --- a/reports/BalanceSheet/viewConfig.js +++ b/reports/BalanceSheet/viewConfig.js @@ -1,4 +1,4 @@ -import frappe, { t } from 'frappe'; +import frappe, { t } from 'fyo'; import getCommonExportActions from '../commonExporter'; const periodicityMap = { diff --git a/reports/BankReconciliation/BankReconciliation.js b/reports/BankReconciliation/BankReconciliation.js index 76cebb09..7e8bf17f 100644 --- a/reports/BankReconciliation/BankReconciliation.js +++ b/reports/BankReconciliation/BankReconciliation.js @@ -1,4 +1,4 @@ -import frappe from 'frappe'; +import frappe from 'fyo'; class BankReconciliation { async run(params) { diff --git a/reports/BankReconciliation/BankReconciliationImport.js b/reports/BankReconciliation/BankReconciliationImport.js index f6534ff6..4af6c2b1 100644 --- a/reports/BankReconciliation/BankReconciliationImport.js +++ b/reports/BankReconciliation/BankReconciliationImport.js @@ -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) => { diff --git a/reports/BankReconciliation/viewConfig.js b/reports/BankReconciliation/viewConfig.js index 9505136a..9524cc66 100644 --- a/reports/BankReconciliation/viewConfig.js +++ b/reports/BankReconciliation/viewConfig.js @@ -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'; diff --git a/reports/Cashflow/Cashflow.js b/reports/Cashflow/Cashflow.js index 3c0bd08f..0fed2e6d 100644 --- a/reports/Cashflow/Cashflow.js +++ b/reports/Cashflow/Cashflow.js @@ -1,4 +1,4 @@ -import frappe from 'frappe'; +import frappe from 'fyo'; import { DateTime } from 'luxon'; import { getFiscalYear, diff --git a/reports/FinancialStatements/FinancialStatements.js b/reports/FinancialStatements/FinancialStatements.js index 332f6319..2e382a63 100644 --- a/reports/FinancialStatements/FinancialStatements.js +++ b/reports/FinancialStatements/FinancialStatements.js @@ -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, diff --git a/reports/GeneralLedger/GeneralLedger.js b/reports/GeneralLedger/GeneralLedger.js index b3bbce23..a1cdbbec 100644 --- a/reports/GeneralLedger/GeneralLedger.js +++ b/reports/GeneralLedger/GeneralLedger.js @@ -1,4 +1,4 @@ -import frappe from 'frappe'; +import frappe from 'fyo'; class GeneralLedger { async run(params) { diff --git a/reports/GeneralLedger/viewConfig.js b/reports/GeneralLedger/viewConfig.js index 87cd442b..db67cff1 100644 --- a/reports/GeneralLedger/viewConfig.js +++ b/reports/GeneralLedger/viewConfig.js @@ -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`; diff --git a/reports/GoodsAndServiceTax/BaseGSTR.js b/reports/GoodsAndServiceTax/BaseGSTR.js index ce039da7..0577584e 100644 --- a/reports/GoodsAndServiceTax/BaseGSTR.js +++ b/reports/GoodsAndServiceTax/BaseGSTR.js @@ -1,4 +1,4 @@ -import frappe from 'frappe'; +import frappe from 'fyo'; import { stateCodeMap } from '../../accounting/gst'; import { convertPesaValuesToFloat } from '../../src/utils'; diff --git a/reports/GoodsAndServiceTax/BaseViewConfig.js b/reports/GoodsAndServiceTax/BaseViewConfig.js index 54e297e9..3171e755 100644 --- a/reports/GoodsAndServiceTax/BaseViewConfig.js +++ b/reports/GoodsAndServiceTax/BaseViewConfig.js @@ -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'; diff --git a/reports/GoodsAndServiceTax/GSTR1View.js b/reports/GoodsAndServiceTax/GSTR1View.js index 0fc54224..68f5d671 100644 --- a/reports/GoodsAndServiceTax/GSTR1View.js +++ b/reports/GoodsAndServiceTax/GSTR1View.js @@ -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'; diff --git a/reports/GoodsAndServiceTax/GSTR2View.js b/reports/GoodsAndServiceTax/GSTR2View.js index 62ce9a67..92bb314e 100644 --- a/reports/GoodsAndServiceTax/GSTR2View.js +++ b/reports/GoodsAndServiceTax/GSTR2View.js @@ -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'; diff --git a/reports/ProfitAndLoss/ProfitAndLoss.js b/reports/ProfitAndLoss/ProfitAndLoss.js index 558d02b3..06999f4b 100644 --- a/reports/ProfitAndLoss/ProfitAndLoss.js +++ b/reports/ProfitAndLoss/ProfitAndLoss.js @@ -1,4 +1,4 @@ -import { unique } from 'frappe/utils'; +import { unique } from 'fyo/utils'; import { getData } from '../FinancialStatements/FinancialStatements'; class ProfitAndLoss { diff --git a/reports/ProfitAndLoss/viewConfig.js b/reports/ProfitAndLoss/viewConfig.js index 7be22ccb..654aeb47 100644 --- a/reports/ProfitAndLoss/viewConfig.js +++ b/reports/ProfitAndLoss/viewConfig.js @@ -1,4 +1,4 @@ -import frappe, { t } from 'frappe'; +import frappe, { t } from 'fyo'; import getCommonExportActions from '../commonExporter'; const title = t`Profit and Loss`; diff --git a/reports/PurchaseRegister/PurchaseRegister.js b/reports/PurchaseRegister/PurchaseRegister.js index af9b60d9..8d1c9f1a 100644 --- a/reports/PurchaseRegister/PurchaseRegister.js +++ b/reports/PurchaseRegister/PurchaseRegister.js @@ -1,4 +1,4 @@ -import frappe from 'frappe'; +import frappe from 'fyo'; class PurchaseRegister { async run({ fromDate, toDate, supplier }) { diff --git a/reports/PurchaseRegister/viewConfig.js b/reports/PurchaseRegister/viewConfig.js index 7617bd90..2434667e 100644 --- a/reports/PurchaseRegister/viewConfig.js +++ b/reports/PurchaseRegister/viewConfig.js @@ -1,5 +1,5 @@ const title = 'Purchase Register'; -import { t } from 'frappe'; +import { t } from 'fyo'; export default { title: title, diff --git a/reports/SalesRegister/SalesRegister.js b/reports/SalesRegister/SalesRegister.js index 0c93eabf..18b3d203 100644 --- a/reports/SalesRegister/SalesRegister.js +++ b/reports/SalesRegister/SalesRegister.js @@ -1,4 +1,4 @@ -import frappe from 'frappe'; +import frappe from 'fyo'; class SalesRegister { async run({ fromDate, toDate, customer }) { diff --git a/reports/SalesRegister/viewConfig.js b/reports/SalesRegister/viewConfig.js index 366f11a7..2036ff8b 100644 --- a/reports/SalesRegister/viewConfig.js +++ b/reports/SalesRegister/viewConfig.js @@ -1,5 +1,5 @@ const title = 'Sales Register'; -import { t } from 'frappe'; +import { t } from 'fyo'; export default { title: title, diff --git a/reports/TrialBalance/viewConfig.js b/reports/TrialBalance/viewConfig.js index 6b7bf7cf..3ab25e2e 100644 --- a/reports/TrialBalance/viewConfig.js +++ b/reports/TrialBalance/viewConfig.js @@ -1,4 +1,4 @@ -import frappe, { t } from 'frappe'; +import frappe, { t } from 'fyo'; import getCommonExportActions from '../commonExporter'; const title = t`Trial Balance`; diff --git a/reports/commonExporter.js b/reports/commonExporter.js index ee0d1f8a..5c19a827 100644 --- a/reports/commonExporter.js +++ b/reports/commonExporter.js @@ -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'; diff --git a/src/App.vue b/src/App.vue index 285cbbf2..84986313 100644 --- a/src/App.vue +++ b/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'; diff --git a/src/dataImport.ts b/src/dataImport.ts index f1cd86fd..99400962 100644 --- a/src/dataImport.ts +++ b/src/dataImport.ts @@ -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', diff --git a/src/errorHandling.ts b/src/errorHandling.ts index a463f40e..dbfda00c 100644 --- a/src/errorHandling.ts +++ b/src/errorHandling.ts @@ -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'; diff --git a/src/initFyo.ts b/src/initFyo.ts index 917b157f..a7d7f126 100644 --- a/src/initFyo.ts +++ b/src/initFyo.ts @@ -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 }); diff --git a/src/pages/ListView/ListView.vue b/src/pages/ListView/ListView.vue index d42210dd..6622ca4e 100644 --- a/src/pages/ListView/ListView.vue +++ b/src/pages/ListView/ListView.vue @@ -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';