2
0
mirror of https://github.com/frappe/books.git synced 2024-12-22 10:58:59 +00:00

fix: append imported modules to head

- refactor doc.getDoc to doc.get
- refactor doc.getNewDoc to doc.new
This commit is contained in:
18alantom 2023-07-25 11:40:31 +05:30
parent 5489cd979f
commit 31b1eed124
49 changed files with 142 additions and 157 deletions

View File

@ -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();
}
}

View File

@ -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,

View File

@ -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;

View File

@ -469,7 +469,7 @@ export class Doc extends Observable<DocValue | Doc[]> {
}
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<DocValue | Doc[]> {
}
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<DocValue | Doc[]> {
updateMap
) as RawValueMap;
return this.fyo.doc.getNewDoc(this.schemaName, rawUpdateMap, true);
return this.fyo.doc.new(this.schemaName, rawUpdateMap, true);
}
/**

View File

@ -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,

View File

@ -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}`);
}

View File

@ -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;

View File

@ -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
);

View File

@ -73,7 +73,7 @@ export class Account extends Doc {
return {
parentField: 'parentAccount',
async getRootLabel(): Promise<string> {
const accountingSettings = await fyo.doc.getDoc('AccountingSettings');
const accountingSettings = await fyo.doc.get('AccountingSettings');
return accountingSettings.companyName as string;
},
};

View File

@ -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,

View File

@ -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<StockTransfer | null> {
@ -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();
}
}

View File

@ -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
);

View File

@ -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,

View File

@ -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,
});

View File

@ -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;

View File

@ -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;

View File

@ -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,

View File

@ -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
);

View File

@ -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;

View File

@ -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
);

View File

@ -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;

View File

@ -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);
}
}

View File

@ -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<StockTransfer> {
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<StockMovement> {
const doc = fyo.doc.getNewDoc(ModelNameEnum.StockMovement, {
const doc = fyo.doc.new(ModelNameEnum.StockMovement, {
movementType,
date,
}) as StockMovement;

View File

@ -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);

View File

@ -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;

View File

@ -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`);
}

View File

@ -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'),

View File

@ -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);

View File

@ -140,7 +140,7 @@ export abstract class BaseGSTR extends Report {
}
async getGstrRow(entryName: string): Promise<GSTRRow> {
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) {

View File

@ -227,8 +227,8 @@ export default defineComponent({
throw error;
},
async setDeskRoute(): Promise<void> {
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) {

View File

@ -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', () => {

View File

@ -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', () => {

View File

@ -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();

View File

@ -229,7 +229,7 @@ export class Importer {
}, {} as Record<string, string>);
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];

View File

@ -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({

View File

@ -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!}`);
},

View File

@ -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<string, DocValue>) {
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;

View File

@ -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);
},

View File

@ -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

View File

@ -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;

View File

@ -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();
}

View File

@ -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();
}
}

View File

@ -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,

View File

@ -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;

View File

@ -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;
}
}

View File

@ -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 {

View File

@ -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(

View File

@ -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);
};

View File

@ -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);
}
}