diff --git a/src/components/POS/SelectedItemRow.vue b/src/components/POS/SelectedItemRow.vue index dcdecccda..a90a01b58 100644 --- a/src/components/POS/SelectedItemRow.vue +++ b/src/components/POS/SelectedItemRow.vue @@ -232,10 +232,7 @@ /> -
+
@@ -264,6 +262,8 @@ import { defineComponent } from 'vue'; import { SalesInvoiceItem } from 'models/baseModels/SalesInvoiceItem/SalesInvoiceItem'; import { Money } from 'pesa'; import { DiscountType } from './types'; +import { t } from 'fyo'; +import { validateSerialNumberCount } from 'src/utils/pos'; export default defineComponent({ name: 'SelectedItemRow', @@ -293,6 +293,9 @@ export default defineComponent({ isUOMConversionEnabled(): boolean { return !!fyo.singles.InventorySettings?.enableUomConversions; }, + hasSerialNumber(): boolean { + return !!(this.row.links?.item && this.row.links?.item.hasSerialNumber); + }, }, methods: { async getAvailableQtyInBatch(): Promise { @@ -318,8 +321,13 @@ export default defineComponent({ if (!serialNumber) { return; } - this.itemSerialNumbers[this.row.item as string] = serialNumber; + + validateSerialNumberCount( + serialNumber, + this.row.quantity ?? 0, + this.row.item! + ); }, setItemDiscount(type: DiscountType, value: Money | number) { if (type === 'percent') { diff --git a/src/utils/pos.ts b/src/utils/pos.ts index 0a62e8c9d..0f41f100c 100644 --- a/src/utils/pos.ts +++ b/src/utils/pos.ts @@ -257,3 +257,26 @@ export async function transferPOSCashAndWriteOff( await (await jvDoc.sync()).submit(); } + +export function validateSerialNumberCount( + serialNumbers: string | undefined, + quantity: number, + item: string +) { + let serialNumberCount = 0; + + if (serialNumbers) { + serialNumberCount = serialNumbers.split('\n').length; + } + + if (quantity !== serialNumberCount) { + const errorMessage = t`Need ${quantity} Serial Numbers for Item ${item}. You have provided ${serialNumberCount}`; + + showToast({ + type: 'error', + message: errorMessage, + duration: 'long', + }); + throw new ValidationError(errorMessage); + } +}