Odoo Web Service API

คู่มือการเชื่อมต่อ Odoo ผ่าน XML-RPC (Odoo Master/19.0) ครอบคลุมการจัดการข้อมูลจากภายนอก

🇹🇭 ภาษาไทย

การเชื่อมต่อ (Connection)

  • Endpoints:
    • /xmlrpc/2/common: สำหรับการตรวจสอบเวอร์ชันและ Authentication
    • /xmlrpc/2/object: สำหรับการเรียกใช้ Methods ของ Models (CRUD)
  • Authentication: ใช้ฟังก์ชัน authenticate เพื่อรับ uid (User ID) สำหรับใช้ในการเรียกครั้งต่อๆ ไป

การเรียกใช้ Methods (execute_kw)

พารามิเตอร์หลัก: db, uid, password, model_name, method_name, positional_params, keyword_params

  1. List & Search:
    • search(): รับ Domain filter และคืนค่ารายการ IDs
    • search_count(): คืนค่าจำนวน Records ที่ตรงตามเงื่อนไข
  2. Read:
    • read([ids], {'fields': [...]}): ดึงข้อมูลตาม IDs โดยระบุฟิลด์ที่ต้องการ (id จะถูกส่งกลับมาเสมอ)
    • search_read(): ทางลัดสำหรับการทำ search และ read ในครั้งเดียว
  3. Write/Create/Delete:
    • create([{'field': value}]): สร้าง Record ใหม่
    • write([ids], {'field': value}): แก้ไข Record (อัปเดตพร้อมกันหลายใบได้)
    • unlink([ids]): ลบ Record
  4. Introspection:
    • fields_get(): ตรวจสอบโครงสร้างฟิลด์ของ Model
    • ir.model & ir.model.fields: ค้นหา Metadata ของระบบ

🇬🇧 English

Overview

The Odoo Web Service API allows external integration via XML-RPC. It is primarily used for data analysis, tool integration, and mobile app development.

Core Endpoints

  • Common: Used for meta-calls like authentication and version checking.
  • Object: Used to call model methods via execute_kw.

Standard CRUD Flow

  1. Authenticate: Log in with DB name, username, and password to get a uid.
  2. Access Rights: Check if the user has permission (e.g., check_access_rights).
  3. Query: Use search or search_read with domain filters (e.g., [['is_company', '=', True]]).
  4. Manipulate: Create, write, or unlink records using positional and keyword arguments.

Advanced Operations

  • Workflows: Trigger signals using exec_workflow (requires account module for invoices).
  • Reports: Render PDF reports via the /xmlrpc/2/report endpoint and render_report method.