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 retrieve user first and last name?

Odoberať

Get notified when there's activity on this post

This question has been flagged
openerpcostum_module
3 Replies
11296 Zobrazenia
Avatar
Andrew

Hello, i'm writing a module for OpenErp and i have some troubles with user's first and last names.

 

this is my piece of code:

def _user_get(self, cr, uid, context=None):
    cr.execute("select id,name from resource_resource")
    return cr.fetchall()
 .....

 

_columns = {

....

'users' : fields.selection(_user_get, 'Users')

...}

 

But it doesn't work. Can someone help me?

It saves data in the table, but does't show user name and family. The rest info is displayed.

0
Avatar
Zrušiť
Andrew
Autor

Thank you  * Bole [1]  *for your answer. I know about "'my_user':fields.many2one('res.users','User')", but the problem is that it displays too much info, such as "Language, Login and date". But i need only first and last name [1] https://www.odoo.com/forum/help-1/user/6104

Bole

o, so create a new view that shows only the fields you need .. in xml do like: that should do the trick of custom tree view fro many 2 one;) also you can define custom form view;) the same way

Bole

i have edited my answer so now you have example on how to show only the fields you want , and not all of them ;)

Avatar
Bole
Best Answer

Well.. you are looking at wrong data.. 

In odoo/openerp resource_resource contains(actualy is hr_employee name i related to this field) 
 the name for employees, not users.. 

there is a table res_users where some user data is stored... (login, password, mail.. etc..) and a relation to res_partner (partner_id) wich contains actual name of user, along with other data (address, phone , mail....)

So eather you rewrite your sql acordingly (using some joins for foreign key ids..) ,

or.. simply user orm methods like.. if you want to search for user wich has login : 'someuser' it would look like:

ids = self.pool.get('res.users').search(cr, uid, [('login'.'=','someuser')])    #expecting a list of ids returned

now that you have list of ids, you can browse those records and read/modify any data stored in fields...

 

but in your case... i think it would be much easier if you do not use fields.selection.. but instead, 

define your:

_columns = {
...
'my_user':fields.many2one('res.users','User'),
...
}
 

this is common usage for many to one field, and it preserves most orm methods in it ( addins and modifying user) 
in case you want to show just a selection on the view... define a view like: (addon after comment:)
<field name="my_user" widget="selection" /> 

If you need only a few fields shown and not the default view for related field, define them in the same view like:

<field name="my_user" widget="selection" > 
    <tree>
        <field name="first_name"/>
        <filed name="last_name"/>
    </tree>
</field>


 

1
Avatar
Zrušiť
Avatar
Zahin
Best Answer

HI. Andrew 

Here right way TODO.

_columns = {

          'user_id': fields.many2one('res.users', 'Salesperson',),

}

_defaults = {
         'user_id': lambda obj, cr, uid, context: uid,

}

I suggest you to read existing code of sale module or account module, and just go through code and understand existing codes and utilize it in your modules.

 

0
Avatar
Zrušiť
Avatar
Andrew
Autor Best Answer

Thank you. I solved this isue in the next way:

_columns = {

...

'user_id': fields.many2many('res.users'),

...

}

 

but in the xml view I inserted this string

 

<field name="user_id" string='Assigned Users' widget="many2many_tags" />

0
Avatar
Zrušiť
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
Create selection type field dynamically?
openerp
Avatar
Avatar
Avatar
2
sep 23
8487
How to hide the create button dynamical tree view in openerp ? Solved
openerp
Avatar
Avatar
2
mar 23
47729
ProgrammingError: can't adapt type 'dict' [SOLVED]
openerp
Avatar
Avatar
Avatar
2
dec 23
58865
How to use the audit app
openerp
Avatar
0
mar 22
3046
How to change default action of elements of tree view?
openerp
Avatar
Avatar
3
jún 20
11412
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