2
0
mirror of https://github.com/frappe/books.git synced 2024-11-14 09:24:04 +00:00
books/models/inventory/helpers.ts

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

30 lines
697 B
TypeScript
Raw Normal View History

2022-10-28 08:04:08 +00:00
import { Fyo } from 'fyo';
import { ModelNameEnum } from 'models/types';
import { StockQueue } from './StockQueue';
export async function getStockQueue(
item: string,
location: string,
fyo: Fyo
): Promise<StockQueue> {
/**
* Create a new StockQueue if it doesn't exist.
*/
const names = (await fyo.db.getAllRaw(ModelNameEnum.StockQueue, {
filters: { item, location },
fields: ['name'],
limit: 1,
})) as { name: string }[];
const name = names?.[0]?.name;
if (!name) {
return fyo.doc.getNewDoc(ModelNameEnum.StockQueue, {
item,
location,
}) as StockQueue;
}
return (await fyo.doc.getDoc(ModelNameEnum.StockQueue, name)) as StockQueue;
}