From 31b1eed124da1bf4f7caba0d3031658fa2d411bc Mon Sep 17 00:00:00 2001 From: 18alantom <2.alan.tom@gmail.com> Date: Tue, 25 Jul 2023 11:40:31 +0530 Subject: [PATCH] fix: append imported modules to head - refactor doc.getDoc to doc.get - refactor doc.getNewDoc to doc.new --- dummy/index.ts | 22 +++++------ fyo/core/docHandler.ts | 6 +-- fyo/index.ts | 4 +- fyo/model/doc.ts | 6 +-- fyo/model/naming.ts | 6 +-- fyo/tests/testFyo.spec.ts | 2 +- models/Transactional/LedgerPosting.ts | 4 +- models/Transactional/Transactional.ts | 2 +- models/baseModels/Account/Account.ts | 2 +- .../AccountingLedgerEntry.ts | 2 +- models/baseModels/Invoice/Invoice.ts | 16 ++++---- models/baseModels/InvoiceItem/InvoiceItem.ts | 9 ++--- models/baseModels/Item/Item.ts | 4 +- models/baseModels/Party/Party.ts | 4 +- models/baseModels/Payment/Payment.ts | 12 +++--- models/baseModels/tests/testPriceList.spec.ts | 8 ++-- models/inventory/StockManager.ts | 2 +- models/inventory/StockMovement.ts | 2 +- models/inventory/StockMovementItem.ts | 5 +-- models/inventory/StockTransfer.ts | 8 ++-- models/inventory/StockTransferItem.ts | 5 +-- models/inventory/helpers.ts | 6 +-- models/inventory/tests/helpers.ts | 6 +-- models/inventory/tests/testBatches.spec.ts | 6 +-- models/inventory/tests/testInventory.spec.ts | 6 +-- .../inventory/tests/testSerialNumbers.spec.ts | 10 ++--- .../inventory/tests/testStockMovement.spec.ts | 6 +-- .../inventory/tests/testStockTransfer.spec.ts | 38 +++++++++---------- reports/GoodsAndServiceTax/BaseGSTR.ts | 4 +- src/App.vue | 4 +- src/components/Controls/DynamicLink.vue | 2 +- src/components/Controls/Link.vue | 2 +- src/components/Sidebar.vue | 2 +- src/importer.ts | 2 +- src/pages/ChartOfAccounts.vue | 4 +- src/pages/Dashboard/UnpaidInvoices.vue | 2 +- src/pages/GetStarted.vue | 8 ++-- src/pages/ListView/ListView.vue | 2 +- src/pages/Plugin/Plugin.vue | 4 +- src/pages/PrintView/PrintView.vue | 8 ++-- src/pages/QuickEditForm.vue | 2 +- src/regional/in/in.ts | 2 +- src/setup/createCOA.ts | 2 +- src/setup/setupInstance.ts | 10 ++--- src/utils/initialization.ts | 10 ++--- src/utils/misc.ts | 8 +--- src/utils/printTemplates.ts | 4 +- src/utils/search.ts | 2 +- src/utils/ui.ts | 6 +-- 49 files changed, 142 insertions(+), 157 deletions(-) diff --git a/dummy/index.ts b/dummy/index.ts index e7827bb5..bbe8a9f0 100644 --- a/dummy/index.ts +++ b/dummy/index.ts @@ -62,8 +62,8 @@ export async function setupDummyInstance( } async function setOtherSettings(fyo: Fyo) { - const doc = await fyo.doc.getDoc(ModelNameEnum.PrintSettings); - const address = fyo.doc.getNewDoc(ModelNameEnum.Address); + const doc = await fyo.doc.get(ModelNameEnum.PrintSettings); + const address = fyo.doc.new(ModelNameEnum.Address); await address.setAndSync({ addressLine1: '1st Column, Fitzgerald Bridge', city: 'Pune', @@ -82,7 +82,7 @@ async function setOtherSettings(fyo: Fyo) { address: address.name, }); - const acc = await fyo.doc.getDoc(ModelNameEnum.AccountingSettings); + const acc = await fyo.doc.get(ModelNameEnum.AccountingSettings); await acc.setAndSync({ gstin: '27LIN180000A1Z5', }); @@ -129,7 +129,7 @@ async function getJournalEntries(fyo: Fyo, salesInvoices: SalesInvoice[]) { const date = DateTime.fromJSDate(lastInv).minus({ months: 6 }).toJSDate(); // Bank Entry - let doc = fyo.doc.getNewDoc( + let doc = fyo.doc.new( ModelNameEnum.JournalEntry, { date, @@ -151,7 +151,7 @@ async function getJournalEntries(fyo: Fyo, salesInvoices: SalesInvoice[]) { entries.push(doc); // Cash Entry - doc = fyo.doc.getNewDoc( + doc = fyo.doc.new( ModelNameEnum.JournalEntry, { date, @@ -183,7 +183,7 @@ async function getPayments(fyo: Fyo, invoices: Invoice[]) { continue; } - const doc = fyo.doc.getNewDoc(ModelNameEnum.Payment, {}, false) as Payment; + const doc = fyo.doc.new(ModelNameEnum.Payment, {}, false) as Payment; doc.party = invoice.party as string; doc.paymentType = invoice.isSales ? 'Receive' : 'Pay'; doc.paymentMethod = 'Cash'; @@ -260,7 +260,7 @@ async function getSalesInvoices( ); const customer = sample(customers); - const doc = fyo.doc.getNewDoc( + const doc = fyo.doc.new( ModelNameEnum.SalesInvoice, { date, @@ -405,7 +405,7 @@ async function getSalesPurchaseInvoices( * For each supplier create a Purchase Invoice */ for (const supplier in supplierGrouped) { - const doc = fyo.doc.getNewDoc( + const doc = fyo.doc.new( ModelNameEnum.PurchaseInvoice, { date, @@ -461,7 +461,7 @@ async function getNonSalesPurchaseInvoices( continue; } - const doc = fyo.doc.getNewDoc( + const doc = fyo.doc.new( ModelNameEnum.PurchaseInvoice, { date, @@ -506,14 +506,14 @@ async function generateStaticEntries(fyo: Fyo) { async function generateItems(fyo: Fyo) { for (const item of items) { - const doc = fyo.doc.getNewDoc('Item', item, false); + const doc = fyo.doc.new('Item', item, false); await doc.sync(); } } async function generateParties(fyo: Fyo) { for (const party of parties) { - const doc = fyo.doc.getNewDoc('Party', party, false); + const doc = fyo.doc.new('Party', party, false); await doc.sync(); } } diff --git a/fyo/core/docHandler.ts b/fyo/core/docHandler.ts index 908f39f6..7e08cfc6 100644 --- a/fyo/core/docHandler.ts +++ b/fyo/core/docHandler.ts @@ -51,7 +51,7 @@ export class DocHandler { * Doc Operations */ - async getDoc( + async get( schemaName: string, name?: string, options = { skipDocumentCache: false } @@ -73,14 +73,14 @@ export class DocHandler { return doc; } - doc = this.getNewDoc(schemaName, { name }, false); + doc = this.new(schemaName, { name }, false); await doc.load(); this.#addToCache(doc); return doc; } - getNewDoc( + new( schemaName: string, data: DocValueMap | RawValueMap = {}, cacheDoc = true, diff --git a/fyo/index.ts b/fyo/index.ts index 472ad595..9e1860b4 100644 --- a/fyo/index.ts +++ b/fyo/index.ts @@ -116,7 +116,7 @@ export class Fyo { this.doc.registerModels(models); this.doc.registerModels(regionalModels); - await this.doc.getDoc('SystemSettings'); + await this.doc.get('SystemSettings'); this._initialized = true; } @@ -190,7 +190,7 @@ export class Fyo { let doc: Doc; let value: DocValue | Doc[]; try { - doc = await this.doc.getDoc(schemaName, name); + doc = await this.doc.get(schemaName, name); value = doc.get(fieldname); } catch (err) { value = undefined; diff --git a/fyo/model/doc.ts b/fyo/model/doc.ts index f9f5e2bb..27c98a2d 100644 --- a/fyo/model/doc.ts +++ b/fyo/model/doc.ts @@ -469,7 +469,7 @@ export class Doc extends Observable { } const childSchemaName = (this.fieldMap[fieldname] as TargetField).target; - const childDoc = this.fyo.doc.getNewDoc( + const childDoc = this.fyo.doc.new( childSchemaName, docValueMap, false, @@ -667,7 +667,7 @@ export class Doc extends Observable { } async _loadLinkDoc(fieldname: string, schemaName: string, name: string) { - this.links![fieldname] = await this.fyo.doc.getDoc(schemaName, name); + this.links![fieldname] = await this.fyo.doc.get(schemaName, name); } getLink(fieldname: string): Doc | null { @@ -1037,7 +1037,7 @@ export class Doc extends Observable { updateMap ) as RawValueMap; - return this.fyo.doc.getNewDoc(this.schemaName, rawUpdateMap, true); + return this.fyo.doc.new(this.schemaName, rawUpdateMap, true); } /** diff --git a/fyo/model/naming.ts b/fyo/model/naming.ts index e3be3e99..3b8bdad4 100644 --- a/fyo/model/naming.ts +++ b/fyo/model/naming.ts @@ -70,7 +70,7 @@ export async function getSeriesNext( let series: NumberSeries; try { - series = (await fyo.doc.getDoc('NumberSeries', prefix)) as NumberSeries; + series = (await fyo.doc.get('NumberSeries', prefix)) as NumberSeries; } catch (e) { const { statusCode } = e as BaseError; if (!statusCode || statusCode !== 404) { @@ -78,7 +78,7 @@ export async function getSeriesNext( } await createNumberSeries(prefix, schemaName, DEFAULT_SERIES_START, fyo); - series = (await fyo.doc.getDoc('NumberSeries', prefix)) as NumberSeries; + series = (await fyo.doc.get('NumberSeries', prefix)) as NumberSeries; } return await series.next(schemaName); @@ -95,7 +95,7 @@ export async function createNumberSeries( return; } - const series = fyo.doc.getNewDoc('NumberSeries', { + const series = fyo.doc.new('NumberSeries', { name: prefix, start, referenceType, diff --git a/fyo/tests/testFyo.spec.ts b/fyo/tests/testFyo.spec.ts index 6c4208f7..1519baa5 100644 --- a/fyo/tests/testFyo.spec.ts +++ b/fyo/tests/testFyo.spec.ts @@ -28,7 +28,7 @@ test('Fyo Docs', async (t) => { continue; } - const doc = fyo.doc.getNewDoc(schemaName); + const doc = fyo.doc.new(schemaName); t.equal(doc.schemaName, schemaName, `equal schemaNames: ${schemaName}`); } diff --git a/models/Transactional/LedgerPosting.ts b/models/Transactional/LedgerPosting.ts index 1af62596..3b49f0b1 100644 --- a/models/Transactional/LedgerPosting.ts +++ b/models/Transactional/LedgerPosting.ts @@ -90,7 +90,7 @@ export class LedgerPosting { return map[account]; } - const ledgerEntry = this.fyo.doc.getNewDoc( + const ledgerEntry = this.fyo.doc.new( ModelNameEnum.AccountingLedgerEntry, { account: account, @@ -162,7 +162,7 @@ export class LedgerPosting { })) as { name: string }[]; for (const { name } of data) { - const doc = (await this.fyo.doc.getDoc( + const doc = (await this.fyo.doc.get( 'AccountingLedgerEntry', name )) as AccountingLedgerEntry; diff --git a/models/Transactional/Transactional.ts b/models/Transactional/Transactional.ts index 76337a5d..6f9538b8 100644 --- a/models/Transactional/Transactional.ts +++ b/models/Transactional/Transactional.ts @@ -88,7 +88,7 @@ export abstract class Transactional extends Doc { )) as { name: string }[]; for (const { name } of ledgerEntryIds) { - const ledgerEntryDoc = await this.fyo.doc.getDoc( + const ledgerEntryDoc = await this.fyo.doc.get( ModelNameEnum.AccountingLedgerEntry, name ); diff --git a/models/baseModels/Account/Account.ts b/models/baseModels/Account/Account.ts index ffc502f5..a3841162 100644 --- a/models/baseModels/Account/Account.ts +++ b/models/baseModels/Account/Account.ts @@ -73,7 +73,7 @@ export class Account extends Doc { return { parentField: 'parentAccount', async getRootLabel(): Promise { - const accountingSettings = await fyo.doc.getDoc('AccountingSettings'); + const accountingSettings = await fyo.doc.get('AccountingSettings'); return accountingSettings.companyName as string; }, }; diff --git a/models/baseModels/AccountingLedgerEntry/AccountingLedgerEntry.ts b/models/baseModels/AccountingLedgerEntry/AccountingLedgerEntry.ts index 0518f30d..8e5173f8 100644 --- a/models/baseModels/AccountingLedgerEntry/AccountingLedgerEntry.ts +++ b/models/baseModels/AccountingLedgerEntry/AccountingLedgerEntry.ts @@ -19,7 +19,7 @@ export class AccountingLedgerEntry extends Doc { } await this.set('reverted', true); - const revertedEntry = this.fyo.doc.getNewDoc( + const revertedEntry = this.fyo.doc.new( ModelNameEnum.AccountingLedgerEntry, { account: this.account, diff --git a/models/baseModels/Invoice/Invoice.ts b/models/baseModels/Invoice/Invoice.ts index 917a1e4d..6401c7b1 100644 --- a/models/baseModels/Invoice/Invoice.ts +++ b/models/baseModels/Invoice/Invoice.ts @@ -143,7 +143,7 @@ export abstract class Invoice extends Transactional { outstandingAmount: this.baseGrandTotal!, }); - const party = (await this.fyo.doc.getDoc('Party', this.party)) as Party; + const party = (await this.fyo.doc.get('Party', this.party)) as Party; await party.updateOutstandingAmount(); if (this.makeAutoPayment && this.autoPaymentAccount) { @@ -170,7 +170,7 @@ export abstract class Invoice extends Transactional { async _cancelPayments() { const paymentIds = await this.getPaymentIds(); for (const paymentId of paymentIds) { - const paymentDoc = (await this.fyo.doc.getDoc( + const paymentDoc = (await this.fyo.doc.get( 'Payment', paymentId )) as Payment; @@ -179,7 +179,7 @@ export abstract class Invoice extends Transactional { } async _updatePartyOutStanding() { - const partyDoc = (await this.fyo.doc.getDoc( + const partyDoc = (await this.fyo.doc.get( ModelNameEnum.Party, this.party )) as Party; @@ -191,7 +191,7 @@ export abstract class Invoice extends Transactional { await super.afterDelete(); const paymentIds = await this.getPaymentIds(); for (const name of paymentIds) { - const paymentDoc = await this.fyo.doc.getDoc(ModelNameEnum.Payment, name); + const paymentDoc = await this.fyo.doc.get(ModelNameEnum.Payment, name); await paymentDoc.delete(); } } @@ -290,7 +290,7 @@ export abstract class Invoice extends Transactional { async getTax(tax: string) { if (!this._taxes[tax]) { - this._taxes[tax] = await this.fyo.doc.getDoc('Tax', tax); + this._taxes[tax] = await this.fyo.doc.get('Tax', tax); } return this._taxes[tax]; @@ -616,7 +616,7 @@ export abstract class Invoice extends Transactional { data[autoPaymentAccount] = this.autoPaymentAccount; } - return this.fyo.doc.getNewDoc(ModelNameEnum.Payment, data) as Payment; + return this.fyo.doc.new(ModelNameEnum.Payment, data) as Payment; } async getStockTransfer(isAuto = false): Promise { @@ -658,7 +658,7 @@ export abstract class Invoice extends Transactional { return null; } - const transfer = this.fyo.doc.getNewDoc(schemaName, data) as StockTransfer; + const transfer = this.fyo.doc.new(schemaName, data) as StockTransfer; for (const row of this.items ?? []) { if (!row.item) { continue; @@ -733,7 +733,7 @@ export abstract class Invoice extends Transactional { const transfers = await this._getLinkedStockTransferNames(true); for (const { name } of transfers) { - const st = await this.fyo.doc.getDoc(schemaName, name); + const st = await this.fyo.doc.get(schemaName, name); await st.delete(); } } diff --git a/models/baseModels/InvoiceItem/InvoiceItem.ts b/models/baseModels/InvoiceItem/InvoiceItem.ts index a01c5dd0..36872561 100644 --- a/models/baseModels/InvoiceItem/InvoiceItem.ts +++ b/models/baseModels/InvoiceItem/InvoiceItem.ts @@ -203,10 +203,7 @@ export abstract class InvoiceItem extends Doc { return this.quantity as number; } - const itemDoc = await this.fyo.doc.getDoc( - ModelNameEnum.Item, - this.item - ); + const itemDoc = await this.fyo.doc.get(ModelNameEnum.Item, this.item); const unitDoc = itemDoc.getLink('uom'); let quantity: number = this.quantity ?? 1; @@ -372,7 +369,7 @@ export abstract class InvoiceItem extends Doc { return this.quantity; } - const refdoc = (await this.fyo.doc.getDoc( + const refdoc = (await this.fyo.doc.get( stockTransferSchemaName, backReference )) as StockTransfer; @@ -554,7 +551,7 @@ async function getItemRateFromPriceList( return; } - const priceList = await doc.fyo.doc.getDoc( + const priceList = await doc.fyo.doc.get( ModelNameEnum.PriceList, priceListName ); diff --git a/models/baseModels/Item/Item.ts b/models/baseModels/Item/Item.ts index 351bf5b5..9422c249 100644 --- a/models/baseModels/Item/Item.ts +++ b/models/baseModels/Item/Item.ts @@ -85,7 +85,7 @@ export class Item extends Doc { label: fyo.t`Sales Invoice`, condition: (doc) => !doc.notInserted && doc.for !== 'Purchases', action: async (doc, router) => { - const invoice = fyo.doc.getNewDoc('SalesInvoice'); + const invoice = fyo.doc.new('SalesInvoice'); await invoice.append('items', { item: doc.name as string, rate: doc.rate as Money, @@ -99,7 +99,7 @@ export class Item extends Doc { label: fyo.t`Purchase Invoice`, condition: (doc) => !doc.notInserted && doc.for !== 'Sales', action: async (doc, router) => { - const invoice = fyo.doc.getNewDoc('PurchaseInvoice'); + const invoice = fyo.doc.new('PurchaseInvoice'); await invoice.append('items', { item: doc.name as string, rate: doc.rate as Money, diff --git a/models/baseModels/Party/Party.ts b/models/baseModels/Party/Party.ts index c2a29634..be5dfdcc 100644 --- a/models/baseModels/Party/Party.ts +++ b/models/baseModels/Party/Party.ts @@ -132,7 +132,7 @@ export class Party extends Doc { condition: (doc: Doc) => !doc.notInserted && (doc.role as PartyRole) !== 'Customer', action: async (partyDoc, router) => { - const doc = fyo.doc.getNewDoc('PurchaseInvoice', { + const doc = fyo.doc.new('PurchaseInvoice', { party: partyDoc.name, account: partyDoc.defaultAccount as string, }); @@ -165,7 +165,7 @@ export class Party extends Doc { condition: (doc: Doc) => !doc.notInserted && (doc.role as PartyRole) !== 'Supplier', action: async (partyDoc, router) => { - const doc = fyo.doc.getNewDoc('SalesInvoice', { + const doc = fyo.doc.new('SalesInvoice', { party: partyDoc.name, account: partyDoc.defaultAccount as string, }); diff --git a/models/baseModels/Payment/Payment.ts b/models/baseModels/Payment/Payment.ts index 073ca608..51210a71 100644 --- a/models/baseModels/Payment/Payment.ts +++ b/models/baseModels/Payment/Payment.ts @@ -65,7 +65,7 @@ export class Payment extends Transactional { } const schemaName = referenceType as string; - const doc = (await this.fyo.doc.getDoc( + const doc = (await this.fyo.doc.get( schemaName, referenceName as string )) as Invoice; @@ -114,7 +114,7 @@ export class Payment extends Transactional { const referenceName = childDoc.referenceName; const referenceType = childDoc.referenceType; - const refDoc = (await this.fyo.doc.getDoc( + const refDoc = (await this.fyo.doc.get( childDoc.referenceType!, childDoc.referenceName )) as Invoice; @@ -294,7 +294,7 @@ export class Payment extends Transactional { async validateReferenceOutstanding() { let outstandingAmount = this.fyo.pesa(0); for (const row of this.for ?? []) { - const referenceDoc = (await this.fyo.doc.getDoc( + const referenceDoc = (await this.fyo.doc.get( row.referenceType as string, row.referenceName as string )) as Invoice; @@ -334,7 +334,7 @@ export class Payment extends Transactional { async updateReferenceDocOutstanding() { for (const row of this.for ?? []) { - const referenceDoc = await this.fyo.doc.getDoc( + const referenceDoc = await this.fyo.doc.get( row.referenceType!, row.referenceName ); @@ -357,7 +357,7 @@ export class Payment extends Transactional { async _revertReferenceOutstanding() { for (const ref of this.for ?? []) { - const refDoc = await this.fyo.doc.getDoc( + const refDoc = await this.fyo.doc.get( ref.referenceType!, ref.referenceName ); @@ -371,7 +371,7 @@ export class Payment extends Transactional { } async updatePartyOutstanding() { - const partyDoc = (await this.fyo.doc.getDoc( + const partyDoc = (await this.fyo.doc.get( ModelNameEnum.Party, this.party )) as Party; diff --git a/models/baseModels/tests/testPriceList.spec.ts b/models/baseModels/tests/testPriceList.spec.ts index 91515ab9..6bac763f 100644 --- a/models/baseModels/tests/testPriceList.spec.ts +++ b/models/baseModels/tests/testPriceList.spec.ts @@ -42,13 +42,13 @@ test('Price List: create dummy item, party, price lists', async (t) => { // Create Items for (const { name, rate } of Object.values(itemMap)) { const item = getItem(name, rate, false); - await fyo.doc.getNewDoc(ModelNameEnum.Item, item).sync(); + await fyo.doc.new(ModelNameEnum.Item, item).sync(); t.ok(await fyo.db.exists(ModelNameEnum.Item, name), `Item: ${name} exists`); } // Create Parties for (const { name, email } of Object.values(partyMap)) { - await fyo.doc.getNewDoc(ModelNameEnum.Party, { name, email }).sync(); + await fyo.doc.new(ModelNameEnum.Party, { name, email }).sync(); t.ok( await fyo.db.exists(ModelNameEnum.Party, name), `Party: ${name} exists` @@ -56,7 +56,7 @@ test('Price List: create dummy item, party, price lists', async (t) => { } for (const priceListItem of Object.values(priceListMap)) { - await fyo.doc.getNewDoc(ModelNameEnum.PriceList, priceListItem).sync(); + await fyo.doc.new(ModelNameEnum.PriceList, priceListItem).sync(); t.ok( await fyo.db.exists(ModelNameEnum.PriceList, priceListItem.name), `Price List: ${priceListItem.name} exists` @@ -67,7 +67,7 @@ test('Price List: create dummy item, party, price lists', async (t) => { }); test('Check if InvoiceItem rate fetched from PriceList', async (t) => { - const sinv = fyo.doc.getNewDoc(ModelNameEnum.SalesInvoice, { + const sinv = fyo.doc.new(ModelNameEnum.SalesInvoice, { date: new Date('2023-01-01'), party: partyMap.partyOne.name, }) as SalesInvoice; diff --git a/models/inventory/StockManager.ts b/models/inventory/StockManager.ts index 16302bc6..07ae5bfc 100644 --- a/models/inventory/StockManager.ts +++ b/models/inventory/StockManager.ts @@ -309,7 +309,7 @@ class StockManagerItem { quantity: number, serialNumber?: string ): StockLedgerEntry { - return this.fyo.doc.getNewDoc(ModelNameEnum.StockLedgerEntry, { + return this.fyo.doc.new(ModelNameEnum.StockLedgerEntry, { date: this.date, item: this.item, rate: this.rate, diff --git a/models/inventory/StockMovement.ts b/models/inventory/StockMovement.ts index cd24b54b..ca9bf52f 100644 --- a/models/inventory/StockMovement.ts +++ b/models/inventory/StockMovement.ts @@ -156,7 +156,7 @@ async function validateSerialNumberStatus(doc: StockMovement) { continue; } - const snDoc = await doc.fyo.doc.getDoc( + const snDoc = await doc.fyo.doc.get( ModelNameEnum.SerialNumber, serialNumber ); diff --git a/models/inventory/StockMovementItem.ts b/models/inventory/StockMovementItem.ts index 613ce79f..73fa552b 100644 --- a/models/inventory/StockMovementItem.ts +++ b/models/inventory/StockMovementItem.ts @@ -142,10 +142,7 @@ export class StockMovementItem extends TransferItem { return this.quantity as number; } - const itemDoc = await this.fyo.doc.getDoc( - ModelNameEnum.Item, - this.item - ); + const itemDoc = await this.fyo.doc.get(ModelNameEnum.Item, this.item); const unitDoc = itemDoc.getLink('uom'); let quantity: number = this.quantity ?? 1; diff --git a/models/inventory/StockTransfer.ts b/models/inventory/StockTransfer.ts index 6cee6b0e..e1e7ad74 100644 --- a/models/inventory/StockTransfer.ts +++ b/models/inventory/StockTransfer.ts @@ -205,7 +205,7 @@ export abstract class StockTransfer extends Transfer { ? ModelNameEnum.SalesInvoice : ModelNameEnum.PurchaseInvoice; - const invoice = (await this.fyo.doc.getDoc( + const invoice = (await this.fyo.doc.get( schemaName, this.backReference )) as Invoice; @@ -296,7 +296,7 @@ export abstract class StockTransfer extends Transfer { return; } - const brDoc = await this.fyo.doc.getDoc(target, backReference); + const brDoc = await this.fyo.doc.get(target, backReference); if (!(brDoc instanceof Invoice)) { return; } @@ -338,7 +338,7 @@ export abstract class StockTransfer extends Transfer { backReference: this.name, }; - const invoice = this.fyo.doc.getNewDoc(schemaName, data) as Invoice; + const invoice = this.fyo.doc.new(schemaName, data) as Invoice; for (const row of this.items ?? []) { if (!row.item) { continue; @@ -386,7 +386,7 @@ async function validateSerialNumberStatus(doc: StockTransfer) { continue; } - const snDoc = await doc.fyo.doc.getDoc( + const snDoc = await doc.fyo.doc.get( ModelNameEnum.SerialNumber, serialNumber ); diff --git a/models/inventory/StockTransferItem.ts b/models/inventory/StockTransferItem.ts index 2a60f906..0f822d34 100644 --- a/models/inventory/StockTransferItem.ts +++ b/models/inventory/StockTransferItem.ts @@ -87,10 +87,7 @@ export class StockTransferItem extends TransferItem { return this.quantity as number; } - const itemDoc = await this.fyo.doc.getDoc( - ModelNameEnum.Item, - this.item - ); + const itemDoc = await this.fyo.doc.get(ModelNameEnum.Item, this.item); const unitDoc = itemDoc.getLink('uom'); let quantity: number = this.quantity ?? 1; diff --git a/models/inventory/helpers.ts b/models/inventory/helpers.ts index b39db8bf..5fcaed3f 100644 --- a/models/inventory/helpers.ts +++ b/models/inventory/helpers.ts @@ -130,7 +130,7 @@ async function validateItemRowSerialNumber( continue; } - const snDoc = await row.fyo.doc.getDoc( + const snDoc = await row.fyo.doc.get( ModelNameEnum.SerialNumber, serialNumber ); @@ -208,7 +208,7 @@ export async function createSerialNumbers(doc: Transfer) { continue; } - const snDoc = doc.fyo.doc.getNewDoc(ModelNameEnum.SerialNumber, { + const snDoc = doc.fyo.doc.new(ModelNameEnum.SerialNumber, { name: serialNumber, item, }); @@ -262,7 +262,7 @@ async function updateSerialNumberStatus( fyo: Fyo ) { for (const name of getSerialNumbers(serialNumber)) { - const doc = await fyo.doc.getDoc(ModelNameEnum.SerialNumber, name); + const doc = await fyo.doc.get(ModelNameEnum.SerialNumber, name); await doc.setAndSync('status', status); } } diff --git a/models/inventory/tests/helpers.ts b/models/inventory/tests/helpers.ts index b473370a..163d9087 100644 --- a/models/inventory/tests/helpers.ts +++ b/models/inventory/tests/helpers.ts @@ -53,7 +53,7 @@ export function getBatch( manufactureDate: Date, fyo: Fyo ): Batch { - const doc = fyo.doc.getNewDoc(schemaName, { + const doc = fyo.doc.new(schemaName, { batch, expiryDate, manufactureDate, @@ -68,7 +68,7 @@ export async function getStockTransfer( transfers: TransferTwo[], fyo: Fyo ): Promise { - const doc = fyo.doc.getNewDoc(schemaName, { party, date }) as StockTransfer; + const doc = fyo.doc.new(schemaName, { party, date }) as StockTransfer; for (const { item, location, quantity, rate } of transfers) { await doc.append('items', { item, location, quantity, rate }); } @@ -81,7 +81,7 @@ export async function getStockMovement( transfers: Transfer[], fyo: Fyo ): Promise { - const doc = fyo.doc.getNewDoc(ModelNameEnum.StockMovement, { + const doc = fyo.doc.new(ModelNameEnum.StockMovement, { movementType, date, }) as StockMovement; diff --git a/models/inventory/tests/testBatches.spec.ts b/models/inventory/tests/testBatches.spec.ts index 0bd2038b..ad4e71e8 100644 --- a/models/inventory/tests/testBatches.spec.ts +++ b/models/inventory/tests/testBatches.spec.ts @@ -44,17 +44,17 @@ test('create dummy items, locations & batches', async (t) => { // Create Items for (const { name, rate } of Object.values(itemMap)) { const item = getItem(name, rate, true); - await fyo.doc.getNewDoc(ModelNameEnum.Item, item).sync(); + await fyo.doc.new(ModelNameEnum.Item, item).sync(); } // Create Locations for (const name of Object.values(locationMap)) { - await fyo.doc.getNewDoc(ModelNameEnum.Location, { name }).sync(); + await fyo.doc.new(ModelNameEnum.Location, { name }).sync(); } // Create Batches for (const batch of Object.values(batchMap)) { - const doc = fyo.doc.getNewDoc(ModelNameEnum.Batch, batch); + const doc = fyo.doc.new(ModelNameEnum.Batch, batch); await doc.sync(); const exists = await fyo.db.exists(ModelNameEnum.Batch, batch.name); diff --git a/models/inventory/tests/testInventory.spec.ts b/models/inventory/tests/testInventory.spec.ts index cfa6ddc9..1f911efc 100644 --- a/models/inventory/tests/testInventory.spec.ts +++ b/models/inventory/tests/testInventory.spec.ts @@ -37,13 +37,13 @@ test('create dummy items & locations', async (t) => { // Create Items for (const { name, rate } of Object.values(itemMap)) { const item = getItem(name, rate); - await fyo.doc.getNewDoc(ModelNameEnum.Item, item).sync(); + await fyo.doc.new(ModelNameEnum.Item, item).sync(); t.ok(await fyo.db.exists(ModelNameEnum.Item, name), `${name} exists`); } // Create Locations for (const name of Object.values(locationMap)) { - await fyo.doc.getNewDoc(ModelNameEnum.Location, { name }).sync(); + await fyo.doc.new(ModelNameEnum.Location, { name }).sync(); t.ok(await fyo.db.exists(ModelNameEnum.Location, name), `${name} exists`); } }); @@ -180,7 +180,7 @@ test('cancel stock movement', async (t) => { for (const { name } of names) { const slesBefore = await getSLEs(name, ModelNameEnum.StockMovement, fyo); - const doc = (await fyo.doc.getDoc( + const doc = (await fyo.doc.get( ModelNameEnum.StockMovement, name )) as StockMovement; diff --git a/models/inventory/tests/testSerialNumbers.spec.ts b/models/inventory/tests/testSerialNumbers.spec.ts index f3ec8635..3e26a1f4 100644 --- a/models/inventory/tests/testSerialNumbers.spec.ts +++ b/models/inventory/tests/testSerialNumbers.spec.ts @@ -52,16 +52,16 @@ test('create dummy items, locations, party & serialNumbers', async (t) => { // Create Items for (const { name, rate } of Object.values(itemMap)) { const item = getItem(name, rate, false, true); - await fyo.doc.getNewDoc(ModelNameEnum.Item, item).sync(); + await fyo.doc.new(ModelNameEnum.Item, item).sync(); } // Create Locations for (const name of Object.values(locationMap)) { - await fyo.doc.getNewDoc(ModelNameEnum.Location, { name }).sync(); + await fyo.doc.new(ModelNameEnum.Location, { name }).sync(); } // Create Party - await fyo.doc.getNewDoc(ModelNameEnum.Party, partyMap.partyOne).sync(); + await fyo.doc.new(ModelNameEnum.Party, partyMap.partyOne).sync(); t.ok( await fyo.db.exists(ModelNameEnum.Party, partyMap.partyOne.name), @@ -70,7 +70,7 @@ test('create dummy items, locations, party & serialNumbers', async (t) => { // Create SerialNumbers for (const serialNumber of Object.values(serialNumberMap)) { - const doc = fyo.doc.getNewDoc(ModelNameEnum.SerialNumber, serialNumber); + const doc = fyo.doc.new(ModelNameEnum.SerialNumber, serialNumber); await doc.sync(); const status = await fyo.getValue( @@ -358,7 +358,7 @@ test('Material Receipt, auto creation of Serial Number', async (t) => { await (await doc.sync()).submit(); for (const sn of serialNumbers) { await assertDoesNotThrow(async () => { - const sndoc = await fyo.doc.getDoc(ModelNameEnum.SerialNumber, sn); + const sndoc = await fyo.doc.get(ModelNameEnum.SerialNumber, sn); t.equal(sndoc.status, 'Active', `Serial Number ${sn} updated to Active`); }, `SerialNumber ${sn} exists`); } diff --git a/models/inventory/tests/testStockMovement.spec.ts b/models/inventory/tests/testStockMovement.spec.ts index 6c39f92c..40053c4f 100644 --- a/models/inventory/tests/testStockMovement.spec.ts +++ b/models/inventory/tests/testStockMovement.spec.ts @@ -24,7 +24,7 @@ test('check store and create test items', async (t) => { const exists: boolean[] = []; for (const item of items) { - await fyo.doc.getNewDoc('Item', item).sync(); + await fyo.doc.new('Item', item).sync(); exists.push(await fyo.db.exists('Item', item.name)); } @@ -32,7 +32,7 @@ test('check store and create test items', async (t) => { }); test('Stock Movement, Material Receipt', async (t) => { - const sm = fyo.doc.getNewDoc(ModelNameEnum.StockMovement); + const sm = fyo.doc.new(ModelNameEnum.StockMovement); await sm.set({ date: new Date('2022-01-01'), @@ -74,7 +74,7 @@ test('Stock Movement, Material Receipt', async (t) => { }); test('Stock Movement, Manufacture', async (t) => { - const sm = fyo.doc.getNewDoc(ModelNameEnum.StockMovement) as StockMovement; + const sm = fyo.doc.new(ModelNameEnum.StockMovement) as StockMovement; await sm.set({ date: new Date('2022-01-02'), diff --git a/models/inventory/tests/testStockTransfer.spec.ts b/models/inventory/tests/testStockTransfer.spec.ts index 0229e1ab..fb7de99e 100644 --- a/models/inventory/tests/testStockTransfer.spec.ts +++ b/models/inventory/tests/testStockTransfer.spec.ts @@ -32,7 +32,7 @@ const testDocs = { test('insert test docs', async (t) => { for (const schemaName in testDocs) { for (const name in testDocs[schemaName]) { - await fyo.doc.getNewDoc(schemaName, testDocs[schemaName][name]).sync(); + await fyo.doc.new(schemaName, testDocs[schemaName][name]).sync(); } } @@ -45,7 +45,7 @@ test('insert test docs', async (t) => { }); test('inventory settings', async (t) => { - const doc = (await fyo.doc.getDoc( + const doc = (await fyo.doc.get( ModelNameEnum.InventorySettings )) as InventorySettings; @@ -211,7 +211,7 @@ test('Stock Transfer, invalid cancellation', async (t) => { )[0] ?? {}; t.ok(name?.startsWith('PREC-')); - const doc = await fyo.doc.getDoc(ModelNameEnum.PurchaseReceipt, name); + const doc = await fyo.doc.get(ModelNameEnum.PurchaseReceipt, name); await assertThrows(async () => await doc.cancel()); t.equal(await fyo.db.getStockQuantity(item, location), 5, 'stock unchanged'); t.equal( @@ -232,7 +232,7 @@ test('Shipment, cancel and delete', async (t) => { )[0] ?? {}; t.ok(name?.startsWith('SHPM-'), 'number series matches'); - const doc = await fyo.doc.getDoc(ModelNameEnum.Shipment, name); + const doc = await fyo.doc.get(ModelNameEnum.Shipment, name); t.ok(doc.isSubmitted, `doc ${name} is submitted`); await assertDoesNotThrow(async () => await doc.cancel()); t.ok(doc.isCancelled), `doc is cancelled`; @@ -266,7 +266,7 @@ test('Purchase Receipt, cancel and delete', async (t) => { )[0] ?? {}; t.ok(name?.startsWith('PREC-'), 'number series matches'); - const doc = await fyo.doc.getDoc(ModelNameEnum.PurchaseReceipt, name); + const doc = await fyo.doc.get(ModelNameEnum.PurchaseReceipt, name); t.ok(doc.isSubmitted, `doc ${name} is submitted`); await assertDoesNotThrow(async () => await doc.cancel()); t.ok(doc.isCancelled), `doc is cancelled`; @@ -292,7 +292,7 @@ test('Purchase Receipt, cancel and delete', async (t) => { test('Purchase Invoice then Purchase Receipt', async (t) => { const rate = testDocs.Item[item].rate as number; const quantity = 3; - const pinv = fyo.doc.getNewDoc(ModelNameEnum.PurchaseInvoice) as Invoice; + const pinv = fyo.doc.new(ModelNameEnum.PurchaseInvoice) as Invoice; const date = new Date('2022-01-04'); await pinv.set({ @@ -329,7 +329,7 @@ test('Purchase Invoice then Purchase Receipt', async (t) => { }); test('Back Ref Purchase Receipt cancel', async (t) => { - const prec = (await fyo.doc.getDoc( + const prec = (await fyo.doc.get( ModelNameEnum.PurchaseReceipt, 'PREC-1002' )) as StockTransfer; @@ -339,7 +339,7 @@ test('Back Ref Purchase Receipt cancel', async (t) => { await prec.cancel(); }); - const pinv = (await fyo.doc.getDoc( + const pinv = (await fyo.doc.get( ModelNameEnum.PurchaseInvoice, 'PINV-1001' )) as Invoice; @@ -353,7 +353,7 @@ test('Back Ref Purchase Receipt cancel', async (t) => { }); test('Cancel Purchase Invoice after Purchase Receipt is created', async (t) => { - const pinv = (await fyo.doc.getDoc( + const pinv = (await fyo.doc.get( ModelNameEnum.PurchaseInvoice, 'PINV-1001' )) as Invoice; @@ -384,7 +384,7 @@ test('Cancel Purchase Invoice after Purchase Receipt is created', async (t) => { test('Sales Invoice then partial Shipment', async (t) => { const rate = testDocs.Item[item].rate as number; - const sinv = fyo.doc.getNewDoc(ModelNameEnum.SalesInvoice) as Invoice; + const sinv = fyo.doc.new(ModelNameEnum.SalesInvoice) as Invoice; await sinv.set({ party, @@ -423,7 +423,7 @@ test('Sales Invoice then partial Shipment', async (t) => { }); test('Sales Invoice then another Shipment', async (t) => { - const sinv = (await fyo.doc.getDoc( + const sinv = (await fyo.doc.get( ModelNameEnum.SalesInvoice, 'SINV-1001' )) as Invoice; @@ -448,7 +448,7 @@ test('Sales Invoice then another Shipment', async (t) => { }); test('Cancel Sales Invoice after Shipment is created', async (t) => { - const sinv = (await fyo.doc.getDoc( + const sinv = (await fyo.doc.get( ModelNameEnum.SalesInvoice, 'SINV-1001' )) as Invoice; @@ -466,7 +466,7 @@ test('Cancel Sales Invoice after Shipment is created', async (t) => { }); test('Cancel partial Shipment', async (t) => { - let shpm = (await fyo.doc.getDoc( + let shpm = (await fyo.doc.get( ModelNameEnum.Shipment, 'SHPM-1003' )) as StockTransfer; @@ -477,13 +477,13 @@ test('Cancel partial Shipment', async (t) => { await assertDoesNotThrow(async () => await shpm.cancel()); t.ok(shpm.isCancelled, 'SHPM cancelled'); - const sinv = (await fyo.doc.getDoc( + const sinv = (await fyo.doc.get( ModelNameEnum.SalesInvoice, 'SINV-1001' )) as Invoice; t.equal(sinv.stockNotTransferred, 1, 'stock qty 1 untransferred'); - shpm = (await fyo.doc.getDoc( + shpm = (await fyo.doc.get( ModelNameEnum.Shipment, 'SHPM-1004' )) as StockTransfer; @@ -498,7 +498,7 @@ test('Cancel partial Shipment', async (t) => { }); test('Duplicate Shipment, backref unset', async (t) => { - const shpm = (await fyo.doc.getDoc( + const shpm = (await fyo.doc.get( ModelNameEnum.Shipment, 'SHPM-1003' )) as StockTransfer; @@ -510,7 +510,7 @@ test('Duplicate Shipment, backref unset', async (t) => { }); test('Cancel and Delete Sales Invoice with cancelled Shipments', async (t) => { - const sinv = (await fyo.doc.getDoc( + const sinv = (await fyo.doc.get( ModelNameEnum.SalesInvoice, 'SINV-1001' )) as Invoice; @@ -556,7 +556,7 @@ test('Create Shipment from manually set Back Ref', async (t) => { ); await (await prec.sync()).submit(); - const sinv = fyo.doc.getNewDoc(ModelNameEnum.SalesInvoice) as Invoice; + const sinv = fyo.doc.new(ModelNameEnum.SalesInvoice) as Invoice; const quantity = 5; await sinv.set({ party, @@ -568,7 +568,7 @@ test('Create Shipment from manually set Back Ref', async (t) => { t.equal(sinv.stockNotTransferred, quantity, "stock hasn't been transferred"); - const shpm = fyo.doc.getNewDoc(ModelNameEnum.Shipment) as Shipment; + const shpm = fyo.doc.new(ModelNameEnum.Shipment) as Shipment; await shpm.set('backReference', sinv.name); await shpm.set('date', new Date('2022-01-10')); shpm.items?.[0].set('location', location); diff --git a/reports/GoodsAndServiceTax/BaseGSTR.ts b/reports/GoodsAndServiceTax/BaseGSTR.ts index beebaaac..017390de 100644 --- a/reports/GoodsAndServiceTax/BaseGSTR.ts +++ b/reports/GoodsAndServiceTax/BaseGSTR.ts @@ -140,7 +140,7 @@ export abstract class BaseGSTR extends Report { } async getGstrRow(entryName: string): Promise { - const entry = (await this.fyo.doc.getDoc( + const entry = (await this.fyo.doc.get( this.schemaName, entryName )) as Invoice; @@ -149,7 +149,7 @@ export abstract class BaseGSTR extends Report { 'gstin' )) as string | null; - const party = (await this.fyo.doc.getDoc('Party', entry.party)) as Party; + const party = (await this.fyo.doc.get('Party', entry.party)) as Party; let place = ''; if (party.address) { diff --git a/src/App.vue b/src/App.vue index e9360b13..3d193f81 100644 --- a/src/App.vue +++ b/src/App.vue @@ -227,8 +227,8 @@ export default defineComponent({ throw error; }, async setDeskRoute(): Promise { - const { onboardingComplete } = await fyo.doc.getDoc('GetStarted'); - const { hideGetStarted } = await fyo.doc.getDoc('SystemSettings'); + const { onboardingComplete } = await fyo.doc.get('GetStarted'); + const { hideGetStarted } = await fyo.doc.get('SystemSettings'); let route = '/get-started'; if (hideGetStarted || onboardingComplete) { diff --git a/src/components/Controls/DynamicLink.vue b/src/components/Controls/DynamicLink.vue index d9a4eb82..dd003605 100644 --- a/src/components/Controls/DynamicLink.vue +++ b/src/components/Controls/DynamicLink.vue @@ -83,7 +83,7 @@ export default { const filters = await this.getCreateFilters(); const { openQuickEdit } = await import('src/utils/ui'); - const doc = fyo.doc.getNewDoc(schemaName, { name, ...filters }); + const doc = fyo.doc.new(schemaName, { name, ...filters }); openQuickEdit({ doc }); doc.once('afterSync', () => { diff --git a/src/components/Controls/Link.vue b/src/components/Controls/Link.vue index e123f50c..0d10795d 100644 --- a/src/components/Controls/Link.vue +++ b/src/components/Controls/Link.vue @@ -136,7 +136,7 @@ export default { const filters = await this.getCreateFilters(); const { openQuickEdit } = await import('src/utils/ui'); - const doc = fyo.doc.getNewDoc(schemaName, { name, ...filters }); + const doc = fyo.doc.new(schemaName, { name, ...filters }); openQuickEdit({ doc }); doc.once('afterSync', () => { diff --git a/src/components/Sidebar.vue b/src/components/Sidebar.vue index a788bf8a..e2be262e 100644 --- a/src/components/Sidebar.vue +++ b/src/components/Sidebar.vue @@ -228,7 +228,7 @@ export default defineComponent({ }, }, async mounted() { - const { companyName } = await fyo.doc.getDoc('AccountingSettings'); + const { companyName } = await fyo.doc.get('AccountingSettings'); this.companyName = companyName as string; this.groups = await getSidebarConfig(); diff --git a/src/importer.ts b/src/importer.ts index c5e5854f..4c1134c5 100644 --- a/src/importer.ts +++ b/src/importer.ts @@ -229,7 +229,7 @@ export class Importer { }, {} as Record); for (const [name, data] of dataMap.entries()) { - const doc = this.fyo.doc.getNewDoc(this.schemaName, data, false); + const doc = this.fyo.doc.new(this.schemaName, data, false); for (const schemaName in targetFieldnameMap) { const fieldname = targetFieldnameMap[schemaName]; const childTable = childTableMap[name]?.[schemaName]; diff --git a/src/pages/ChartOfAccounts.vue b/src/pages/ChartOfAccounts.vue index 1d4169a8..d1e0adb1 100644 --- a/src/pages/ChartOfAccounts.vue +++ b/src/pages/ChartOfAccounts.vue @@ -328,7 +328,7 @@ export default defineComponent({ return; } - const doc = await fyo.doc.getDoc(ModelNameEnum.Account, account.name); + const doc = await fyo.doc.get(ModelNameEnum.Account, account.name); this.setOpenAccountDocListener(doc, account); await openQuickEdit({ doc }); }, @@ -447,7 +447,7 @@ export default defineComponent({ this.insertingAccount = true; const accountName = this.newAccountName.trim(); - const doc = fyo.doc.getNewDoc('Account'); + const doc = fyo.doc.new('Account'); try { let { name, rootType, accountType } = parentAccount; await doc.set({ diff --git a/src/pages/Dashboard/UnpaidInvoices.vue b/src/pages/Dashboard/UnpaidInvoices.vue index c5fbe059..0104a19e 100644 --- a/src/pages/Dashboard/UnpaidInvoices.vue +++ b/src/pages/Dashboard/UnpaidInvoices.vue @@ -216,7 +216,7 @@ export default defineComponent({ this.barWidth = (this.paid / (this.total || 1)) * 100; }, async newInvoice() { - const doc = fyo.doc.getNewDoc(this.schemaName); + const doc = fyo.doc.new(this.schemaName); await routeTo(`/edit/${this.schemaName}/${doc.name!}`); }, diff --git a/src/pages/GetStarted.vue b/src/pages/GetStarted.vue index 63f35559..b4ad0833 100644 --- a/src/pages/GetStarted.vue +++ b/src/pages/GetStarted.vue @@ -95,7 +95,7 @@ export default defineComponent({ }; }, async activated() { - await fyo.doc.getDoc('GetStarted'); + await fyo.doc.get('GetStarted'); await this.checkForCompletedTasks(); }, methods: { @@ -139,7 +139,7 @@ export default defineComponent({ return true; } - const doc = await fyo.doc.getDoc('GetStarted'); + const doc = await fyo.doc.get('GetStarted'); const onboardingComplete = fyo.schemaMap.GetStarted?.fields .filter(({ fieldname }) => fieldname !== 'onboardingComplete') .map(({ fieldname }) => doc.get(fieldname)) @@ -147,7 +147,7 @@ export default defineComponent({ if (onboardingComplete) { await this.updateChecks({ onboardingComplete }); - const systemSettings = await fyo.doc.getDoc('SystemSettings'); + const systemSettings = await fyo.doc.get('SystemSettings'); await systemSettings.set('hideGetStarted', true); await systemSettings.sync(); } @@ -199,7 +199,7 @@ export default defineComponent({ }, async updateChecks(toUpdate: Record) { await fyo.singles.GetStarted?.setAndSync(toUpdate); - await fyo.doc.getDoc('GetStarted'); + await fyo.doc.get('GetStarted'); }, isCompleted(item: ListItem) { return fyo.singles.GetStarted?.get(item.fieldname) || false; diff --git a/src/pages/ListView/ListView.vue b/src/pages/ListView/ListView.vue index 11ce0010..392123e1 100644 --- a/src/pages/ListView/ListView.vue +++ b/src/pages/ListView/ListView.vue @@ -160,7 +160,7 @@ export default defineComponent({ } const filters = getCreateFiltersFromListViewFilters(this.filters ?? {}); - const doc = fyo.doc.getNewDoc(this.schemaName, filters); + const doc = fyo.doc.new(this.schemaName, filters); const route = getFormRoute(this.schemaName, doc.name!); await routeTo(route); }, diff --git a/src/pages/Plugin/Plugin.vue b/src/pages/Plugin/Plugin.vue index 0f882794..6ebf9006 100644 --- a/src/pages/Plugin/Plugin.vue +++ b/src/pages/Plugin/Plugin.vue @@ -30,9 +30,9 @@ export default defineComponent({ }, async mounted() { if (this.name) { - this.doc = await this.fyo.doc.getDoc(ModelNameEnum.Plugin, this.name); + this.doc = await this.fyo.doc.get(ModelNameEnum.Plugin, this.name); } else { - this.doc = this.fyo.doc.getNewDoc(ModelNameEnum.Plugin); + this.doc = this.fyo.doc.new(ModelNameEnum.Plugin); } if (this.fyo.store.isDevelopment) { // @ts-ignore diff --git a/src/pages/PrintView/PrintView.vue b/src/pages/PrintView/PrintView.vue index 2c4d1ecd..88da0a52 100644 --- a/src/pages/PrintView/PrintView.vue +++ b/src/pages/PrintView/PrintView.vue @@ -131,7 +131,7 @@ export default defineComponent({ label: this.t`New Template`, group: this.t`Create`, action: async () => { - const doc = this.fyo.doc.getNewDoc(ModelNameEnum.PrintTemplate, { + const doc = this.fyo.doc.new(ModelNameEnum.PrintTemplate, { type: this.schemaName, }); @@ -159,7 +159,7 @@ export default defineComponent({ label: this.t`Duplicate Template`, group: this.t`Create`, action: async () => { - const doc = this.fyo.doc.getNewDoc(ModelNameEnum.PrintTemplate, { + const doc = this.fyo.doc.new(ModelNameEnum.PrintTemplate, { type: this.schemaName, template: this.templateDoc?.template, }); @@ -191,7 +191,7 @@ export default defineComponent({ }, methods: { async initialize() { - this.doc = await fyo.doc.getDoc(this.schemaName, this.name); + this.doc = await fyo.doc.get(this.schemaName, this.name); await this.setTemplateList(); await this.setTemplateFromDefault(); if (!this.templateDoc && this.templateList.length) { @@ -227,7 +227,7 @@ export default defineComponent({ this.templateName = value; try { - this.templateDoc = (await this.fyo.doc.getDoc( + this.templateDoc = (await this.fyo.doc.get( ModelNameEnum.PrintTemplate, this.templateName )) as PrintTemplate; diff --git a/src/pages/QuickEditForm.vue b/src/pages/QuickEditForm.vue index 1c6e50d4..e8bf504c 100644 --- a/src/pages/QuickEditForm.vue +++ b/src/pages/QuickEditForm.vue @@ -226,7 +226,7 @@ export default defineComponent({ }, async setDoc() { try { - this.doc = await fyo.doc.getDoc(this.schemaName, this.name); + this.doc = await fyo.doc.get(this.schemaName, this.name); } catch (e) { return this.$router.back(); } diff --git a/src/regional/in/in.ts b/src/regional/in/in.ts index 561040bc..b21cbcdf 100644 --- a/src/regional/in/in.ts +++ b/src/regional/in/in.ts @@ -19,7 +19,7 @@ async function createTaxes(fyo: Fyo) { const name = `${type}-${percent}`; const details = getTaxDetails(type as TaxType, percent); - const newTax = fyo.doc.getNewDoc('Tax', { name, details }); + const newTax = fyo.doc.new('Tax', { name, details }); await newTax.sync(); } } diff --git a/src/setup/createCOA.ts b/src/setup/createCOA.ts index 7324978d..d6c56f6b 100644 --- a/src/setup/createCOA.ts +++ b/src/setup/createCOA.ts @@ -49,7 +49,7 @@ export class CreateCOA { child as COAChildAccount | COARootAccount ); - const doc = this.fyo.doc.getNewDoc('Account', { + const doc = this.fyo.doc.new('Account', { name: accountName, parentAccount, isGroup, diff --git a/src/setup/setupInstance.ts b/src/setup/setupInstance.ts index 124a7814..affac37d 100644 --- a/src/setup/setupInstance.ts +++ b/src/setup/setupInstance.ts @@ -92,7 +92,7 @@ async function updateAccountingSettings( }: SetupWizardOptions, fyo: Fyo ) { - const accountingSettings = (await fyo.doc.getDoc( + const accountingSettings = (await fyo.doc.get( 'AccountingSettings' )) as AccountingSettings; await accountingSettings.setAndSync({ @@ -111,7 +111,7 @@ async function updatePrintSettings( { logo, companyName, email }: SetupWizardOptions, fyo: Fyo ) { - const printSettings = await fyo.doc.getDoc('PrintSettings'); + const printSettings = await fyo.doc.get('PrintSettings'); await printSettings.setAndSync({ logo, companyName, @@ -130,7 +130,7 @@ async function updateSystemSettings( companyCurrency ?? countryOptions.currency ?? DEFAULT_CURRENCY; const locale = countryOptions.locale ?? DEFAULT_LOCALE; const countryCode = getCountryCodeFromCountry(country); - const systemSettings = await fyo.doc.getDoc('SystemSettings'); + const systemSettings = await fyo.doc.get('SystemSettings'); const instanceId = getRandomString(); await systemSettings.setAndSync({ @@ -260,7 +260,7 @@ async function checkAndCreateDoc( return; } - const doc = fyo.doc.getNewDoc(schemaName, docObject); + const doc = fyo.doc.new(schemaName, docObject); return doc.sync(); } @@ -347,7 +347,7 @@ async function createDefaultNumberSeries(fyo: Fyo) { } async function updateInventorySettings(fyo: Fyo) { - const inventorySettings = (await fyo.doc.getDoc( + const inventorySettings = (await fyo.doc.get( ModelNameEnum.InventorySettings )) as InventorySettings; diff --git a/src/utils/initialization.ts b/src/utils/initialization.ts index a59fe767..f187e05a 100644 --- a/src/utils/initialization.ts +++ b/src/utils/initialization.ts @@ -50,7 +50,7 @@ async function setSingles(fyo: Fyo) { continue; } - await fyo.doc.getDoc(schema.name); + await fyo.doc.get(schema.name); } } @@ -121,7 +121,7 @@ async function setVersion(fyo: Fyo) { const { appVersion } = fyo.store; if (version !== appVersion) { - const systemSettings = await fyo.doc.getDoc(ModelNameEnum.SystemSettings); + const systemSettings = await fyo.doc.get(ModelNameEnum.SystemSettings); await systemSettings?.setAndSync('version', appVersion); } } @@ -137,7 +137,7 @@ function setDeviceId(fyo: Fyo) { } async function setInstanceId(fyo: Fyo) { - const systemSettings = await fyo.doc.getDoc(ModelNameEnum.SystemSettings); + const systemSettings = await fyo.doc.get(ModelNameEnum.SystemSettings); if (!systemSettings.instanceId) { await systemSettings.setAndSync('instanceId', getRandomString()); } @@ -161,7 +161,7 @@ export async function setCurrencySymbols(fyo: Fyo) { } async function setOpenCount(fyo: Fyo) { - const misc = await fyo.doc.getDoc(ModelNameEnum.Misc); + const misc = await fyo.doc.get(ModelNameEnum.Misc); let openCount = misc.openCount as number | null; if (typeof openCount !== 'number') { @@ -218,7 +218,7 @@ async function loadPlugins(fyo: Fyo) { resolve(); }; }); - document.body.appendChild(module); + document.head.appendChild(module); await loadPromise; } } diff --git a/src/utils/misc.ts b/src/utils/misc.ts index 13b6c85b..1ea0e373 100644 --- a/src/utils/misc.ts +++ b/src/utils/misc.ts @@ -68,13 +68,7 @@ export function getSetupWizardDoc(languageMap?: LanguageMap) { if (languageMap) { translateSchema(schema, languageMap, schemaTranslateables); } - return fyo.doc.getNewDoc( - 'SetupWizard', - {}, - false, - schema as Schema, - SetupWizard - ); + return fyo.doc.new('SetupWizard', {}, false, schema as Schema, SetupWizard); } export function updateConfigFiles(fyo: Fyo): ConfigFile { diff --git a/src/utils/printTemplates.ts b/src/utils/printTemplates.ts index 867f89ad..0a1d7a38 100644 --- a/src/utils/printTemplates.ts +++ b/src/utils/printTemplates.ts @@ -40,13 +40,13 @@ export async function getPrintTemplatePropValues( (values.doc as PrintTemplateData).entryType = doc.schema.name; (values.doc as PrintTemplateData).entryLabel = doc.schema.label; - const printSettings = await fyo.doc.getDoc(ModelNameEnum.PrintSettings); + const printSettings = await fyo.doc.get(ModelNameEnum.PrintSettings); const printValues = await getPrintTemplateDocValues( printSettings, printSettingsFields ); - const accountingSettings = await fyo.doc.getDoc( + const accountingSettings = await fyo.doc.get( ModelNameEnum.AccountingSettings ); const accountingValues = await getPrintTemplateDocValues( diff --git a/src/utils/search.ts b/src/utils/search.ts index 961aef53..735f2413 100644 --- a/src/utils/search.ts +++ b/src/utils/search.ts @@ -74,7 +74,7 @@ export function getGroupLabelMap() { function getCreateAction(fyo: Fyo, schemaName: string, initData?: RawValueMap) { return async function action() { - const doc = fyo.doc.getNewDoc(schemaName, initData); + const doc = fyo.doc.new(schemaName, initData); const route = getFormRoute(schemaName, doc.name!); await routeTo(route); }; diff --git a/src/utils/ui.ts b/src/utils/ui.ts index a1c8c907..7ac8eb8f 100644 --- a/src/utils/ui.ts +++ b/src/utils/ui.ts @@ -362,13 +362,13 @@ export async function getDocFromNameIfExistsElseNew( name?: string ) { if (!name) { - return fyo.doc.getNewDoc(schemaName); + return fyo.doc.new(schemaName); } try { - return await fyo.doc.getDoc(schemaName, name); + return await fyo.doc.get(schemaName, name); } catch { - return fyo.doc.getNewDoc(schemaName); + return fyo.doc.new(schemaName); } }