تخطي للذهاب إلى المحتوى
أودو القائمة
  • تسجيل الدخول
  • جرب مجاناً
  • التطبيقات
    المالية
    • المحاسبة
    • فوترة
    • النفقات
    • جدول البيانات (BI)
    • المستندات
    • توقيع إلكتروني
    المبيعات
    • إدارة علاقات العملاء
    • المبيعات
    • نقطة البيع للمتاجر
    • نقطة البيع للمطاعم
    • الاشتراكات
    • تأجير
    المواقع الإلكترونية
    • أداة بناء المواقع الإلكترونية
    • متاجر إلكترونية
    • مدونة
    • المنتدى
    • دردشة مباشرة
    • التعليم الإلكتروني
    سلسلة التوريد
    • المستودعات
    • التصنيع
    • إدارة دورة حياة المنتج
    • المشتريات
    • الصيانة
    • الجودة
    الموارد البشرية
    • موظفون
    • التوظيف
    • إجازة عمل
    • التقييمات
    • الإحالات
    • تطبيق الأسطول
    التسويق
    • التسويق الإجتماعي
    • التسويق عبر البريد الإلكتروني
    • التسويق عبر الرسائل النصية
    • فعاليات
    • أتمتة التسويق
    • الاستطلاعات
    الخدمات
    • المشاريع
    • الجداول الزمنية
    • الخدمة الميدانية
    • مكتب المساعدة
    • التخطيط
    • مواعيد
    اﻹنتاجية
    • مناقشة
    • الموافقات
    • إنترنت الأشياء "IoT"
    • بروتوكول ربط المحادثات الصوتية عبر الإنترنت
    • المعرفة
    • WhatsApp
    التطبيقات الخارجية ستوديو أودو منصة أودو السحابية
  • قطاعات الأعمال
    البيع بالتجزئة
    • متجر كتب
    • متجر ملابس
    • متجر أثاث
    • متجر بقالة
    • متجر معدات
    • متجر ألعاب
    الطعام والضيافة
    • بار وحانة
    • المطعم
    • مطعم للوجبات السريعة
    • نزل للضيوف
    • موزّع مشروبات
    • فندق
    العقارات
    • وكالة عقارات
    • شركة هندسة معمارية
    • البناء
    • إدارة العقارات
    • العناية بالحدائق
    • اتحاد مُلاّك العقارات
    استشارة
    • مؤسسة محاسبية
    • شريك أودو
    • وكالة تسويقية
    • منشأة قانونية
    • استقطاب المواهب
    • التدقيق والتوثيق
    التصنيع
    • الأقمشة
    • معدني
    • الأثاث
    • الطعام
    • مصنع خمور
    • هدايا الشركات
    الصحة واللياقة البدنية
    • نادي رياضي
    • متجر نظارات
    • مركز لياقة بدنية
    • الممارسون الصحيون
    • صيدلية
    • صالون تصفيف الشعر
    التجارة
    • عامل صيانة
    • الأجهزة والمعدات التقنية ودعمها
    • أنظمة الطاقة الشمسية
    • صانع أحذية
    • خدمات التنظيف
    • خدمات التكييف (HVAC)
    غير ذلك
    • منظمة غير ربحية
    • وكالة بيئية
    • تأجير لوحات إعلانية
    • تصوير
    • تأجير دراجات
    • بائع وسيط للبرمجيات
    تصفح كافة قطاعات الأعمال
  • مجتمع أودو
    تعلم
    • دروس
    • التوثيق
    • شهادات
    • التدريب
    • مدونة
    • بودكاست
    قم بتعزيز التعليم
    • برنامج تعليم
    • Scale UP! لعبة الأعمال
    • قم بزيارة أودو
    احصل على البرنامج
    • تحميل
    • قارنْ الإصدارات
    • إطلاق
    تعاون
    • جيت هاب "Github"
    • المنتدى
    • فعاليات
    • الترجمات
    • كنْ شريكاً
    • خدمات الشركاء
    • سجل مكتب المحاسبة الخاص بك
    احصل على الخدمات
    • اعثر على شريك
    • اعثر على محاسب
    • قابل أحد مرشدي الأعمال
    • خدمات التنفيذ
    • مراجع العملاء
    • الدعم
    • الترقيات
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    الحصول على عرض توضيحي
  • الأسعار
  • المساعدة

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

  • إدارة علاقات العملاء
  • e-Commerce
  • المحاسبة
  • المخزون
  • PoS
  • المشروع
  • MRP
