Files
gh-jamshu-jamshi-marketplac…/commands/api-reference.md
2025-11-29 18:50:06 +08:00

13 KiB

Complete API reference for the Odoo client and cache stores in generated PWAs.

What this command does:

  • Provides comprehensive API documentation
  • Lists all available methods and functions
  • Shows parameter types and return values
  • Includes code examples for each method
  • Helps developers use the generated code effectively

Odoo API Client Reference 🔌

The Odoo API client (src/lib/odoo.js or equivalent) provides methods for interacting with Odoo Studio models.

Configuration

Environment Variables

VITE_ODOO_URL=https://yourcompany.odoo.com
VITE_ODOO_DB=yourcompany-main
ODOO_API_KEY=your_api_key
ODOO_USERNAME=your.email@company.com
VITE_MODEL_NAME=x_expense

CRUD Operations

createRecord()

Create a new record in Odoo.

Signature:

async function createRecord(model, fields)

Parameters:

  • model (string) - Odoo model name (e.g., 'x_expense')
  • fields (object) - Field values to set

Returns: Promise - ID of created record

Example:

const newId = await odoo.createRecord('x_expense', {
  x_studio_description: 'Team lunch',
  x_studio_amount: 45.50,
  x_studio_date: '2025-01-15',
  x_studio_category: 'meal',
  x_studio_employee: odoo.formatMany2one(12)
});

console.log(`Created expense with ID: ${newId}`);

Error Handling:

try {
  const id = await odoo.createRecord('x_expense', fields);
} catch (error) {
  console.error('Failed to create:', error.message);
  // Handle error (show message to user, retry, etc.)
}

searchRecords()

Search and read records from Odoo.

Signature:

async function searchRecords(model, domain, fields, limit = null, offset = null)

Parameters:

  • model (string) - Odoo model name
  • domain (array) - Odoo domain filter (e.g., 'id', '>', 100)
  • fields (array) - List of field names to fetch
  • limit (number, optional) - Maximum number of records
  • offset (number, optional) - Number of records to skip

Returns: Promise<Array