Přejít na obsah
Odoo Menu
  • Přihlásit se
  • Vyzkoušejte zdarma
  • Aplikace
    Finance
    • Účetnictví
    • Fakturace
    • Výdaje
    • Spreadsheet (BI)
    • Dokumenty
    • Podpisy
    Prodej
    • CRM
    • Prodej
    • POS Obchod
    • POS Restaurace
    • Předplatné
    • Pronájem
    Webové stránky
    • Webové stránky
    • E-shop
    • Blog
    • Fórum
    • Živý chat
    • eLearning
    Dodavatelský řetězec
    • Sklad
    • Výroba
    • PLM
    • Nákup
    • Údržba
    • Kvalita
    Lidské zdroje
    • Zaměstnanci
    • Nábor
    • Volno
    • Hodnocení zaměstnanců
    • Doporučení
    • Vozový park
    Marketing
    • Marketing sociálních sítí
    • Emailový marketing
    • SMS Marketing
    • Události
    • Marketingová automatizace
    • Dotazníky
    Služby
    • Projekt
    • Časové výkazy
    • Práce v terénu
    • Helpdesk
    • Plánování
    • Schůzky
    Produktivita
    • Diskuze
    • Schvalování
    • IoT
    • VoIP
    • Znalosti
    • WhatsApp
    Aplikace třetích stran Odoo Studio Odoo cloudová platforma
  • Branže
    Maloobchod
    • Knihkupectví
    • Obchod s oblečením
    • Obchod s nábytkem
    • Potraviny
    • Obchod s hardwarem
    • Hračkářství
    Jídlo a pohostinství
    • Bar a Pub
    • Restaurace
    • Fast Food
    • Penzion
    • Distributor nápojů
    • Hotel
    Nemovitost
    • Realitní kancelář
    • Architektonická firma
    • Stavba
    • Správa nemovitostí
    • Zahradnictví
    • Asociace vlastníků nemovitosti
    Poradenství
    • Účetní firma
    • Odoo Partner
    • Marketingová agentura
    • Právník
    • Akvizice talentů
    • Audit a certifikace
    Výroba
    • Textil
    • Kov
    • Nábytek
    • Jídlo
    • Pivovar
    • Korporátní dárky
    Zdraví a fitness
    • Sportovní klub
    • Prodejna brýli
    • Fitness Centrum
    • Wellness praktikové
    • Lékárna
    • Kadeřnictví
    Transakce
    • Údržbář
    • Podpora IT & hardware
    • Systémy solární energie
    • Výrobce obuvi
    • Úklidové služby
    • Služby HVAC
    Ostatní
    • Nezisková organizace
    • Agentura pro životní prostředí
    • Pronájem billboardů
    • Fotografování
    • Leasing jízdních kol
    • Prodejce softwaru
    Procházet všechna odvětví
  • Komunita
    Edukační program
    • Tutoriály
    • Dokumentace
    • Certifikace
    • Vzdělávání
    • Blog
    • Podcast
    Podpora vzdělávání
    • Vzdělávací program
    • Scale Up! Hra na firmu
    • Navštivte Odoo
    Získat software
    • Stáhnout
    • Porovnejte edice
    • Verze
    Spolupráce
    • Github
    • Fórum
    • Události
    • Překlady
    • Stát se partnerem
    • Služby pro partnery
    • Registrujte svou účetní firmu
    Získat služby
    • Najít partnera
    • Najít účetní
    • Setkejte se s poradcem
    • Implementační služby
    • Zákaznické reference
    • Podpora
    • Upgrady
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Dohodnout demo
  • Ceník
  • Pomoc

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

  • CRM
  • e-Commerce
  • Účetnictví
  • Sklad
  • PoS
  • Projekty
  • MRP
All apps
You need to be registered to interact with the community.
All Posts Lidé Odznaky
Štítky (View all)
odoo accounting v14 pos v15
O tomto fóru
You need to be registered to interact with the community.
All Posts Lidé Odznaky
Štítky (View all)
odoo accounting v14 pos v15
O tomto fóru
Pomoc

