Skip to Content
Odoo Menu
  • Sign in
  • Try it free
  • Apps
    Finance
    • Accounting
    • Invoicing
    • Expenses
    • Spreadsheet (BI)
    • Documents
    • Sign
    Sales
    • CRM
    • Sales
    • POS Shop
    • POS Restaurant
    • Subscriptions
    • Rental
    Websites
    • Website Builder
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Supply Chain
    • Inventory
    • Manufacturing
    • PLM
    • Purchase
    • Maintenance
    • Quality
    Human Resources
    • Employees
    • Recruitment
    • Time Off
    • Appraisals
    • Referrals
    • Fleet
    Marketing
    • Social Marketing
    • Email Marketing
    • SMS Marketing
    • Events
    • Marketing Automation
    • Surveys
    Services
    • Project
    • Timesheets
    • Field Service
    • Helpdesk
    • Planning
    • Appointments
    Productivity
    • Discuss
    • Artificial Intelligence
    • IoT
    • VoIP
    • Knowledge
    • WhatsApp
    Third party apps Odoo Studio Odoo Cloud Platform
  • Industries
    Retail
    • Book Store
    • Clothing Store
    • Furniture Store
    • Grocery Store
    • Hardware Store
    • Toy Store
    Food & Hospitality
    • Bar and Pub
    • Restaurant
    • Fast Food
    • Guest House
    • Beverage Distributor
    • Hotel
    Real Estate
    • Real Estate Agency
    • Architecture Firm
    • Construction
    • Property Management
    • Gardening
    • Property Owner Association
    Consulting
    • Accounting Firm
    • Odoo Partner
    • Marketing Agency
    • Law firm
    • Talent Acquisition
    • Audit & Certification
    Manufacturing
    • Textile
    • Metal
    • Furnitures
    • Food
    • Brewery
    • Corporate Gifts
    Health & Fitness
    • Sports Club
    • Eyewear Store
    • Fitness Center
    • Wellness Practitioners
    • Pharmacy
    • Hair Salon
    Trades
    • Handyman
    • IT Hardware & Support
    • Solar Energy Systems
    • Shoe Maker
    • Cleaning Services
    • HVAC Services
    Others
    • Nonprofit Organization
    • Environmental Agency
    • Billboard Rental
    • Photography
    • Bike Leasing
    • Software Reseller
    Browse all Industries
  • Community
    Learn
    • Tutorials
    • Documentation
    • Certifications
    • Training
    • Blog
    • Podcast
    Empower Education
    • Education Program
    • Scale Up! Business Game
    • Visit Odoo
    Get the Software
    • Download
    • Compare Editions
    • Releases
    Collaborate
    • Github
    • Forum
    • Events
    • Translations
    • Become a Partner
    • Services for Partners
    • Register your Accounting Firm
    Get Services
    • Find a Partner
    • Find an Accountant
    • Meet an advisor
    • Implementation Services
    • Customer References
    • Support
    • Upgrades
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Get a demo
  • Pricing
  • Help
