diff --git a/models/baseModels/Invoice/Invoice.ts b/models/baseModels/Invoice/Invoice.ts index 4cdab7e5..329b2c7f 100644 --- a/models/baseModels/Invoice/Invoice.ts +++ b/models/baseModels/Invoice/Invoice.ts @@ -1073,7 +1073,9 @@ export abstract class Invoice extends Transactional { linkedEntries = await getLinkedEntries(sinvDoc); } - if (!this.stockNotTransferred) { + const itemVisibility = this.fyo.singles.POSSettings?.itemVisibility; + + if (!this.stockNotTransferred && itemVisibility === 'Inventory Items') { return null; } @@ -1119,9 +1121,13 @@ export abstract class Invoice extends Transactional { continue; } + let quantity; + if (itemDoc.trackItem) { + quantity = row.stockNotTransferred; + } else { + quantity = row.quantity; + } const item = row.item; - const quantity = row.stockNotTransferred; - const trackItem = itemDoc.trackItem; const batch = row.batch || null; const description = row.description; const hsnCode = row.hsnCode; @@ -1131,7 +1137,7 @@ export abstract class Invoice extends Transactional { rate = rate.mul(this.exchangeRate); } - if (!quantity || !trackItem) { + if (!quantity && itemVisibility === 'Inventory Items') { continue; } @@ -1144,7 +1150,7 @@ export abstract class Invoice extends Transactional { data.date )) ?? 0; - if (stock < quantity) { + if (stock < (quantity as number)) { continue; } } diff --git a/models/helpers.ts b/models/helpers.ts index 22f22944..4ec166f8 100644 --- a/models/helpers.ts +++ b/models/helpers.ts @@ -866,6 +866,16 @@ export async function validateQty( } } + const trackItem = await sinvDoc.fyo.getValue( + ModelNameEnum.Item, + item.item as string, + 'trackItem' + ); + + if (!trackItem) { + return; + } + if (!itemQtyMap[itemName] || itemQtyMap[itemName].availableQty === 0) { throw new ValidationError(t`Item ${itemName} has Zero Quantity`); } diff --git a/models/inventory/StockManager.ts b/models/inventory/StockManager.ts index 392d32e1..a25b3a62 100644 --- a/models/inventory/StockManager.ts +++ b/models/inventory/StockManager.ts @@ -92,6 +92,11 @@ export class StockManager { } #validateQuantity(details: SMIDetails) { + const itemVisibility = this.fyo.singles.POSSettings?.itemVisibility; + if (itemVisibility !== 'Inventory Items') { + return; + } + if (!details.quantity) { throw new ValidationError(t`Quantity needs to be set`); } @@ -127,7 +132,13 @@ export class StockManager { } async #validateStockAvailability(details: SMIDetails) { - if (!details.fromLocation) { + const trackItem = await this.fyo.getValue( + ModelNameEnum.Item, + details.item, + 'trackItem' + ); + + if (!details.fromLocation || !trackItem) { return; } diff --git a/src/pages/POS/POS.vue b/src/pages/POS/POS.vue index 78441cb3..3950b4db 100644 --- a/src/pages/POS/POS.vue +++ b/src/pages/POS/POS.vue @@ -373,9 +373,18 @@ export default defineComponent({ await this.afterSync(); }, async setItems() { + const filters: Record = {}; + const itemVisibility = this.fyo.singles.POSSettings?.itemVisibility; + + if (itemVisibility === 'Inventory Items') { + filters.trackItem = true; + } else { + filters.trackItem = false; + } + const items = (await fyo.db.getAll(ModelNameEnum.Item, { fields: [], - filters: { trackItem: true }, + filters, })) as Item[]; this.items = [] as POSItem[]; @@ -623,7 +632,12 @@ export default defineComponent({ await this.validate(); await this.submitSinvDoc(); - if (this.sinvDoc.stockNotTransferred) { + const itemVisibility = this.fyo.singles.POSSettings?.itemVisibility; + + if ( + this.sinvDoc.stockNotTransferred || + itemVisibility !== 'Inventory Items' + ) { await this.makeStockTransfer(); } @@ -708,6 +722,16 @@ export default defineComponent({ } for (const item of shipmentDoc.items) { + const trackItem = await fyo.getValue( + ModelNameEnum.Item, + item.item as string, + 'trackItem' + ); + + if (!trackItem) { + continue; + } + item.location = fyo.singles.POSSettings?.inventory; item.serialNumber = this.itemSerialNumbers[item.item as string] ?? undefined; @@ -787,7 +811,7 @@ export default defineComponent({ this.setTotalTaxedAmount(); }, async validate() { - validateSinv(this.sinvDoc as SalesInvoice, this.itemQtyMap); + await validateSinv(this.sinvDoc as SalesInvoice, this.itemQtyMap); await validateShipment(this.itemSerialNumbers); }, async applyPricingRule() { diff --git a/src/utils/pos.ts b/src/utils/pos.ts index 221e2758..74112283 100644 --- a/src/utils/pos.ts +++ b/src/utils/pos.ts @@ -76,24 +76,37 @@ export async function getItem(item: string): Promise { return itemDoc; } -export function validateSinv(sinvDoc: SalesInvoice, itemQtyMap: ItemQtyMap) { +export async function validateSinv( + sinvDoc: SalesInvoice, + itemQtyMap: ItemQtyMap +) { if (!sinvDoc) { return; } - validateSinvItems( + await validateSinvItems( sinvDoc.items as SalesInvoiceItem[], itemQtyMap, sinvDoc.returnAgainst as string ); } -function validateSinvItems( +async function validateSinvItems( sinvItems: SalesInvoiceItem[], itemQtyMap: ItemQtyMap, isReturn?: string ) { for (const item of sinvItems) { + const trackItem = await fyo.getValue( + ModelNameEnum.Item, + item.item as string, + 'trackItem' + ); + + if (!trackItem) { + return; + } + if (!item.quantity || (item.quantity < 1 && !isReturn)) { throw new ValidationError( t`Invalid Quantity for Item ${item.item as string}`