ver.14: id of currently logged in user as default value of a field in model (python file)

Odebírat

Get notified when there's activity on this post

This question has been flagged
idLoginv14
1 Odpovědět
7805 Zobrazení
Avatar
SmithJohn45

want to get currently logged in user id as default value in python file but when submit/save it is showing NULL value when querying thru psql. how i can get it, below are what i did, row saved but without current user's id in field user_id.

in python file:

user_id = fields.Many2one('res.partner', string="User",compute='_get_current_user')
    @api.depends('name')
    def _get_current_user(self):
        for r in self:
            r.user_id = self.env.user

created a web page as my view for data entry and controller file:

class QuickOrdersForm(http.Controller):
    @http.route(['/web/quickorders/form'], type='http', auth="public", website=True)
    def quickorders_form(self, **post):
        return request.render("tests.web_quickorders_form", {})
    @http.route(['/web/quickorders/form/submit'], type='http', auth="public", website=True)
    # next controller with url for submitting data from the form#
    def quickorders_form_submit(self, **post):
        qorder = request.env['tests.quickorders'].create({
            'name': post.get('name'),
            'order_type': post.get('order_type')
        })
        vals = {
            'qorder': qorder,
        }
        # inherited the model to pass the values to the model from the form#
        return request.render("tests.web_quickorders_form_success", vals)


0
Avatar
Zrušit
Avatar
Begineer
Nejlepší odpověď

Mr.Smith,

            Your Many2one field user_id  points to the table 'res.partner'. It is wrong and it should be res.users in order to capture the current user who has logged in. 
user_id = fields.Many2one('res.users', string="User", compute='_get_current_user')

1
Avatar
Zrušit
SmithJohn45
Autor

thanks to point my mistake, will change and confirm.

Begineer

Hope it helps. If so please close your query as answered. Thanks

SmithJohn45
Autor

@Karthikeyan, i modified it as per instructed but still not getting logged-in user's 'id' in my user_id field. is there anything in function _get_current_user or something else?

Begineer

You can simply use "default" in your field definition instead of writing a compute,

user_id = fields.Many2one('res.users', string='User', default=lambda self: self.env.user)

SmithJohn45
Autor

yeah, now it works perfectly... modified to use default=lambda self: self.env.user

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

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

Přihlásit se
Related Posts Odpovědi Zobrazení Aktivita
Add contact ID Vyřešeno
id unique v14
Avatar
Avatar
Avatar
Avatar
3
zář 22
4701
which function called when Odoo SH login with connect button
Login v14 OdooSH
Avatar
0
kvě 22
2710
Got 403 forbidden error when accessing shop for public user
shop Login v14
Avatar
0
bře 22
7736
Odoo14 alternative for Automated Translations through Gengo API module
v14
Avatar
Avatar
Avatar
Avatar
3
zář 25
3644
Odoo Community v14 Slow on High-End Servers, Fast on i5/i7 PCs
v14
Avatar
0
srp 25
1087
Komunita
  • Tutoriály
  • Dokumentace
  • Fórum
Open Source
  • Stáhnout
  • Github
  • Runbot
  • Překlady
Služby
  • Odoo.sh hostování
  • Podpora
  • Upgrade
  • Nestandardní vývoj
  • Edukační program
  • Najít účetní
  • Najít partnera
  • Stát se partnerem
O nás
  • Naše společnost
  • Podklady značky
  • Kontakujte nás
  • Práce
  • Události
  • Podcast
  • Blog
  • Zákazníci
  • Právní dokumenty • Soukromí
  • Zabezpečení
الْعَرَبيّة 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 balíček open-source aplikací, které pokrývají všechny potřeby vaší společnosti: CRM, e-shop, účetnictví, sklady, kasy, projektové řízení a další.

Unikátní nabídka od Odoo poskytuje velmi jednoduché uživatelské rozhraní a vše je integrované na jednom místě.

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