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
- List & Search:
search(): รับ Domain filter และคืนค่ารายการ IDssearch_count(): คืนค่าจำนวน Records ที่ตรงตามเงื่อนไข
- Read:
read([ids], {'fields': [...]}): ดึงข้อมูลตาม IDs โดยระบุฟิลด์ที่ต้องการ (id จะถูกส่งกลับมาเสมอ)search_read(): ทางลัดสำหรับการทำ search และ read ในครั้งเดียว
- Write/Create/Delete:
create([{'field': value}]): สร้าง Record ใหม่write([ids], {'field': value}): แก้ไข Record (อัปเดตพร้อมกันหลายใบได้)unlink([ids]): ลบ Record
- Introspection:
fields_get(): ตรวจสอบโครงสร้างฟิลด์ของ Modelir.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
- Authenticate: Log in with DB name, username, and password to get a
uid. - Access Rights: Check if the user has permission (e.g.,
check_access_rights). - Query: Use
searchorsearch_readwith domain filters (e.g.,[['is_company', '=', True]]). - Manipulate: Create, write, or unlink records using positional and keyword arguments.
Advanced Operations
- Workflows: Trigger signals using
exec_workflow(requiresaccountmodule for invoices). - Reports: Render PDF reports via the
/xmlrpc/2/reportendpoint andrender_reportmethod.