Skip to Content
Odoo Menu
  • Zaloguj się
  • Wypróbuj za darmo
  • Aplikacje
    Finanse
    • Księgowość
    • Fakturowanie
    • Wydatki
    • Arkusz kalkulacyjny (BI)
    • Dokumenty
    • Podpisy
    Sprzedaż
    • CRM
    • Sprzedaż
    • PoS Sklep
    • PoS Restauracja
    • Subskrypcje
    • Wypożyczalnia
    Strony Internetowe
    • Kreator Stron Internetowych
    • eCommerce
    • Blog
    • Forum
    • Czat na Żywo
    • eLearning
    Łańcuch dostaw
    • Magazyn
    • Produkcja
    • PLM
    • Zakupy
    • Konserwacja
    • Jakość
    Zasoby Ludzkie
    • Pracownicy
    • Rekrutacja
    • Urlopy
    • Ocena pracy
    • Polecenia Pracownicze
    • Flota
    Marketing
    • Marketing Społecznościowy
    • E-mail Marketing
    • SMS Marketing
    • Wydarzenia
    • Automatyzacja Marketingu
    • Ankiety
    Usługi
    • Projekt
    • Ewidencja czasu pracy
    • Usługi Terenowe
    • Helpdesk
    • Planowanie
    • Spotkania
    Produktywność
    • Dyskusje
    • Zatwierdzenia
    • IoT
    • VoIP
    • Baza wiedzy
    • WhatsApp
    Aplikacje trzecich stron Studio Odoo Odoo Cloud Platform
  • Branże
    Sprzedaż detaliczna
    • Księgarnia
    • Sklep odzieżowy
    • Sklep meblowy
    • Sklep spożywczy
    • Sklep z narzędziami
    • Sklep z zabawkami
    Żywienie i hotelarstwo
    • Bar i Pub
    • Restauracja
    • Fast Food
    • Pensjonat
    • Dystrybutor napojów
    • Hotel
    Agencja nieruchomości
    • Agencja nieruchomości
    • Biuro architektoniczne
    • Budowa
    • Zarządzanie nieruchomościami
    • Ogrodnictwo
    • Stowarzyszenie właścicieli nieruchomości
    Doradztwo
    • Biuro księgowe
    • Partner Odoo
    • Agencja marketingowa
    • Kancelaria prawna
    • Agencja rekrutacyjna
    • Audyt i certyfikacja
    Produkcja
    • Tekstylia
    • Metal
    • Meble
    • Jedzenie
    • Browar
    • Prezenty firmowe
    Zdrowie & Fitness
    • Klub sportowy
    • Salon optyczny
    • Centrum fitness
    • Praktycy Wellness
    • Apteka
    • Salon fryzjerski
    Transakcje
    • Złota rączka
    • Wsparcie Sprzętu IT
    • Systemy energii słonecznej
    • Szewc
    • Firma sprzątająca
    • Usługi HVAC
    Inne
    • Organizacja non-profit
    • Agencja Środowiskowa
    • Wynajem billboardów
    • Fotografia
    • Leasing rowerów
    • Sprzedawca oprogramowania
    Przeglądaj wszystkie branże
  • Community
    Ucz się
    • Samouczki
    • Dokumentacja
    • Certyfikacje
    • Szkolenie
    • Blog
    • Podcast
    Pomóż w nauce innym
    • Program Edukacyjny
    • Scale Up! Gra biznesowa
    • Odwiedź Odoo
    Skorzystaj z oprogramowania
    • Pobierz
    • Porównaj edycje
    • Wydania
    Współpracuj
    • Github
    • Forum
    • Wydarzenia
    • Tłumaczenia
    • Zostań partnerem
    • Usługi dla partnerów
    • Zarejestruj swoją firmę rachunkową
    Skorzystaj z usług
    • Znajdź partnera
    • Znajdź księgowego
    • Spotkaj się z doradcą
    • Usługi wdrożenia
    • Opinie klientów
    • Wsparcie
    • Aktualizacje
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Zaplanuj demo
  • Cennik
  • Pomoc

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

  • CRM
  • e-Commerce
  • Księgowość
  • Zapasy
  • PoS
  • Projekt
  • MRP
All apps
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
Wszystkie posty Osoby Odznaki
Tagi (Zobacz wszystko)
odoo accounting v14 pos v15
O tym forum
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
Wszystkie posty Osoby Odznaki
Tagi (Zobacz wszystko)
odoo accounting v14 pos v15
O tym forum
Pomoc

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

Zaprenumeruj

Otrzymaj powiadomienie o aktywności w tym poście

To pytanie dostało ostrzeżenie
1133 Widoki
Awatar
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
Awatar
Odrzuć
Podoba Ci się ta dyskusja? Dołącz do niej!

Stwórz konto dzisiaj, aby cieszyć się ekskluzywnymi funkcjami i wchodzić w interakcje z naszą wspaniałą społecznością!

Zarejestruj się
Społeczność
  • Samouczki
  • Dokumentacja
  • Forum
Open Source
  • Pobierz
  • Github
  • Runbot
  • Tłumaczenia
Usługi
  • Hosting Odoo.sh
  • Wsparcie
  • Aktualizacja
  • Indywidualne rozwiązania
  • Edukacja
  • Znajdź księgowego
  • Znajdź partnera
  • Zostań partnerem
O nas
  • Nasza firma
  • Zasoby marki
  • Skontaktuj się z nami
  • Oferty pracy
  • Wydarzenia
  • Podcast
  • Blog
  • Klienci
  • Informacje prawne • Prywatność
  • Bezpieczeństwo Odoo
الْعَرَبيّة 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 to pakiet aplikacji biznesowych typu open source, które zaspokoją wszystkie potrzeby Twojej firmy: CRM, eCommerce, księgowość, inwentaryzacja, punkt sprzedaży, zarządzanie projektami itp.

Unikalną wartością Odoo jest to, że jest jednocześnie bardzo łatwe w użyciu i w pełni zintegrowane.

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