Skip to Content
Odoo Menu
  • Prihlásiť sa
  • Vyskúšajte zadarmo
  • Aplikácie
    Financie
    • Účtovníctvo
    • Fakturácia
    • Výdavky
    • Tabuľka (BI)
    • Dokumenty
    • Podpis
    Predaj
    • CRM
    • Predaj
    • POS Shop
    • POS Restaurant
    • Manažment odberu
    • Požičovňa
    Webstránky
    • Tvorca webstránok
    • eShop
    • Blog
    • Fórum
    • Živý chat
    • eLearning
    Supply Chain
    • Sklad
    • Výroba
    • Správa životného cyklu produktu
    • Nákup
    • Údržba
    • Manažment kvality
    Ľudské zdroje
    • Zamestnanci
    • Nábor zamestnancov
    • Voľné dni
    • Hodnotenia
    • Odporúčania
    • Vozový park
    Marketing
    • Marketing sociálnych sietí
    • Email marketing
    • SMS marketing
    • Eventy
    • Marketingová automatizácia
    • Prieskumy
    Služby
    • Projektové riadenie
    • Pracovné výkazy
    • Práca v teréne
    • Helpdesk
    • Plánovanie
    • Schôdzky
    Produktivita
    • Tímová komunikácia
    • Schvalovania
    • IoT
    • VoIP
    • Znalosti
    • WhatsApp
    Third party apps Odoo Studio Odoo Cloud Platform
  • Priemyselné odvetvia
    Retail
    • Book Store
    • Clothing Store
    • Furniture Store
    • Grocery Store
    • Hardware Store
    • Toy Store
    Food & Hospitality
    • Bar and Pub
    • Reštaurácia
    • Fast Food
    • Guest House
    • Beverage distributor
    • Hotel
    Reality
    • Real Estate Agency
    • Architecture Firm
    • Konštrukcia
    • Estate Managament
    • Gardening
    • Property Owner Association
    Poradenstvo
    • Accounting Firm
    • Odoo Partner
    • Marketing Agency
    • Law firm
    • Talent Acquisition
    • Audit & Certification
    Výroba
    • Textile
    • Metal
    • Furnitures
    • Jedlo
    • Brewery
    • Corporate Gifts
    Health & Fitness
    • Sports Club
    • Eyewear Store
    • Fitness Center
    • Wellness Practitioners
    • Pharmacy
    • Hair Salon
    Trades
    • Handyman
    • IT Hardware and Support
    • Solar Energy Systems
    • Shoe Maker
    • Cleaning Services
    • HVAC Services
    Iní
    • Nonprofit Organization
    • Environmental Agency
    • Billboard Rental
    • Photography
    • Bike Leasing
    • Software Reseller
    Browse all Industries
  • Komunita
    Vzdelávanie
    • Tutoriály
    • Dokumentácia
    • Certifikácie
    • Školenie
    • Blog
    • Podcast
    Empower Education
    • Vzdelávací program
    • Scale Up! Business Game
    • Visit Odoo
    Softvér
    • Stiahnuť
    • Porovnanie Community a Enterprise vierzie
    • Releases
    Spolupráca
    • Github
    • Fórum
    • Eventy
    • Preklady
    • Staň sa partnerom
    • Services for Partners
    • Register your Accounting Firm
    Služby
    • Nájdite partnera
    • Nájdite účtovníka
    • Meet an advisor
    • Implementation Services
    • Zákaznícke referencie
    • Podpora
    • Upgrades
    ​Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Získajte demo
  • Cenník
  • Pomoc

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

  • CRM
  • e-Commerce
  • Účtovníctvo
  • Sklady
  • PoS
  • Projektové riadenie
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Tagy (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Tagy (View all)
odoo accounting v14 pos v15
About this forum
Pomoc

How to get groups of user logged in

Odoberať

Get notified when there's activity on this post

This question has been flagged
userinvisiblegroupsloggedodooV8
4 Replies
27411 Zobrazenia
Avatar
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
Avatar
Zrušiť
Kabeer KB

Define your function like this

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

//statement

Avatar
Jesús Marco
Autor Best Answer

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
Avatar
Zrušiť
Avatar
Sehrish
Best Answer

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
Avatar
Zrušiť
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

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

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

Registrácia
Related Posts Replies Zobrazenia Aktivita
how to get the logged user Solved
user logged
Avatar
Avatar
Avatar
2
feb 24
15229
Custom code: Field is restricted to the group(s) base.group_no_one. Solved
invisible groups modifier
Avatar
Avatar
1
apr 25
1898
how to make button available only for the requester ?
invisible context groups
Avatar
Avatar
Avatar
2
nov 19
3878
Automatically filling in field with the user name - Odoo8
user automatic odooV8
Avatar
Avatar
1
jún 15
3744
set a new menu for specific user
settings user odooV8
Avatar
0
máj 15
3889
Komunita
  • Tutoriály
  • Dokumentácia
  • Fórum
Open Source
  • Stiahnuť
  • Github
  • Runbot
  • Preklady
Služby
  • Odoo.sh hosting
  • Podpora
  • Vyššia verzia
  • Custom Developments
  • Vzdelávanie
  • Nájdite účtovníka
  • Nájdite partnera
  • Staň sa partnerom
O nás
  • Naša spoločnosť
  • Majetok značky
  • Kontaktujte nás
  • Pracovné ponuky
  • Eventy
  • Podcast
  • Blog
  • Zákazníci
  • Právne dokumenty • Súkromie
  • Bezpečnosť
الْعَرَبيّة 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 je sada podnikových aplikácií s otvoreným zdrojovým kódom, ktoré pokrývajú všetky potreby vašej spoločnosti: CRM, e-shop, účtovníctvo, skladové hospodárstvo, miesto predaja, projektový manažment atď.

Odoo prináša vysokú pridanú hodnotu v jednoduchom použití a súčasne plne integrovanými biznis aplikáciami.

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