All apps
يجب أن تكون مسجلاً حتى تتفاعل مع المجتمع.
كافة المنشورات الأفراد الشارات
علامات التصنيف (عرض الكل)
odoo accounting v14 pos v15
حول هذا المنتدى
يجب أن تكون مسجلاً حتى تتفاعل مع المجتمع.
كافة المنشورات الأفراد الشارات
علامات التصنيف (عرض الكل)
odoo accounting v14 pos v15
حول هذا المنتدى
المساعدة

Odoo 18 POS - Discount Button Group Permissions Not Working

اشتراك

تسلم الإشعارات عندما يكون هناك نشاط في هذا المنشور

لقد تم الإبلاغ عن هذا السؤال
javascriptdevelopment
2 الردود
1864 أدوات العرض
الصورة الرمزية
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
الصورة الرمزية
إهمال
الصورة الرمزية
Samar Guicha
الكاتب أفضل إجابة

0
الصورة الرمزية
إهمال
الصورة الرمزية
STAFFINSIDE
أفضل إجابة

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
الصورة الرمزية
إهمال
Samar Guicha
الكاتب

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

هل أعجبك النقاش؟ لا تكن مستمعاً فقط. شاركنا!

أنشئ حساباً اليوم لتستمتع بالخصائص الحصرية، وتفاعل مع مجتمعنا الرائع!

تسجيل
المنشورات ذات الصلة الردود أدوات العرض النشاط
How can I use my only web url domain using odoo?
javascript development
الصورة الرمزية
الصورة الرمزية
1
سبتمبر 25
1309
How to Load Related Many2Many Data (pos.ticket.type) into the Frontend?
javascript development
الصورة الرمزية
0
يونيو 25
1713
¿Cómo puedo crear un Dashboard con KPIs y gráficos con Chart.js?
javascript development
الصورة الرمزية
0
أبريل 25
1898
Odoo icon change تم الحل
javascript development
الصورة الرمزية
الصورة الرمزية
2
يناير 25
2388
How to get the Model name and Action of the Current page? v7 تم الحل
javascript development
الصورة الرمزية
الصورة الرمزية
الصورة الرمزية
2
فبراير 24
13600
المجتمع
  • دروس
  • التوثيق
  • المنتدى
مصدر مفتوح
  • تحميل
  • جيت هاب "Github"
  • المشغل الآلي رنبوت
  • الترجمات
خدماتنا
  • استضافة أودو إس إتش
  • الدعم
  • الترقية
  • التطويرات المخصصة
  • التعليم
  • اعثر على محاسب
  • اعثر على شريك
  • كنْ شريكاً
معلومات عنا
  • شركتنا
  • أصول العلامة التجارية
  • اتصلْ بنا
  • الوظائف
  • فعاليات
  • بودكاست
  • مدونة
  • عملاء
  • قانوني • الخصوصية
  • الحماية
الْعَرَبيّة 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

أودو هو عبارة عن مجموعة من تطبيقات الأعمال مفتوحة المصدر التي تغطي جميع احتياجات شركتك، مثل: إدارة علاقات العملاء والتجارة الإلكترونية والمحاسبة والمخزون ونقاط البيع وإدارة المشاريع وما إلى ذلك.

ما يجعل من أودو مميزاً هو هدفه بأن يكون سهل الاستخدام للغاية ومتكاملاً تمامًا في الوقت ذاته.

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