1.0.1 • Published 6 months ago

nestjs-odoo v1.0.1

Weekly downloads
-
License
MIT
Repository
-
Last release
6 months ago

NestJS Odoo Integration

A NestJS module for integrating with Odoo using XML-RPC.

Installation

npm install nestjs-odoo

Usage

// app.module.ts
import { Module } from '@nestjs/common';
import { OdooModule } from 'nestjs-odoo';

@Module({
  imports: [
    OdooModule.forRoot({
      url: 'your-odoo-server.com',
      port: 8069,
      db: 'your-database',
      username: 'your-username',
      password: 'your-password',
    }),
  ],
})
export class AppModule {}

// your.service.ts
import { Injectable } from '@nestjs/common';
import { OdooService } from 'nestjs-odoo';

@Injectable()
export class YourService {
  constructor(private readonly odooService: OdooService) {}

  async getPartners() {
    const partners = await this.odooService.searchRead(
      'res.partner',
      [['is_company', '=', true]],
      ['name', 'email', 'phone'],
    );
    return partners;
  }
}

Available Methods

  • authenticate(): Authenticate with Odoo server
  • search(): Search for records
  • read(): Read record details
  • searchRead(): Combine search and read operations
  • create(): Create new records
  • write(): Update existing records
  • unlink(): Delete records

Configuration

Basic Configuration

Use forRoot() to provide static configuration:

OdooModule.forRoot({
  url: 'your-odoo-server.com',
  port: 8069,
  db: 'your-database',
  username: 'your-username',
  password: 'your-password',
});

Async Configuration

Use forRootAsync() for dynamic configuration:

OdooModule.forRootAsync({
  inject: [ConfigService],
  useFactory: (configService: ConfigService) => ({
    url: configService.get('ODOO_URL'),
    port: configService.get('ODOO_PORT'),
    db: configService.get('ODOO_DB'),
    username: configService.get('ODOO_USERNAME'),
    password: configService.get('ODOO_PASSWORD'),
  }),
});

API Reference

OdooService Methods

authenticate()

Authenticates with the Odoo server and returns a user ID.

search(model: string, domain: any[], options: any = {})

Searches for records matching the given domain.

read(model: string, ids: number[], fields: string[] = [])

Reads the specified fields of records with the given IDs.

searchRead(model: string, domain: any[] = [], fields: string[] = [], options: any = {})

Combines search and read operations in a single call.

create(model: string, values: any)

Creates a new record with the given values.

write(model: string, id: number, values: any)

Updates an existing record with the given values.

unlink(model: string, id: number)

Deletes the specified record.

License

MIT

1.0.1

6 months ago

1.0.0

6 months ago