Odoo POS扫描含空格条码引发异常问题求助
Looks like you've hit a niche but annoying edge case with Odoo POS and barcode scanners! Let's break down what's happening and how to fix it:
What's Causing the Issue?
The root problem here is how your Honeywell scanner outputs barcodes with spaces, combined with Odoo POS's input handling logic. When you scan a barcode like HB 5732, your scanner is likely sending the full string (including the space) followed by a default suffix (usually a carriage return/enter key press).
Odoo POS's barcode listener might be interpreting the space as a signal to "submit" the current input, then the remaining characters (5732) get routed to the quantity field of the previously selected product (which was set to 3). That's why you end up with 33—it's concatenating the original quantity with the first digit of the remaining barcode segment.
Manual input works because you're explicitly entering the full barcode without triggering the scanner's automatic suffix/input splitting behavior.
Fix Recommendations
1. Adjust Your Scanner's Output Configuration (Quickest Fix)
Honeywell MS7120 scanners let you reconfigure their output via special setup barcodes. Here's what to do:
- Replace spaces in barcodes with a non-whitespace character: Scan the appropriate setup barcode to enable "character replacement"—map spaces to an underscore (
_) or hyphen (-). This way, the scanner sendsHB_5732instead ofHB 5732, which Odoo will recognize as a single barcode. - Disable automatic suffix characters: If the scanner adds a carriage return after scanning, scan the setup barcode to turn this off. This prevents the system from prematurely processing partial input.
You can find these setup barcodes in the Honeywell MS7120 user manual—look for sections on "Data Formatting" or "Suffix Characters".
2. Modify Odoo POS's Barcode Handling Logic
If adjusting the scanner isn't feasible, you'll need to tweak Odoo's POS code to properly handle space-containing barcodes:
- Navigate to the POS module's static JS files:
point_of_sale/static/src/js/ - Open
screens.js(ormodels.js, depending on your exact v11 build) and locate the barcode scanning handler (usually named something likescan_barcodeoron_barcode_scanned). - Modify the logic to wait for the full barcode input before processing:
- Instead of triggering processing on every key press, wait until the enter key is pressed (the standard scanner suffix) to read the entire input box value.
- Ensure the code captures the full input string, including spaces, instead of splitting on whitespace.
Example snippet adjustment:
// Original logic might split on whitespace—replace with full value var barcode = $('.pos-search-input').val().trim(); // Process the full barcode string here, regardless of spaces
3. Temporary Workaround: Update Product Barcodes
If you need an immediate fix without config/code changes, edit the product with the space-containing barcode to remove the space (e.g., change HB 5732 to HB5732) or replace it with a non-whitespace character. This will let the scanner read it as a single, uninterrupted barcode.
Verification Steps
After implementing any fix:
- Scan your first product and set its quantity to 3.
- Scan the space-containing (or modified) barcode.
- Confirm the first product's quantity stays at 3, and the new product is added correctly.
内容的提问来源于stack exchange,提问作者Shibin John

