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
    • Validations
    • 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
    • Épicerie
    • 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
    • Bricoleur
    • 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
    • Devenez 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

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

  • CRM
  • e-Commerce
  • Comptabilité
  • Inventaire
  • PoS
  • Projet
  • MRP
All apps
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

Issue with Creating Users in Odoo via XML-RPC from Express.js Backend

S'inscrire

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

Cette question a été signalée
1337 Vues
Avatar
Nolhan

Voici une version mise à jour de ton problème en anglais, incluant toutes les informations et les fichiers pertinents :

Subject: Error Creating Users in Odoo via XML-RPC from Express.js Backend


Hi,


I’m experiencing an issue when trying to create users in Odoo using the xml-rpc library in my Express.js backend. Here’s a detailed overview of my setup:


Setup

1. Environment

• Dockerized Application

• Odoo: version 18.0

• PostgreSQL: version 15

• Backend: Express.js (with xml-rpc library) with node:16

• Frontend: Next.js (not directly relevant to the issue)

• The Odoo database is correctly initialized using Docker, and there are no issues with the database setup.

2. Endpoints

• A GET route verifies the connection to Odoo via XML-RPC, and it works perfectly.

• A POST route attempts to create a user in Odoo by calling the create method of the res.users model.

3. The Problem

• When I send a POST request to create a user, I receive an error indicating that I am providing too many “positional arguments”.

• The error persists despite passing what I believe to be the correct payload.


Key Files


Below are the files relevant to my setup:


docker-compose.yml

services:
  postgres_db:
    image: postgres:15
    container_name: postgres_db
    environment:
      POSTGRES_USER: postgres
      POSTGRES_PASSWORD: password
      POSTGRES_DB: xiptelecom
    volumes:
      - postgres_data:/var/lib/postgresql/data
      - ./init_postgres_odoo.sql:/docker-entrypoint-initdb.d/init_postgres_odoo.sql
    ports:
      - "5432:5432"
    restart: always

  odoo:
    image: odoo:18.0
    container_name: odoo
    depends_on:
      - postgres_db
    ports:
      - "8069:8069"
    volumes:
      - odoo-web-data:/var/lib/odoo
      - ./config:/etc/odoo
      - ./addons:/mnt/extra-addons
      - ./logs:/var/log/odoo
    environment:
      - HOST=postgres_db
      - USER=odoo_user
      - PASSWORD=odoo_password
    command: odoo -d odoo --db_user=odoo_user --db_password=odoo_password -i base
    restart: always

  pgadmin:
    image: dpage/pgadmin4
    container_name: pgadmin4_container
    restart: always
    ports:
      - "5050:80"
    environment:
      PGADMIN_DEFAULT_EMAIL: admin@admin.com
      PGADMIN_DEFAULT_PASSWORD: admin
    volumes:
      - pgadmin_data:/var/lib/pgadmin

  backend:
    build:
      context: ./Backend
      dockerfile: Dockerfile
    container_name: backend
    command: "npm run dev"
    volumes:
      - ./Backend:/usr/src/app
    ports:
      - "1337:1337"
    depends_on:
      - postgres_db

  frontend:
    build:
      context: ./Frontend
      container_name: frontend
      command: "npm run dev"
      volumes:
        - ./Frontend:/app
      ports:
        - "3000:3000"
      depends_on:
        - backend

volumes:
  postgres_data:
  pgadmin_data:
  odoo-web-data:
  odoo-db-data:

server.js

const express = require('express');
const port = 1337;
const app = express();

app.use(express.json());

const { connectToOdoo, createUserInOdoo } = require('./odoo.js');

app.get('/api/test-odoo', async (req, res) => {
    try {
        await connectToOdoo();
        res.status(200).json({ message: 'Connexion à Odoo réussie !' });
    } catch (err) {
        res.status(500).json({ error: 'Connexion à Odoo échouée.', details: err.message });
    }
});

