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
    • Artificial Intelligence
    • 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
    • Property Management
    • 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
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

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

Odoberať

Get notified when there's activity on this post

This question has been flagged
19
2 Replies
1233 Zobrazenia
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
Zrušiť
Avatar
DUCKPAGE DI OLIMPI MARCO & RUSU IULIAN S.N.C.
Autor Best Answer

Thanks Ray, with "group_ids" works!

0
Avatar
Zrušiť
Avatar
Ray Carnes (ray)
Best Answer
ValueError: Invalid field 'groups_id' in 'res.users'

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
Can we integrate ingenico in the Odoo 19 system for the country france?
19
Avatar
Avatar
1
jan 26
1221
menu contrats
contracts 19
Avatar
Avatar
Avatar
Avatar
4
mar 26
974
Reordering rules for mulitple quantity's Odoo 19
reordering-rules 19
Avatar
Avatar
1
feb 26
1343
Migration V17-V19 Phone Number and Title missing
migration 19
Avatar
0
jan 26
1234
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
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 Svenska ภาษาไทย 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