diff --git a/fyo/core/docHandler.ts b/fyo/core/docHandler.ts index a0478558..17a6fae9 100644 --- a/fyo/core/docHandler.ts +++ b/fyo/core/docHandler.ts @@ -133,15 +133,6 @@ export class DocHandler { return doc; } - getModel(schemaName: string): typeof Doc { - const Model = this.models[schemaName]; - if (Model === undefined) { - return Doc; - } - - return Model; - } - async getSingle(schemaName: string) { return await this.getDoc(schemaName, schemaName); } @@ -169,13 +160,17 @@ export class DocHandler { schema?: Schema, Model?: typeof Doc ): Doc { - Model ??= this.getModel(schemaName); + if (!this.models[schemaName] && Model) { + this.models[schemaName] = Model; + } + + Model ??= this.models[schemaName]; schema ??= this.fyo.schemaMap[schemaName]; if (schema === undefined) { throw new Error(`Schema not found for ${schemaName}`); } - const doc = new Model(schema, data, this.fyo); + const doc = new Model!(schema, data, this.fyo); doc.setDefaults(); return doc; } diff --git a/fyo/model/types.ts b/fyo/model/types.ts index ca5e4e9f..8150f7af 100644 --- a/fyo/model/types.ts +++ b/fyo/model/types.ts @@ -31,9 +31,9 @@ export type FormulaMap = Record; export type DefaultMap = Record; export type ValidationMap = Record; export type RequiredMap = Record; -export type CurrenciesMap = Record; -export type HiddenMap = Record