Skip to Content
Odoo Menu
  • Zaloguj się
  • Wypróbuj za darmo
  • Aplikacje
    Finanse
    • Księgowość
    • Fakturowanie
    • Wydatki
    • Arkusz kalkulacyjny (BI)
    • Dokumenty
    • Podpisy
    Sprzedaż
    • CRM
    • Sprzedaż
    • PoS Sklep
    • PoS Restauracja
    • Subskrypcje
    • Wypożyczalnia
    Strony Internetowe
    • Kreator Stron Internetowych
    • eCommerce
    • Blog
    • Forum
    • Czat na Żywo
    • eLearning
    Łańcuch dostaw
    • Magazyn
    • Produkcja
    • PLM
    • Zakupy
    • Konserwacja
    • Jakość
    Zasoby Ludzkie
    • Pracownicy
    • Rekrutacja
    • Urlopy
    • Ocena pracy
    • Polecenia Pracownicze
    • Flota
    Marketing
    • Marketing Społecznościowy
    • E-mail Marketing
    • SMS Marketing
    • Wydarzenia
    • Automatyzacja Marketingu
    • Ankiety
    Usługi
    • Projekt
    • Ewidencja czasu pracy
    • Usługi Terenowe
    • Helpdesk
    • Planowanie
    • Spotkania
    Produktywność
    • Dyskusje
    • Zatwierdzenia
    • IoT
    • VoIP
    • Baza wiedzy
    • WhatsApp
    Aplikacje trzecich stron Studio Odoo Odoo Cloud Platform
  • Branże
    Sprzedaż detaliczna
    • Księgarnia
    • Sklep odzieżowy
    • Sklep meblowy
    • Sklep spożywczy
    • Sklep z narzędziami
    • Sklep z zabawkami
    Żywienie i hotelarstwo
    • Bar i Pub
    • Restauracja
    • Fast Food
    • Pensjonat
    • Dystrybutor napojów
    • Hotel
    Agencja nieruchomości
    • Agencja nieruchomości
    • Biuro architektoniczne
    • Budowa
    • Zarządzanie nieruchomościami
    • Ogrodnictwo
    • Stowarzyszenie właścicieli nieruchomości
    Doradztwo
    • Biuro księgowe
    • Partner Odoo
    • Agencja marketingowa
    • Kancelaria prawna
    • Agencja rekrutacyjna
    • Audyt i certyfikacja
    Produkcja
    • Tekstylia
    • Metal
    • Meble
    • Jedzenie
    • Browar
    • Prezenty firmowe
    Zdrowie & Fitness
    • Klub sportowy
    • Salon optyczny
    • Centrum fitness
    • Praktycy Wellness
    • Apteka
    • Salon fryzjerski
    Transakcje
    • Złota rączka
    • Wsparcie Sprzętu IT
    • Systemy energii słonecznej
    • Szewc
    • Firma sprzątająca
    • Usługi HVAC
    Inne
    • Organizacja non-profit
    • Agencja Środowiskowa
    • Wynajem billboardów
    • Fotografia
    • Leasing rowerów
    • Sprzedawca oprogramowania
    Przeglądaj wszystkie branże
  • Community
    Ucz się
    • Samouczki
    • Dokumentacja
    • Certyfikacje
    • Szkolenie
    • Blog
    • Podcast
    Pomóż w nauce innym
    • Program Edukacyjny
    • Scale Up! Gra biznesowa
    • Odwiedź Odoo
    Skorzystaj z oprogramowania
    • Pobierz
    • Porównaj edycje
    • Wydania
    Współpracuj
    • Github
    • Forum
    • Wydarzenia
    • Tłumaczenia
    • Zostań partnerem
    • Usługi dla partnerów
    • Zarejestruj swoją firmę rachunkową
    Skorzystaj z usług
    • Znajdź partnera
    • Znajdź księgowego
    • Spotkaj się z doradcą
    • Usługi wdrożenia
    • Opinie klientów
    • Wsparcie
    • Aktualizacje
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Zaplanuj demo
  • Cennik
  • Pomoc

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

  • CRM
  • e-Commerce
  • Księgowość
  • Zapasy
  • PoS
  • Projekt
  • MRP
