Skip to Content
Odoo Menu
  • Prijavi
  • Try it free
  • Aplikacije
    Finance
    • Knjigovodstvo
    • Obračun
    • Stroški
    • Spreadsheet (BI)
    • Dokumenti
    • Podpisovanje
    Prodaja
    • CRM
    • Prodaja
    • POS Shop
    • POS Restaurant
    • Naročnine
    • Najem
    Spletne strani
    • Website Builder
    • Spletna trgovina
    • Blog
    • Forum
    • Pogovor v živo
    • eUčenje
    Dobavna veriga
    • Zaloga
    • Proizvodnja
    • PLM
    • Nabava
    • Vzdrževanje
    • Kakovost
    Kadri
    • Kadri
    • Kadrovanje
    • Odsotnost
    • Ocenjevanja
    • Priporočila
    • Vozni park
    Marketing
    • Družbeno Trženje
    • Email Marketing
    • SMS Marketing
    • Dogodki
    • Avtomatizacija trženja
    • Ankete
    Storitve
    • Projekt
    • Časovnice
    • Storitve na terenu
    • Služba za pomoč
    • Načrtovanje
    • Termini
    Produktivnost
    • Razprave
    • Artificial Intelligence
    • IoT
    • Voip
    • Znanje
    • WhatsApp
    Third party apps Odoo Studio Odoo Cloud Platform
  • Industrije
    Trgovina na drobno
    • Book Store
    • Trgovina z oblačili
    • Trgovina s pohištvom
    • Grocery Store
    • Trgovina s strojno opremo računalnikov
    • Trgovina z igračami
    Food & Hospitality
    • Bar and Pub
    • Restavracija
    • Hitra hrana
    • Guest House
    • Beverage Distributor
    • Hotel
    Nepremičnine
    • Real Estate Agency
    • Arhitekturno podjetje
    • Gradbeništvo
    • Property Management
    • Vrtnarjenje
    • Združenje lastnikov nepremičnin
    Svetovanje
    • Računovodsko podjetje
    • Odoo Partner
    • Marketinška agencija
    • Law firm
    • Pridobivanje talentov
    • Audit & Certification
    Proizvodnja
    • Tekstil
    • Metal
    • Pohištvo
    • Hrana
    • Brewery
    • Poslovna darila
    Health & Fitness
    • Športni klub
    • Trgovina z očali
    • Fitnes center
    • Wellness Practitioners
    • Lekarna
    • Frizerski salon
    Trades
    • Handyman
    • IT Hardware & Support
    • Sistemi sončne energije
    • Izdelovalec čevljev
    • Čistilne storitve
    • HVAC Services
    Ostali
    • Neprofitna organizacija
    • Agencija za okolje
    • Najem oglasnih panojev
    • Fotografija
    • Najem koles
    • Prodajalec programske opreme
    Browse all Industries
  • Skupnost
    Learn
    • Tutorials
    • Dokumentacija
    • Certifikati
    • Šolanje
    • Blog
    • Podcast
    Empower Education
    • Education Program
    • Scale Up! Business Game
    • Visit Odoo
    Get the Software
    • Prenesi
    • Compare Editions
    • Releases
    Collaborate
    • Github
    • Forum
    • Dogodki
    • Prevodi
    • Become a Partner
    • Services for Partners
    • Register your Accounting Firm
    Get Services
    • Find a Partner
    • Find an Accountant
    • Meet an advisor
    • Implementation Services
    • Sklici kupca
    • Podpora
    • Upgrades
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Get a demo
  • Določanje cen
  • Pomoč
