Skip to Content
Odoo Menu
  • Sign in
  • Try it free
  • Apps
    Finance
    • Accounting
    • Invoicing
    • Expenses
    • Spreadsheet (BI)
    • Documents
    • Sign
    Sales
    • CRM
    • Sales
    • POS Shop
    • POS Restaurant
    • Subscriptions
    • Rental
    Websites
    • Website Builder
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Supply Chain
    • Inventory
    • Manufacturing
    • PLM
    • Purchase
    • Maintenance
    • Quality
    Human Resources
    • Employees
    • Recruitment
    • Time Off
    • Appraisals
    • Referrals
    • Fleet
    Marketing
    • Social Marketing
    • Email Marketing
    • SMS Marketing
    • Events
    • Marketing Automation
    • Surveys
    Services
    • Project
    • Timesheets
    • Field Service
    • Helpdesk
    • Planning
    • Appointments
    Productivity
    • Discuss
    • Approvals
    • IoT
    • VoIP
    • Knowledge
    • WhatsApp
    Third party apps Odoo Studio Odoo Cloud Platform
  • Industries
    Retail
    • Book Store
    • Clothing Store
    • Furniture Store
    • Grocery Store
    • Hardware Store
    • Toy Store
    Food & Hospitality
    • Bar and Pub
    • Restaurant
    • Fast Food
    • Guest House
    • Beverage Distributor
    • Hotel
    Real Estate
    • Real Estate Agency
    • Architecture Firm
    • Construction
    • Property Management
    • Gardening
    • Property Owner Association
    Consulting
    • Accounting Firm
    • Odoo Partner
    • Marketing Agency
    • Law firm
    • Talent Acquisition
    • Audit & Certification
    Manufacturing
    • Textile
    • Metal
    • Furnitures
    • Food
    • Brewery
    • Corporate Gifts
    Health & Fitness
    • Sports Club
    • Eyewear Store
    • Fitness Center
    • Wellness Practitioners
    • Pharmacy
    • Hair Salon
    Trades
    • Handyman
    • IT Hardware & Support
    • Solar Energy Systems
    • Shoe Maker
    • Cleaning Services
    • HVAC Services
    Others
    • Nonprofit Organization
    • Environmental Agency
    • Billboard Rental
    • Photography
    • Bike Leasing
    • Software Reseller
    Browse all Industries
  • Community
    Learn
    • Tutorials
    • Documentation
    • Certifications
    • Training
    • Blog
    • Podcast
    Empower Education
    • Education Program
    • Scale Up! Business Game
    • Visit Odoo
    Get the Software
    • Download
    • Compare Editions
    • Releases
    Collaborate
    • Github
    • Forum
    • Events
    • Translations
    • Become a Partner
    • Services for Partners
    • Register your Accounting Firm
    Get Services
    • Find a Partner
    • Find an Accountant
    • Meet an advisor
    • Implementation Services
    • Customer References
    • Support
    • Upgrades
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Get a demo
  • Pricing
  • Help
You need to be registered to interact with the community.
All Posts People Badges
Tags (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Tags (View all)
odoo accounting v14 pos v15
About this forum
Help

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

Subscribe

Get notified when there's activity on this post

This question has been flagged
19
2 Replies
360 Views
Avatar
Duck Page

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
Discard
Avatar
Duck Page
Author Best Answer

Thanks Ray, with "group_ids" works!

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

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

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

Sign up
Related Posts Replies Views Activity
Can we integrate ingenico in the Odoo 19 system for the country france?
19
Avatar
Avatar
1
Jan 26
486
menu contrats
contracts 19
Avatar
Avatar
Avatar
Avatar
4
Mar 26
234
Reordering rules for mulitple quantity's Odoo 19
reordering-rules 19
Avatar
Avatar
1
Feb 26
468
Migration V17-V19 Phone Number and Title missing
migration 19
Avatar
0
Jan 26
440
19 enterprise on-premises (Windows): "No rule has been found to replenish 'Widget 01' in 'Inter-warehouse transit'."
inventory 19
Avatar
0
Dec 25
475
Community
  • Tutorials
  • Documentation
  • Forum
Open Source
  • Download
  • Github
  • Runbot
  • Translations
Services
  • Odoo.sh Hosting
  • Support
  • Upgrade
  • Custom Developments
  • Education
  • Find an Accountant
  • Find a Partner
  • Become a Partner
About us
  • Our company
  • Brand Assets
  • Contact us
  • Jobs
  • Events
  • Podcast
  • Blog
  • Customers
  • Legal • Privacy
  • Security
الْعَرَبيّة 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