Overslaan naar inhoud
Odoo Menu
  • Aanmelden
  • Probeer het gratis
  • Apps
    Financiën
    • Boekhouding
    • Facturatie
    • Onkosten
    • Spreadsheet (BI)
    • Documenten
    • Ondertekenen
    Verkoop
    • CRM
    • Verkoop
    • Kassasysteem winkel
    • Kassasysteem Restaurant
    • Abonnementen
    • Verhuur
    Websites
    • Websitebouwer
    • E-commerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Bevoorradingsketen
    • Voorraad
    • Productie
    • PLM
    • Inkoop
    • Onderhoud
    • Kwaliteit
    Personeelsbeheer
    • Werknemers
    • Werving & Selectie
    • Verlof
    • Evaluaties
    • Aanbevelingen
    • Wagenpark
    Marketing
    • Social media Marketing
    • E-mailmarketing
    • SMS Marketing
    • Evenementen
    • Marketingautomatisering
    • Enquêtes
    Diensten
    • Project
    • Urenstaten
    • Buitendienst
    • Helpdesk
    • Planning
    • Afspraken
    Productiviteit
    • Chat
    • Goedkeuringen
    • IoT
    • VoIP
    • Kennis
    • WhatsApp
    Apps van derden Odoo Studio Odoo Cloud Platform
  • Bedrijfstakken
    Detailhandel
    • Boekhandel
    • kledingwinkel
    • Meubelzaak
    • Supermarkt
    • Bouwmarkt
    • Speelgoedwinkel
    Food & Hospitality
    • Bar en Pub
    • Restaurant
    • Fastfood
    • Guest House
    • Drankenhandelaar
    • Hotel
    Real Estate
    • Real Estate Agency
    • Architectenbureau
    • Bouw
    • Vastgoedbeheer
    • Tuinieren
    • Vereniging van eigenaren
    Consulting
    • Accounting Firm
    • Odoo Partner
    • Marketingbureau
    • Advocatenkantoor
    • Talentenwerving
    • Audit & Certificering
    Productie
    • Textile
    • Metal
    • Furnitures
    • Food
    • Brewery
    • Relatiegeschenken
    Gezondheid & Fitness
    • Sportclub
    • Opticien
    • Fitnesscentrum
    • Wellness-medewerkers
    • Apotheek
    • Kapper
    Trades
    • Klusjesman
    • IT-hardware & support
    • Solar Energy Systems
    • Schoenmaker
    • Schoonmaakdiensten
    • HVAC Services
    Others
    • Nonprofit Organization
    • Milieuagentschap
    • Verhuur van Billboards
    • Fotograaf
    • Fietsleasing
    • Softwareverkoper
    Browse all Industries
  • Community
    Leren
    • Tutorials
    • Documentatie
    • Certificeringen
    • Training
    • Blog
    • Podcast
    Versterk het onderwijs
    • Onderwijs- programma
    • Scale Up! Business Game
    • Bezoek Odoo
    Download de Software
    • Downloaden
    • Vergelijk edities
    • Releases
    Werk samen
    • Github
    • Forum
    • Evenementen
    • Vertalingen
    • Word een Partner
    • Services for Partners
    • Registreer je accountantskantoor
    Diensten
    • Vind een partner
    • Vind een boekhouder
    • Een adviseur ontmoeten
    • Implementatiediensten
    • Klantreferenties
    • Ondersteuning
    • Upgrades
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Vraag een demo aan
  • Prijzen
  • Help

Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:

  • CRM
  • e-Commerce
  • Boekhouding
  • Voorraad
  • PoS
  • Project
  • MRP
All apps
Je moet geregistreerd zijn om te kunnen communiceren met de community.
Alle posts Personen Badges
Labels (Bekijk alle)
odoo accounting v14 pos v15
Over dit forum
Je moet geregistreerd zijn om te kunnen communiceren met de community.
Alle posts Personen Badges
Labels (Bekijk alle)
odoo accounting v14 pos v15
Over dit forum
Help

Odoo 18 POS - Discount Button Group Permissions Not Working

Inschrijven

Ontvang een bericht wanneer er activiteit is op deze post

Deze vraag is gerapporteerd
javascriptdevelopment
2 Antwoorden
1734 Weergaven
Avatar
Samar Guicha

Problem:

I'm trying to disable the POS discount button for users without the proper group permissions, but my implementation either:

  1. The cashier object is undefined when checking permissions
  2. The button either shows for all users or is disabled for everyone

Current Implementation:

1. JavaScript Patch (PosAccessRight.js):

patch(ProductScreen.prototype, {
    getNumpadButtons() {
        const originalButtons = super.getNumpadButtons();
        try {
            const pos = this.env.services.pos;
            const cashier = pos.globalState?.get_cashier() || pos.globalState?.cashier;
            const hasDiscountGroup = cashier?.hasGroupDiscount || false;
            
            return originalButtons.map(button => ({
                ...button,
                ...((button.value === "discount" || button.value === "price") && {
                    disabled: !hasDiscountGroup
                })
            }));
        } catch (error) {
            console.error("Button modification failed:", error);
            return originalButtons;
        }
    }
});

2. Python Extension (res_users.py):

