Skip to content

Commit

Permalink
fix: refactored
Browse files Browse the repository at this point in the history
  • Loading branch information
AbleKSaju committed Dec 26, 2024
1 parent 3d84756 commit 4f9fe44
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 15 deletions.
6 changes: 6 additions & 0 deletions models/inventory/Point of Sale/POSSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ export class POSSettings extends Doc {
cashAccount?: string;
writeOffAccount?: string;
weightEnabledBarcode?: boolean;
checkDigit?: number;
itemCodeDigits?: number;
itemWeight?: number;

posUI?: 'Classic' | 'Modern';

Expand All @@ -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,
};
}
25 changes: 10 additions & 15 deletions src/components/Controls/weightEnabledBarcode.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, string> = isWeightEnabled
? {
weightBarcode: barcode.slice(
randomNumberLength,
randomNumberLength + ItemBarcodeLength
checkDigit,
checkDigit + itemCodeDigits
),
}
: { barcode };
Expand All @@ -109,7 +104,7 @@ export default defineComponent({
? this.parseBarcode(
barcode,
unit as string,
randomNumberLength + ItemBarcodeLength
checkDigit + itemCodeDigits
)
: 1;
Expand All @@ -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;
Expand Down

0 comments on commit 4f9fe44

Please sign in to comment.