All apps
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
Wszystkie posty Osoby Odznaki
Tagi (Zobacz wszystko)
odoo accounting v14 pos v15
O tym forum
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
Wszystkie posty Osoby Odznaki
Tagi (Zobacz wszystko)
odoo accounting v14 pos v15
O tym forum
Pomoc

How to get groups of user logged in

Zaprenumeruj

Otrzymaj powiadomienie o aktywności w tym poście

To pytanie dostało ostrzeżenie
userinvisiblegroupsloggedodooV8
4 Odpowiedzi
27406 Widoki
Awatar
Jesús Marco

Hello everybody.

    I am trying to obtain the groups which the logged in user belong to; after this what I´m trying to achieve is to compare if the logged in user belongs to a certain group in order to create a boolean flag which later on, I will use un my xml view to conditioned a page to be invisible or not.

I am using odoo 8 and the code I have until now is the following:

'make_invisible':fields.function(get_user, string="Is Invisible")
def get_user(self, cr, uid, ids, context=None): 
    _logger.debug("This is GET_USER method ")
    result = {}
    user = self.pool.get('res.users').browse(cr, uid, user_id, context=context)
    if user.has_group('hr_employee.NewGroup'):
        _logger.debug(":::True:::")
        return False
    else:
        _logger.debug(":::False:::")
        return False

Another question is: with the "has_group" should I use the group name that I wrote through the GUI or the XML ID??

Currently I am getting:

TypeError: get_user() takes at most 5 arguments (7 given)

0
Awatar
Odrzuć
Kabeer KB

Define your function like this