You need to be registered to interact with the community.
All Posts People Badges
Tags (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Tags (View all)
odoo accounting v14 pos v15
About this forum
Help

Custom PLU Weight Barcode Parsing Not Working in Odoo 18 POS JS Patch

Subscribe

Get notified when there's activity on this post

This question has been flagged
javascriptposbarcode
1 Reply
420 Views
Avatar
Ashilkrishna

Hi everyone,

I am trying to implement custom PLU barcode parsing in Odoo 18 POS using JavaScript patching, but it is not working.

My goal:

  • Barcode format: 0PPPPWWWWW

  • First 5 digits → product barcode

  • Last 5 digits → weight in grams

my code:

{
'name': 'POS PLU Barcode Parser',
'version': '18.0.1.0.0',
'category': 'Point of Sale',
'summary': 'Adds support for parsing weight from PLU barcodes in the Point of Sale.',
'depends': ['point_of_sale'],
'assets': {
'point_of_sale._assets_pos': [
'zl_product_plu_barcode/static/src/js/plu_barcode_parser.js',
],
},
'installable': True,
'auto_install': False,
'license': 'LGPL-3',
}
/** @odoo-module **/

import { patch } from "@web/core/utils/patch";
import { ProductScreen } from "@point_of_sale/app/screens/product_screen/product_screen";
import { _t } from "@web/core/l10n/translation";

patch(ProductScreen.prototype, {
/**
* This is the correct function to override for Odoo 18.
* The useBarcodeReader hook in ProductScreen directs product-related scans to this method.
*/

async _barcodeProductAction(code) {
const barcode = code.code;

// Our custom logic for weight-embedded barcodes
if (barcode && barcode.length === 10 && barcode.startsWith('0') && /^\d+$/.test(barcode)) {
const product_barcode = barcode.substring(0, 5).replace(/^0+/, '');
const weight = parseFloat(barcode.substring(5)) / 1000.0;

// Create a mock code object for the product search
const productCode = { code: product_barcode, type: 'product' };
const product = await this._getProductByBarcode(productCode);

if (product) {
// Product found. Call the same function as the original method,
// but inject our custom quantity into the options object.
await this.pos.addLineToCurrentOrder(
{ product_id: product },
{ code, quantity: weight }, // Pass original code and new quantity
product.needToConfigure()
);
this.numberBuffer.reset(); // Reset buffer like the original function
return; // Stop further processing
} else {
// Product not found, show a notification.
this.pos.env.services.notification.add(
_t("Product with barcode '%s' not found.", product_barcode),
{ type: 'danger' }
);
return;
}
}

// If it's not our custom weight barcode, fall back to the original Odoo method.
return await super._barcodeProductAction(code);
}
});

The module installs successfully, but barcode scanning does not trigger my custom logic.

Any help would be greatly appreciated.

Thank you.

0
Avatar
Discard
Avatar
Vivek Kundaliya
Best Answer

The issue is that in Odoo 18, the POS barcode scanning architecture was refactored. The _barcodeProductAction method may not be the correct hook to override.\n\nHere are the key fixes:\n\n1. Check the correct method to patch. In Odoo 18 POS, barcode scanning goes through the BarcodeReader service, not directly through ProductScreen. Check the Odoo 18 source at point_of_sale/static/src/app/barcode/barcode_reader.js to find the method that processes product barcodes. The method name may have changed from Odoo 17.\n\n2. Verify your patch is being applied by adding a console.log at the top of your patched method. If the log never appears, your patch target is wrong.\n\n3. Recommended alternative: use Odoo's built-in Barcode Nomenclature. This is the native Odoo way and requires zero JavaScript:\n- Go to Inventory > Configuration > Barcode Nomenclatures\n- Add a rule with Type = Weighted Product and configure the pattern to match your 0PPPPWWWWW format\n- Odoo will automatically parse the product code and weight from the barcode\n\nThe barcode nomenclature approach is strongly recommended as it requires no custom code, works with standard Odoo, and survives version upgrades without breaking.

0
Avatar
Discard
Enjoying the discussion? Don't just read, join in!

Create an account today to enjoy exclusive features and engage with our awesome community!

Sign up
Related Posts Replies Views Activity
Odoo 19 POS Pay Later – Need Review of Custom Implementation
javascript pos
Avatar
0
May 26
684
I am customizing the POS receipt in Odoo 19.
javascript pos
Avatar
0
May 26
688
Can anyone correct my code-iam coustmizing odoo 19 defualt pos reciept Solved
javascript pos
Avatar
Avatar
1
May 26
1123
Odoo 19 POS Receipt Customization – Remove Default Unit Price and Show Custom MRP Line
javascript pos
Avatar
1
May 26
805
Barcode scanning on POS Solved
pos barcode
Avatar
Avatar
Avatar
2
Oct 25
12689
Community
  • Tutorials
  • Documentation
  • Forum
Open Source
  • Download
  • Github
  • Runbot
  • Translations
Services
  • Odoo.sh Hosting
  • Support
  • Upgrade
  • Custom Developments
  • Education
  • Find an Accountant
  • Find a Partner
  • Become a Partner
About us
  • Our company
  • Brand Assets
  • Contact us
  • Jobs
  • Events
  • Podcast
  • Blog
  • Customers
  • Legal • Privacy
  • Security
الْعَرَبيّة Català 简体中文 繁體中文 (台灣) Čeština Dansk Nederlands English Suomi Français Deutsch हिंदी Bahasa Indonesia Italiano 日本語 한국어 (KR) Lietuvių kalba Język polski Português (BR) română русский язык Slovenský jazyk Slovenščina Español (América Latina) Español Svenska ภาษาไทย Türkçe українська Tiếng Việt

Odoo is a suite of open source business apps that cover all your company needs: CRM, eCommerce, accounting, inventory, point of sale, project management, etc.

Odoo's unique value proposition is to be at the same time very easy to use and fully integrated.

Website made with

Odoo Experience on YouTube

1. Use the live chat to ask your questions.
2. The operator answers within a few minutes.

Live support on Youtube
Watch now