Skip to Content
Odoo Menu
  • Prijavi
  • Try it free
  • Aplikacije
    Finance
    • Knjigovodstvo
    • Obračun
    • Stroški
    • Spreadsheet (BI)
    • Dokumenti
    • Podpisovanje
    Prodaja
    • CRM
    • Prodaja
    • POS Shop
    • POS Restaurant
    • Naročnine
    • Najem
    Spletne strani
    • Website Builder
    • Spletna trgovina
    • Blog
    • Forum
    • Pogovor v živo
    • eUčenje
    Dobavna veriga
    • Zaloga
    • Proizvodnja
    • PLM
    • Nabava
    • Vzdrževanje
    • Kakovost
    Kadri
    • Kadri
    • Kadrovanje
    • Odsotnost
    • Ocenjevanja
    • Priporočila
    • Vozni park
    Marketing
    • Družbeno Trženje
    • Email Marketing
    • SMS Marketing
    • Dogodki
    • Avtomatizacija trženja
    • Ankete
    Storitve
    • Projekt
    • Časovnice
    • Storitve na terenu
    • Služba za pomoč
    • Načrtovanje
    • Termini
    Produktivnost
    • Razprave
    • Odobritve
    • IoT
    • Voip
    • Znanje
    • WhatsApp
    Third party apps Odoo Studio Odoo Cloud Platform
  • Industrije
    Trgovina na drobno
    • Book Store
    • Trgovina z oblačili
    • Trgovina s pohištvom
    • Grocery Store
    • Trgovina s strojno opremo računalnikov
    • Trgovina z igračami
    Food & Hospitality
    • Bar and Pub
    • Restavracija
    • Hitra hrana
    • Guest House
    • Beverage Distributor
    • Hotel
    Nepremičnine
    • Real Estate Agency
    • Arhitekturno podjetje
    • Gradbeništvo
    • Estate Management
    • Vrtnarjenje
    • Združenje lastnikov nepremičnin
    Svetovanje
    • Računovodsko podjetje
    • Odoo Partner
    • Marketinška agencija
    • Law firm
    • Pridobivanje talentov
    • Audit & Certification
    Proizvodnja
    • Tekstil
    • Metal
    • Pohištvo
    • Hrana
    • Brewery
    • Poslovna darila
    Health & Fitness
    • Športni klub
    • Trgovina z očali
    • Fitnes center
    • Wellness Practitioners
    • Lekarna
    • Frizerski salon
    Trades
    • Handyman
    • IT Hardware & Support
    • Sistemi sončne energije
    • Izdelovalec čevljev
    • Čistilne storitve
    • HVAC Services
    Ostali
    • Neprofitna organizacija
    • Agencija za okolje
    • Najem oglasnih panojev
    • Fotografija
    • Najem koles
    • Prodajalec programske opreme
    Browse all Industries
  • Skupnost
    Learn
    • Tutorials
    • Dokumentacija
    • Certifikati
    • Šolanje
    • Blog
    • Podcast
    Empower Education
    • Education Program
    • Scale Up! Business Game
    • Visit Odoo
    Get the Software
    • Prenesi
    • Compare Editions
    • Releases
    Collaborate
    • Github
    • Forum
    • Dogodki
    • Prevodi
    • Become a Partner
    • Services for Partners
    • Register your Accounting Firm
    Get Services
    • Find a Partner
    • Find an Accountant
    • Meet an advisor
    • Implementation Services
    • Sklici kupca
    • Podpora
    • Upgrades
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Get a demo
  • Določanje cen
  • Pomoč

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

  • CRM
  • e-Commerce
  • Knjigovodstvo
  • Zaloga
  • PoS
  • Projekt
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Ključne besede (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Ključne besede (View all)
odoo accounting v14 pos v15
About this forum
Pomoč

Odoo 18 POS - Discount Button Group Permissions Not Working

Naroči se

Get notified when there's activity on this post

This question has been flagged
javascriptdevelopment
2 Odgovori
1877 Prikazi
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
Opusti
Avatar
Samar Guicha
Avtor Best Answer

0
Avatar
Opusti
Avatar
STAFFINSIDE
Best Answer

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
Opusti
Samar Guicha
Avtor

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

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

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

Prijavi
Related Posts Odgovori Prikazi Aktivnost
How can I use my only web url domain using odoo?
javascript development
Avatar
Avatar
1
sep. 25
1328
How to Load Related Many2Many Data (pos.ticket.type) into the Frontend?
javascript development
Avatar
0
jun. 25
1719
¿Cómo puedo crear un Dashboard con KPIs y gráficos con Chart.js?
javascript development
Avatar
0
apr. 25
1901
Odoo icon change Solved
javascript development
Avatar
Avatar
2
jan. 25
2401
How to get the Model name and Action of the Current page? v7 Solved
javascript development
Avatar
Avatar
Avatar
2
feb. 24
13612
Community
  • Tutorials
  • Dokumentacija
  • Forum
Open Source
  • Prenesi
  • Github
  • Runbot
  • Prevodi
Services
  • Odoo.sh Hosting
  • Podpora
  • Nadgradnja
  • Custom Developments
  • Izobraževanje
  • Find an Accountant
  • Find a Partner
  • Become a Partner
About us
  • Our company
  • Sredstva blagovne znamke
  • Kontakt
  • Zaposlitve
  • Dogodki
  • Podcast
  • Blog
  • Stranke
  • Pravno • Zasebnost
  • Varnost
الْعَرَبيّة 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 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