class ResUsers(models.Model):
    _inherit = 'res.users'
    
    def _load_pos_data(self, data):
        res = super()._load_pos_data(data)
        user = self.env["res.users"].browse(res["data"][0]["id"])
        res["data"][0]["hasGroupDiscount"] = user.has_group('pos_access_right.group_discount')
        return res

Key Questions:

  1. Why is pos.globalState.cashier undefined during button rendering?
  2. What's the correct way to access the logged-in cashier's permissions in Odoo 18 POS?
  3. Where should I properly check group permissions if not in getNumpadButtons?

Environment:

  • Odoo 18.0 Community
  • Custom POS module (depends on point_of_sale)
  • PostgreSQL 13 / Ubuntu 20.04
  • Chrome 


0
Avatar
Annuleer
Avatar
Samar Guicha
Auteur Beste antwoord

0
Avatar
Annuleer
Avatar
STAFFINSIDE
Beste antwoord

Issues

  1. pos.globalState.get_cashier() is undefined:
    • The cashier object is populated only after the POS session is fully loaded and a user is logged in.
    • If you're patching getNumpadButtons() too early (before the cashier is set), the cashier object will be undefined.
  2. Why the button shows for all or none:
    • Because you're relying on cashier.hasGroupDiscount, and if cashier is undefined, your fallback disables the logic or treats all users the same.

You should defer the permission check to runtime and not during the initial button setup, or ensure the cashier object is guaranteed to be available before patching.

Fix: Check cashier in setup() or use reactive model

Instead of patching getNumpadButtons(), consider overriding the setup() method and dynamically updating the button state once the cashier is available. Like this:

import { patch } from "@web/core/utils/patch"; import { ProductScreen } from "@point_of_sale/app/screens/product_screen/product_screen"; patch(ProductScreen.prototype, { setup() { super.setup(); this.env.services.pos.bus.on('cashier-changed', null, () => { this.render(); // re-render when cashier changes }); }, get numpadButtons() { const buttons = super.numpadButtons; const cashier = this.env.services.pos.get_cashier?.() || null; const hasGroupDiscount = cashier?.hasGroupDiscount || false; return buttons.map(button => { if (["discount", "price"].includes(button.value)) { return { ...button, disabled: !hasGroupDiscount, }; } return button; }); }, });

Python Fix: Ensure field is loaded to POS user data

Your Python code seems mostly correct, but verify the custom group external ID is correct and ensure it's added to the loaded user data:

python

CopiarEditar

class ResUsers(models.Model): _inherit = 'res.users' def _load_pos_data(self, data): res = super()._load_pos_data(data) for record in res["data"]: user = self.browse(record["id"]) record["hasGroupDiscount"] = user.has_group('pos_access_right.group_discount') return res

Also, confirm that hasGroupDiscount is being passed to the JS frontend via the POS session config and is accessible in the cashier object.

Group Access Configuration

Make sure:

  • Your custom group group_discount exists and has the correct external ID (pos_access_right.group_discount).
  • POS users are correctly added to the group via Settings > Users > Access Rights.

0
Avatar
Annuleer
Samar Guicha
Auteur

Thank you for your suggested solution! I implemented your approach, but encountered an error : TypeError: this.env.services.pos.bus.on is not a function

Geniet je van het gesprek? Blijf niet alleen lezen, doe ook mee!

Maak vandaag nog een account aan om te profiteren van exclusieve functies en deel uit te maken van onze geweldige community!

Aanmelden
Gerelateerde posts Antwoorden Weergaven Activiteit
How can I use my only web url domain using odoo?
javascript development
Avatar
Avatar
1
sep. 25
1201
How to Load Related Many2Many Data (pos.ticket.type) into the Frontend?
javascript development
Avatar
0
jun. 25
1615
¿Cómo puedo crear un Dashboard con KPIs y gráficos con Chart.js?
javascript development
Avatar
0
apr. 25
1852
Odoo icon change Opgelost
javascript development
Avatar
Avatar
2
jan. 25
2283
How to get the Model name and Action of the Current page? v7 Opgelost
javascript development
Avatar
Avatar
Avatar
2
feb. 24
13496
Community
  • Tutorials
  • Documentatie
  • Forum
Open Source
  • Downloaden
  • Github
  • Runbot
  • Vertalingen
Diensten
  • Odoo.sh Hosting
  • Ondersteuning
  • Upgrade
  • Gepersonaliseerde ontwikkelingen
  • Onderwijs
  • Vind een boekhouder
  • Vind een partner
  • Word een Partner
Over ons
  • Ons bedrijf
  • Merkelementen
  • Neem contact met ons op
  • Vacatures
  • Evenementen
  • Podcast
  • Blog
  • Klanten
  • Juridisch • Privacy
  • Beveiliging
الْعَرَبيّة 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 ภาษาไทย Türkçe українська Tiếng Việt

Odoo is een suite van open source zakelijke apps die aan al je bedrijfsbehoeften voldoet: CRM, E-commerce, boekhouding, inventaris, kassasysteem, projectbeheer, enz.

Odoo's unieke waardepropositie is om tegelijkertijd zeer gebruiksvriendelijk en volledig geïntegreerd te zijn.

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