Skip to Content
Odoo Menú
  • Registra entrada
  • Prova-ho gratis
  • Aplicacions
    Finances
    • Comptabilitat
    • Facturació
    • Despeses
    • Full de càlcul (IA)
    • Documents
    • Signatura
    Vendes
    • CRM
    • Vendes
    • Punt de venda per a botigues
    • Punt de venda per a restaurants
    • Subscripcions
    • Lloguer
    Imatges de llocs web
    • Creació de llocs web
    • Comerç electrònic
    • Blog
    • Fòrum
    • Xat en directe
    • Aprenentatge en línia
    Cadena de subministrament
    • Inventari
    • Fabricació
    • PLM
    • Compres
    • Manteniment
    • Qualitat
    Recursos humans
    • Empleats
    • Reclutament
    • Absències
    • Avaluacions
    • Recomanacions
    • Flota
    Màrqueting
    • Màrqueting Social
    • Màrqueting per correu electrònic
    • Màrqueting per SMS
    • Esdeveniments
    • Automatització del màrqueting
    • Enquestes
    Serveis
    • Projectes
    • Fulls d'hores
    • Servei de camp
    • Suport
    • Planificació
    • Cites
    Productivitat
    • Converses
    • Artificial Intelligence
    • IoT
    • VoIP
    • Coneixements
    • WhatsApp
    Aplicacions de tercers Odoo Studio Plataforma d'Odoo al núvol
  • Sectors
    Comerç al detall
    • Llibreria
    • Botiga de roba
    • Botiga de mobles
    • Botiga d'ultramarins
    • Ferreteria
    • Botiga de joguines
    Food & Hospitality
    • Bar i pub
    • Restaurant
    • Menjar ràpid
    • Guest House
    • Distribuïdor de begudes
    • Hotel
    Immobiliari
    • Agència immobiliària
    • Estudi d'arquitectura
    • Construcció
    • Property Management
    • Jardineria
    • Associació de propietaris de béns immobles
    Consultoria
    • Empresa comptable
    • Partner d'Odoo
    • Agència de màrqueting
    • Bufet d'advocats
    • Captació de talent
    • Auditoria i certificació
    Fabricació
    • Textile
    • Metal
    • Mobles
    • Menjar
    • Brewery
    • Regals corporatius
    Salut i fitness
    • Club d'esport
    • Òptica
    • Centre de fitness
    • Especialistes en benestar
    • Farmàcia
    • Perruqueria
    Trades
    • Servei de manteniment
    • Hardware i suport informàtic
    • Sistemes d'energia solar
    • Shoe Maker
    • Serveis de neteja
    • Instal·lacions HVAC
    Altres
    • Nonprofit Organization
    • Agència del medi ambient
    • Lloguer de panells publicitaris
    • Fotografia
    • Lloguer de bicicletes
    • Distribuïdors de programari
    Browse all Industries
  • Comunitat
    Aprèn
    • Tutorials
    • Documentació
    • Certificacions
    • Formació
    • Blog
    • Pòdcast
    Potenciar l'educació
    • Programa educatiu
    • Scale-Up! El joc empresarial
    • Visita Odoo
    Obtindre el programari
    • Descarregar
    • Comparar edicions
    • Novetats de les versions
    Col·laborar
    • GitHub
    • Fòrum
    • Esdeveniments
    • Traduccions
    • Converteix-te en partner
    • Services for Partners
    • Registra la teva empresa comptable
    • Referral Program
    Obtindre els serveis
    • Troba un partner
    • Troba un comptable
    • Contacta amb un expert
    • Serveis d'implementació
    • Referències del client
    • Suport
    • Actualitzacions
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Programar una demo
  • Preus
  • Ajuda
You need to be registered to interact with the community.
All Posts People Badges
Etiquetes (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Etiquetes (View all)
odoo accounting v14 pos v15
About this forum
Ajuda

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

Subscriure's

Get notified when there's activity on this post

This question has been flagged
javascriptposbarcode
1 Respondre
563 Vistes
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
Descartar
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
Descartar
Enjoying the discussion? Don't just read, join in!

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

Registrar-se
Related Posts Respostes Vistes Activitat
Odoo 19 POS Pay Later – Need Review of Custom Implementation
javascript pos
Avatar
0
de maig 26
924
I am customizing the POS receipt in Odoo 19.
javascript pos
Avatar
0
de maig 26
951
Can anyone correct my code-iam coustmizing odoo 19 defualt pos reciept Solved
javascript pos
Avatar
Avatar
1
de maig 26
1319
Odoo 19 POS Receipt Customization – Remove Default Unit Price and Show Custom MRP Line
javascript pos
Avatar
1
de maig 26
1024
Barcode scanning on POS Solved
pos barcode
Avatar
Avatar
Avatar
2
d’oct. 25
12826
Community
  • Tutorials
  • Documentació
  • Fòrum
Codi obert
  • Descarregar
  • GitHub
  • Runbot
  • Traduccions
Serveis
  • Allotjament a Odoo.sh
  • Suport
  • Actualització
  • Desenvolupaments personalitzats
  • Educació
  • Troba un comptable
  • Troba un partner
  • Converteix-te en partner
Sobre nosaltres
  • La nostra empresa
  • Actius de marca
  • Contacta amb nosaltres
  • Llocs de treball
  • Esdeveniments
  • Pòdcast
  • Blog
  • Clients
  • Informació legal • Privacitat
  • Seguretat
الْعَرَبيّة 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 és un conjunt d'aplicacions empresarials de codi obert que cobreix totes les necessitats de la teva empresa: CRM, comerç electrònic, comptabilitat, inventari, punt de venda, gestió de projectes, etc.

La proposta única de valor d'Odoo és ser molt fàcil d'utilitzar i estar totalment integrat, ambdues alhora.

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