fix: prefer pending pallet for carton scan

This commit is contained in:
2026-09-20 16:10:48 +08:00
parent 117431a4fb
commit 1e171ec81c
2 changed files with 16 additions and 1 deletions
+11
View File
@@ -149,3 +149,14 @@ test('sealed pallet resolves either its DP code or any member carton as one whol
status: state.ITEM_STATUS.PICKED,
})
})
test('a carton duplicated by a stale task payload selects the remaining sealed pallet', () => {
const picked = { id: 1, unitType: 'SEALED_PALLET', palletNo: 'DP-260920-0001', boxCodes: ['EXXHWK2809191198#20-01'] }
const pending = { id: 2, unitType: 'SEALED_PALLET', palletNo: 'DP-260920-0002', boxCodes: ['EXXHWK2809191198#20-01', 'EXXHWK2809191198#20-19'] }
assert.deepEqual(state.classifyScan([picked, pending], {
1: state.ITEM_STATUS.PICKED,
2: state.ITEM_STATUS.PENDING,
}, 'EXXHWK2809191198#20-19'), {
type: 'pallet', item: pending, matchedBy: 'carton',
})
})
+5 -1
View File
@@ -92,7 +92,11 @@ export function classifyScan(items, states, scanCode, scannedBoxCodes = {}) {
return { type: 'pallet', item: palletItem }
}
const item = items.find((entry) => (entry.boxCodes || []).includes(scanCode)) || null
const matchingItems = items.filter((entry) => (entry.boxCodes || []).includes(scanCode))
const item = matchingItems.find((entry) => {
const status = states[entry.id] || ITEM_STATUS.PENDING
return status !== ITEM_STATUS.PICKED && status !== ITEM_STATUS.SKIPPED
}) || matchingItems[0] || null
if (!item) return { type: 'unknown', item: null }
if (isSealedPalletItem(item)) {
const status = states[item.id] || ITEM_STATUS.PENDING