Se rendre au contenu
Odoo Menu
  • Se connecter
  • Essai gratuit
  • Applications
    Finance
    • Comptabilité
    • Facturation
    • Notes de frais
    • Feuilles de calcul (BI)
    • Documents
    • Signature
    Ventes
    • CRM
    • Ventes
    • PdV Boutique
    • PdV Restaurant
    • Abonnements
    • Location
    Sites web
    • Site Web
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Chaîne d'approvisionnement
    • Inventaire
    • Fabrication
    • PLM
    • Achats
    • Maintenance
    • Qualité
    Ressources Humaines
    • Employés
    • Recrutement
    • Congés
    • Évaluations
    • Recommandations
    • Parc automobile
    Marketing
    • Marketing Social
    • E-mail Marketing
    • SMS Marketing
    • Événements
    • Marketing Automation
    • Sondages
    Services
    • Projet
    • Feuilles de temps
    • Services sur Site
    • Assistance
    • Planification
    • Rendez-vous
    Productivité
    • Discussion
    • Intelligence artificielle
    • Internet des Objets
    • VoIP
    • Connaissances
    • WhatsApp
    Applications tierces Odoo Studio Plateforme Cloud d'Odoo
  • Industries
    Commerce de détail
    • Librairie
    • Magasin de vêtements
    • Magasin de meubles
    • Supermarché
    • Quincaillerie
    • Magasin de jouets
    Restauration & Hôtellerie
    • Bar et Pub
    • Restaurant
    • Fast-food
    • Maison d’hôtes
    • Distributeur de boissons
    • Hôtel
    Immobilier
    • Agence immobilière
    • Cabinet d'architecture
    • Construction
    • Gestion immobilière
    • Jardinage
    • Association de copropriétaires
    Consultance
    • Cabinet d'expertise comptable
    • Partenaire Odoo
    • Agence Marketing
    • Cabinet d'avocats
    • Aquisition de talents
    • Audit & Certification
    Fabrication
    • Textile
    • Métal
    • Meubles
    • Alimentation
    • Brasserie
    • Cadeaux d'entreprise
    Santé & Fitness
    • Club de sports
    • Opticien
    • Salle de fitness
    • Praticiens bien-être
    • Pharmacie
    • Salon de coiffure
    Commerce
    • Homme à tout faire
    • Matériel informatique & support
    • Systèmes photovoltaïques
    • Cordonnier
    • Services de nettoyage
    • Services CVC
    Autres
    • Organisation à but non lucratif
    • Agence environnementale
    • Location de panneaux d'affichage
    • Photographie
    • Leasing de vélos
    • Revendeur de logiciel
    Parcourir toutes les industries
  • Communauté
    Apprenez
    • Tutoriels
    • Documentation
    • Certifications
    • Formation
    • Blog
    • Podcast
    Renforcer l'éducation
    • Programme éducatif
    • Business Game Scale-Up!
    • Rendez-nous visite
    Obtenir le logiciel
    • Téléchargement
    • Comparez les éditions
    • Versions
    Collaborer
    • Github
    • Forum
    • Événements
    • Traductions
    • Devenir partenaire
    • Services pour partenaires
    • Enregistrer votre cabinet comptable
    Nos Services
    • Trouver un partenaire
    • Trouver un comptable
    • Rencontrer un conseiller
    • Services de mise en œuvre
    • Références clients
    • Assistance
    • Mises à niveau
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Obtenir une démonstration
  • Tarification
  • Aide
Vous devez être inscrit pour interagir avec la communauté.
Toutes les publications Personnes Badges
Étiquettes (Voir toutl)
odoo accounting v14 pos v15
À propos de ce forum
Vous devez être inscrit pour interagir avec la communauté.
Toutes les publications Personnes Badges
Étiquettes (Voir toutl)
odoo accounting v14 pos v15
À propos de ce forum
Aide

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

S'inscrire

Recevez une notification lorsqu'il y a de l'activité sur ce poste

Cette question a été signalée
19
2 Réponses
1246 Vues
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
Ignorer
Avatar
DUCKPAGE DI OLIMPI MARCO & RUSU IULIAN S.N.C.
Auteur Meilleure réponse

Thanks Ray, with "group_ids" works!

0
Avatar
Ignorer
Avatar
Ray Carnes (ray)
Meilleure réponse
ValueError: Invalid field 'groups_id' in 'res.users'

0
Avatar
Ignorer
Vous appréciez la discussion ? Ne vous contentez pas de lire, rejoignez-nous !

Créez un compte dès aujourd'hui pour profiter de fonctionnalités exclusives et échanger avec notre formidable communauté !

S'inscrire
Publications associées Réponses Vues Activité
Can we integrate ingenico in the Odoo 19 system for the country france?
19
Avatar
Avatar
1
janv. 26
1221
menu contrats
contracts 19
Avatar
Avatar
Avatar
Avatar
4
mars 26
983
Reordering rules for mulitple quantity's Odoo 19
reordering-rules 19
Avatar
Avatar
1
févr. 26
1348
Migration V17-V19 Phone Number and Title missing
migration 19
Avatar
0
janv. 26
1239
19 enterprise on-premises (Windows): "No rule has been found to replenish 'Widget 01' in 'Inter-warehouse transit'."
inventory 19
Avatar
0
déc. 25
1058
Communauté
  • Tutoriels
  • Documentation
  • Forum
Open Source
  • Téléchargement
  • Github
  • Runbot
  • Traductions
Services
  • Hébergement Odoo.sh
  • Assistance
  • Migration
  • Développements personnalisés
  • Éducation
  • Trouver un comptable
  • Trouver un partenaire
  • Devenir partenaire
À propos
  • Notre société
  • Actifs de la marque
  • Contactez-nous
  • Emplois
  • Événements
  • Podcast
  • Blog
  • Clients
  • Informations légales • Confidentialité
  • Sécurité.
الْعَرَبيّة 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 est une suite d'applications open source couvrant tous les besoins de votre entreprise : CRM, eCommerce, Comptabilité, Inventaire, Point de Vente, Gestion de Projet, etc.

Le positionnement unique d'Odoo est d'être à la fois très facile à utiliser et totalement intégré.

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