app.post('/create-user', async (req, res) => {
    const { name, email, login } = req.body;

    if (!name || !email || !login) {
        return res.status(400).json({ error: 'Tous les champs sont requis (name, email, login)' });
    }

    try {
        await connectToOdoo();
        const userId = await createUserInOdoo({ name, login, email });
        res.status(201).json({ message: 'Utilisateur créé avec succès dans Odoo', userId });
    } catch (err) {
        res.status(500).json({ error: 'Erreur lors de la création de l\'utilisateur dans Odoo', details: err.message });
    }
});

app.listen(port, () => console.log(`Le backend à démarré sur le port : ${port}`));

odoo.js

const Odoo = require('odoo-xmlrpc');

const odoo = new Odoo({
    url: 'http://odoo:8069',
    db: 'odoo',
    username: 'admin',
    password: 'admin',
});

const connectToOdoo = async () => {
    return new Promise((resolve, reject) => {
        odoo.connect((err) => {
            if (err) {
                reject(err);
            } else {
                resolve();
            }
        });
    });
};

const createUserInOdoo = async (userData) => {
    try {
        await connectToOdoo();
        const response = await new Promise((resolve, reject) => {
            odoo.execute_kw('res.users', 'create', [userData], (err, value) => {
                if (err) reject(err);
                else resolve(value);
            });
        });
        return response;
    } catch (err) {
        throw new Error(err);
    }
};

module.exports = { connectToOdoo, createUserInOdoo };

Request Sent from REST Client

POST http://localhost:1337/create-user
Content-Type: application/json

{
  "name": "Test User",
  "email": "testuser@example.com",
  "login": "testuser"
}

The error I receive :

HTTP/1.1 500 Internal Server Error
X-Powered-By: Express
Content-Type: application/json; charset=utf-8
Content-Length: 1973
ETag: W/"7b5-HnkxxuFqhmAddquOjPBhWEHKDTE"
Date: Mon, 27 Jan 2025 15:22:10 GMT
Connection: close

{
  "error": "Erreur lors de la création de l'utilisateur dans Odoo",
  "details": "Erreur lors de la création de l'utilisateur : Erreur lors de la création de l'utilisateur : XML-RPC fault: Traceback (most recent call last):\n  File \"/usr/lib/python3/dist-packages/odoo/addons/base/controllers/rpc.py\", line 161, in xmlrpc_2\n    response = self._xmlrpc(service)\n               ^^^^^^^^^^^^^^^^^^^^^\n  File \"/usr/lib/python3/dist-packages/odoo/addons/base/controllers/rpc.py\", line 139, in _xmlrpc\n    result = dispatch_rpc(service, method, params)\n             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n  File \"/usr/lib/python3/dist-packages/odoo/http.py\", line 398, in dispatch_rpc\n    return dispatch(method, params)\n           ^^^^^^^^^^^^^^^^^^^^^^^^\n  File \"/usr/lib/python3/dist-packages/odoo/service/model.py\", line 39, in dispatch\n    res = execute_kw(db, uid, *params[3:])\n          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n  File \"/usr/lib/python3/dist-packages/odoo/service/model.py\", line 61, in execute_kw\n    return execute(db, uid, obj, method, *args, **kw or {})\n           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n  File \"/usr/lib/python3/dist-packages/odoo/service/model.py\", line 68, in execute\n    res = execute_cr(cr, uid, obj, method, *args, **kw)\n          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n  File \"/usr/lib/python3/dist-packages/odoo/service/model.py\", line 52, in execute_cr\n    result = retrying(partial(odoo.api.call_kw, recs, method, args, kw), env)\n             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n  File \"/usr/lib/python3/dist-packages/odoo/service/model.py\", line 137, in retrying\n    result = func()\n             ^^^^^^\n  File \"/usr/lib/python3/dist-packages/odoo/api.py\", line 517, in call_kw\n    result = getattr(recs, name)(*args, **kwargs)\n             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\nTypeError: create() takes 2 positional arguments but 4 were given\n"
}


Question


• Why does the create() method fail with a “positional arguments” error in this context?

• Could you provide guidance on the correct format for the create method in Odoo when using XML-RPC?

• Do I need to adjust the userData object structure to align with Odoo’s expectations?


Thank you in advance for any assistance!


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
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
  • Devenez 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 ภาษาไทย 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