You need to be registered to interact with the community.
All Posts People Badges
Ključne besede (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Ključne besede (View all)
odoo accounting v14 pos v15
About this forum
Pomoč

[19] How create an admin user from CLI when init a new db

Naroči se

Get notified when there's activity on this post

This question has been flagged
19
2 Odgovori
1257 Prikazi
Avatar
DUCKPAGE DI OLIMPI MARCO & RUSU IULIAN S.N.C.

Hi, in a production server i need to create the admin user when i init the db from the cli (using -i base --stop-after-init --without-demo). The db is manualy create with psql and i set db_name and list_db=false.

Online I found to use the shell with  a custom python script (example --shell-file=odoo.createadmin.py) and here my script

login = "sandbox@odoo.com"
pwd = "Password123"
name = "Sandbox Admin"

Users = env["res.users"].sudo().with_context(active_test=False)
u = Users.search([("login", "=", login)], limit=1)

vals = {
    "name": name,
    "login": login,
    "email": login,
    "share": False,
    "active": True,
}

if not u:
    vals["password"] = pwd
    u = Users.create(vals)
else:
    vals["password"] = pwd
    u.write(vals)

group_user = env.ref("base.group_user")
group_system = env.ref("base.group_system")

# Prova a scrivere direttamente su res.users
try:
    u.write({
        "groups_id": [(4, group_user.id, 0), (4, group_system.id, 0)]
    })
except Exception:
    # Se fallisce, prova tramite il partner
    if not u.partner_id:
        partner = env['res.partner'].create({
            'name': name,
            'email': login,
        })
        u.write({'partner_id': partner.id})
    u.partner_id.write({
        'groups_id': [(6, 0, [group_user.id, group_system.id])]
    })

env.cr.commit()

But I get

env: <odoo.orm.environments.Environment object at 0x7f1ce4d62c40>
odoo: <module 'odoo' (namespace) from ['/opt/odoo/odoo-server/odoo']>
openerp: <module 'odoo' (namespace) from ['/opt/odoo/odoo-server/odoo']>
self: res.users(1,)
Traceback (most recent call last):
File "/opt/odoo/odoo-server/odoo/orm/models.py", line 4381, in write
self._check_field_access(self._fields[field_name], 'write')
~~~~~~~~~~~~^^^^^^^^^^^^
KeyError: 'groups_id'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "odoo.createadmin.py", line 28, in <module>
u.write({
~~~~~~~^^
"groups_id": [(4, group_user.id, 0), (4, group_system.id, 0)]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
})
^^
File "/opt/odoo/odoo-server/odoo/addons/base/models/res_users.py", line 1370, in write
res = super().write(vals)
File "/opt/odoo/odoo-server/odoo/addons/base/models/res_users.py", line 617, in write
res = super().write(vals)
File "/opt/odoo/odoo-server/odoo/orm/models.py", line 4383, in write
raise ValueError(f"Invalid field {field_name!r} in {self._name!r}") from e
ValueError: Invalid field 'groups_id' in 'res.users'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "odoo.createadmin.py", line 39, in <module>
u.partner_id.write({
~~~~~~~~~~~~~~~~~~^^
'groups_id': [(6, 0, [group_user.id, group_system.id])]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
})
^^
File "/opt/odoo/odoo-server/odoo/addons/base/models/res_partner.py", line 880, in write
pre_values_list = [{fname: partner[fname] for fname in vals} for partner in self]
~~~~~~~^^^^^^^
File "/opt/odoo/odoo-server/odoo/orm/models.py", line 6686, in __getitem__
return self._fields[key].__get__(self)
~~~~~~~~~~~~^^^^^
KeyError: 'groups_id'

What is the correct way? I search in the docs but withour success.

Thanks

0
Avatar
Opusti
Avatar
DUCKPAGE DI OLIMPI MARCO & RUSU IULIAN S.N.C.
Avtor Best Answer

Thanks Ray, with "group_ids" works!

0
Avatar
Opusti
Avatar
Ray Carnes (ray)
Best Answer
ValueError: Invalid field 'groups_id' in 'res.users'

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

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

Prijavi
Related Posts Odgovori Prikazi Aktivnost
Can we integrate ingenico in the Odoo 19 system for the country france?
19
Avatar
Avatar
1
jan. 26
1222
menu contrats
contracts 19
Avatar
Avatar
Avatar
Avatar
4
mar. 26
999
Reordering rules for mulitple quantity's Odoo 19
reordering-rules 19
Avatar
Avatar
1
feb. 26
1361
Migration V17-V19 Phone Number and Title missing
migration 19
Avatar
0
jan. 26
1257
19 enterprise on-premises (Windows): "No rule has been found to replenish 'Widget 01' in 'Inter-warehouse transit'."
inventory 19
Avatar
0
dec. 25
1058
Community
  • Tutorials
  • Dokumentacija
  • Forum
Open Source
  • Prenesi
  • Github
  • Runbot
  • Prevodi
Services
  • Odoo.sh Hosting
  • Podpora
  • Nadgradnja
  • Custom Developments
  • Izobraževanje
  • Find an Accountant
  • Find a Partner
  • Become a Partner
About us
  • Our company
  • Sredstva blagovne znamke
  • Kontakt
  • Zaposlitve
  • Dogodki
  • Podcast
  • Blog
  • Stranke
  • Pravno • Zasebnost
  • Varnost
الْعَرَبيّة 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 Svenska ภาษาไทย Türkçe українська Tiếng Việt

Odoo is a suite of open source business apps that cover all your company needs: CRM, eCommerce, accounting, inventory, point of sale, project management, etc.

Odoo's unique value proposition is to be at the same time very easy to use and fully integrated.

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