From 9fca47134262ebef9c54df80a78ec180356435ae Mon Sep 17 00:00:00 2001 From: NotAbdelrahmanelsayed Date: Fri, 12 Jun 2026 20:33:31 +0200 Subject: [PATCH] fix(pos): honor scanned barcode UOM in item selection dialog When a barcode is tied to a non-stock UOM (e.g. a barcode keyed to "Nos" on a gram-stocked item), search_by_barcode resolves item.uom to that UOM, but ItemSelectionDialog defaulted the UOM radio to the stock UOM whenever there was more than one possible UOM. barcode_uoms isn't carried on the search_by_barcode response, so its single-barcode auto-select never fired either, and the scan landed on the stock UOM instead of the barcode's UOM. Prefer an explicitly resolved UOM when defaulting the selection: resolved_uom -> scanned barcode UOM (item.uom != stock_uom) -> a sole barcode UOM -> stock UOM. No behaviour change when item.uom is absent or equals the stock UOM. Co-Authored-By: Claude Opus 4.8 --- .../components/sale/ItemSelectionDialog.vue | 30 ++++++++++++------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/POS/src/components/sale/ItemSelectionDialog.vue b/POS/src/components/sale/ItemSelectionDialog.vue index a502a96cf..3ab79d276 100644 --- a/POS/src/components/sale/ItemSelectionDialog.vue +++ b/POS/src/components/sale/ItemSelectionDialog.vue @@ -468,20 +468,28 @@ async function loadOptions() { // Load UOM options options.value = buildUomOptions() if (options.value.length > 0) { - // Check if item has a single barcode UOM to auto-select + // Prefer an explicitly resolved UOM. A scanned barcode carries its own + // UOM: search_by_barcode sets item.uom from `Item Barcode.uom` (e.g. a + // barcode keyed to "Nos" on a gram-stocked item). Honour that over the + // stock UOM. Order: resolved_uom (weighted/priced) -> scanned barcode UOM + // -> a sole barcode UOM -> first option (stock UOM). const barcodeUoms = props.item?.barcode_uoms ? props.item.barcode_uoms.split(",").filter(Boolean) : [] - - if (barcodeUoms.length === 1) { - // Find and select the matching UOM option - const uom = props.item.resolved_uom || barcodeUoms[0] - const matchingOption = options.value.find((opt) => opt.uom === uom) - selectedOption.value = matchingOption || options.value[0] - } else { - // Default to first option (stock UOM) - selectedOption.value = options.value[0] - } + const scannedUom = + props.item?.uom && props.item.uom !== props.item.stock_uom + ? props.item.uom + : null + const preferredUom = + props.item?.resolved_uom || + scannedUom || + (barcodeUoms.length === 1 ? barcodeUoms[0] : null) + + const matchingOption = preferredUom + ? options.value.find((opt) => opt.uom === preferredUom) + : null + // Default to first option (stock UOM) when nothing more specific matches. + selectedOption.value = matchingOption || options.value[0] } loading.value = false }