diff --git a/models/inventory/Point of Sale/POSSettings.ts b/models/inventory/Point of Sale/POSSettings.ts index 07e01682a..279b342f2 100644 --- a/models/inventory/Point of Sale/POSSettings.ts +++ b/models/inventory/Point of Sale/POSSettings.ts @@ -11,6 +11,9 @@ export class POSSettings extends Doc { cashAccount?: string; writeOffAccount?: string; weightEnabledBarcode?: boolean; + checkDigit?: number; + itemCodeDigits?: number; + itemWeight?: number; posUI?: 'Classic' | 'Modern'; @@ -25,5 +28,8 @@ export class POSSettings extends Doc { hidden: HiddenMap = { weightEnabledBarcode: () => !this.fyo.singles.InventorySettings?.enableBarcodes, + checkDigit: () => !this.fyo.singles.InventorySettings?.enableBarcodes, + itemCodeDigits: () => !this.fyo.singles.InventorySettings?.enableBarcodes, + itemWeight: () => !this.fyo.singles.InventorySettings?.enableBarcodes, }; } diff --git a/src/components/Controls/weightEnabledBarcode.vue b/src/components/Controls/weightEnabledBarcode.vue index cab28f100..4388006e4 100644 --- a/src/components/Controls/weightEnabledBarcode.vue +++ b/src/components/Controls/weightEnabledBarcode.vue @@ -73,25 +73,20 @@ export default defineComponent({ const isWeightEnabled = this.fyo.singles.POSSettings?.weightEnabledBarcode; - const randomNumberLength = this.fyo.singles.POSSettings - ?.randomNumberLength as number; - const ItemBarcodeLength = this.fyo.singles.POSSettings - ?.ItemBarcodeLength as number; - const quantityBarcodeLength = this.fyo.singles.POSSettings - ?.quantityBarcodeLength as number; - - if ( - code.length !== - randomNumberLength + ItemBarcodeLength + quantityBarcodeLength - ) { + const checkDigit = this.fyo.singles.POSSettings?.checkDigit as number; + const itemCodeDigits = this.fyo.singles.POSSettings + ?.itemCodeDigits as number; + const itemWeight = this.fyo.singles.POSSettings?.itemWeight as number; + + if (code.length !== checkDigit + itemCodeDigits + itemWeight) { return this.error(this.t`Barcode ${barcode} has an invalid length.`); } const filters: Record = isWeightEnabled ? { weightBarcode: barcode.slice( - randomNumberLength, - randomNumberLength + ItemBarcodeLength + checkDigit, + checkDigit + itemCodeDigits ), } : { barcode }; @@ -109,7 +104,7 @@ export default defineComponent({ ? this.parseBarcode( barcode, unit as string, - randomNumberLength + ItemBarcodeLength + checkDigit + itemCodeDigits ) : 1; @@ -118,7 +113,7 @@ export default defineComponent({ }, parseBarcode(barcode: string, unitType: string, sliceDigit: number) { - const weightRaw = parseInt(barcode.slice(sliceDigit), sliceDigit); + const weightRaw = parseInt(barcode.slice(sliceDigit)); let itemQuantity = 0;