` def get_user (self, cr, uid, ids, name, arg, context=None):

//statement

Awatar
Jesús Marco
Autor Najlepsza odpowiedź

Hi Sehrish, Kabeer thanks for the tips, although I think I´m getting closer, I still can´t make it work, I went coding with method 2 (Sehrish) using it inside a computed field but several exceptions have been occurring:

field:

'make_invisible':fields.function(get_user, string="Is Invisible", readonly=0)

XML:

<field name="make_invisible"/>

First try:

def get_user(self, cr, uid, ids, name, arg, context=None):   
    _logger.debug("This is GET_USER method ") 
    desired_group_name = self.env['res.groups'].search([('name','=','GM')]) 
    is_desired_group = self.env.user.id in desired_group_name.users.ids 
    self.make_visible=is_desired_group

got:

desired_group_name = self.env['res.groups'].search([('name','=','GM')]) 
AttributeError: 'hr.employee' object has no attribute 'env'

Second try: (try to use api.multi to avoid previous error)

@api.multi 
def get_user(self, cr, uid, ids, name, arg, context=None):
    _logger.debug("This is GET_USER method ")
    desired_group_name = self.env['res.groups'].search([('name','=','GM')])
    is_desired_group = self.env.user.id in desired_group_name.users.ids 
    self.make_visible=is_desired_group

got:

File "/opt/odoo/openerp/api.py", line 363, in old_api 
    result = method(recs, *args, **kwargs)
TypeError: get_user() takes at least 6 arguments (4 given)

Third try: (use different function definition with api.multi)

@api.multi 
def get_user(self):
    _logger.debug("This is GET_USER method ")
    desired_group_name = self.env['res.groups'].search([('name','=','GM')])
    is_desired_group = self.env.user.id in desired_group_name.users.ids 
    self.make_visible=is_desired_group

got:

File "/opt/odoo/openerp/api.py", line 709, in __new__  
    self.cr, self.uid, self.context = self.args = (cr, uid, frozendict(context)) 
ValueError: dictionary update sequence element #0 has length 1; 2 is required

Fouth try: (tried to use original function definition with pool.get instead of env)

def get_user(self, cr, uid, ids, name, arg, context=None):  
    _logger.debug("This is GET_USER method ")
    #desired_group_name = self.env['res.groups'].search([('name','=','GM')])
    desired_group_name = self.pool.get('res.groups').search([('name','=','GM')])
    is_desired_group = self.env.user.id in desired_group_name.users.ids 
    self.make_visible=is_desired_group

got:

File "/opt/odoo/openerp/api.py", line 241, in wrapper  
    return old_api(self, *args, **kwargs) 
TypeError: search() takes at least 4 arguments (2 given)

Please help, dont know what else to do and what am I doing wrong!!!

0
Awatar
Odrzuć
Awatar
Sehrish
Najlepsza odpowiedź

How to check login user group. The need of this post is, to sometime we need to visible invisible some filed on the basis of login user group or we want to perform some action on the basis of login user. To do so we need to get login user group. There are two ways

Method 1:

user = self.env['res.users'].sudo().search([('login','=',self.env.user.login)]) 
desired_group_user = self.env['res.groups'].sudo().search([('name','=','desired_group_name')]) 
query = "select gid from res_groups_users_rel where gid ={} and uid={}".format(desired_group_user.id,user.id)
self.env.cr.execute(query) is_desired_group = self.env.cr.fetchone() 
desired_user_gr = self.env['res.groups'].sudo().search([('id','=',is_desired_group)])

Method 2:

desired_group_name = self.env['res.groups'].search([('name','=','desired_group_name')])
is_desired_group = self.env.user.id in desired_group_name.users.ids

For further info about code and description visit: http://learnopenerp.blogspot.com/2017/10/how-to-check-login-user-group-in-odoo.html

This is the answer of your first part of question. If you want to visible invisible fields on some condition read: http://learnopenerp.blogspot.com/2016/10/how-to-visible-and-invisible-fields-in.html

0
Awatar
Odrzuć
Sehrish

How to check/find login user group: http://learnopenerp.blogspot.com/2017/10/how-to-check-login-user-group-in-odoo.html

How to visible and invisible fields in odoo: http://learnopenerp.blogspot.com/2016/10/how-to-visible-and-invisible-fields-in.html

Podoba Ci się ta dyskusja? Dołącz do niej!

Stwórz konto dzisiaj, aby cieszyć się ekskluzywnymi funkcjami i wchodzić w interakcje z naszą wspaniałą społecznością!

Zarejestruj się
Powiązane posty Odpowiedzi Widoki Czynność
how to get the logged user Rozwiązane
user logged
Awatar
Awatar
Awatar
2
lut 24
15225
Custom code: Field is restricted to the group(s) base.group_no_one. Rozwiązane
invisible groups modifier
Awatar
Awatar
1
kwi 25
1893
how to make button available only for the requester ?
invisible context groups
Awatar
Awatar
Awatar
2
lis 19
3876
Automatically filling in field with the user name - Odoo8
user automatic odooV8
Awatar
Awatar
1
cze 15
3743
set a new menu for specific user
settings user odooV8
Awatar
0
maj 15
3887
Społeczność
  • Samouczki
  • Dokumentacja
  • Forum
Open Source
  • Pobierz
  • Github
  • Runbot
  • Tłumaczenia
Usługi
  • Hosting Odoo.sh
  • Wsparcie
  • Aktualizacja
  • Indywidualne rozwiązania
  • Edukacja
  • Znajdź księgowego
  • Znajdź partnera
  • Zostań partnerem
O nas
  • Nasza firma
  • Zasoby marki
  • Skontaktuj się z nami
  • Oferty pracy
  • Wydarzenia
  • Podcast
  • Blog
  • Klienci
  • Informacje prawne • Prywatność
  • Bezpieczeństwo Odoo
الْعَرَبيّة 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 to pakiet aplikacji biznesowych typu open source, które zaspokoją wszystkie potrzeby Twojej firmy: CRM, eCommerce, księgowość, inwentaryzacja, punkt sprzedaży, zarządzanie projektami itp.

Unikalną wartością Odoo jest to, że jest jednocześnie bardzo łatwe w użyciu i w pełni zintegrowane.

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