0.1.1 • Published 1 year ago

node-odoo-crud v0.1.1

Weekly downloads
-
License
ISC
Repository
github
Last release
1 year ago

Node-Odoo-CRUD

Odoo CRUD Node.js Library

This library provides a simple interface to interact with Odoo's XML-RPC API using Node.js.

It supports basic 
 CRUD (
  Create,
 Read, 
 Update,
  Delete
  list_records
 pagination
  search_records
  ) operations on Odoo models.

Installation

First, you need to install the node-odoo-crud package, which is a dependency for this library.

Bash

 $ npm install node-odoo-crud

Then, save the provided code in a file, for example, odoo.js.

Usage

const Odoo = require('./odoo');
Configuration
Create a configuration object with the following parameters:

url: The URL of your Odoo instance.
db: The database name.
username: Your Odoo username.
password: Your Odoo password.

const config = {
  url: 'https://your-odoo-instance.com',
  db: 'your-database-name',
  username: 'your-username',
  password: 'your-password'
};

const odoo = new Odoo(config);
Connecting to Odoo
Before performing any operations, you need to connect to your Odoo instance.
 This method will authenticate the user and retrieve the
  user's unique ID (uid).

odoo.connect((error, uid) => {
  if (error) {
    console.error('Connection error:', error);
  } else {
    console.log('Connected to Odoo with UID:', uid);
    // You can now perform CRUD operations
  }
});

Creating a Record

To create a record in a specific model:

const model = 'res.partner';
const data = {
  name: 'your odoo name',
  email: 'your odoo  email'
};

odoo.createRecord(model, data, (error, recordId) => {
  if (error) {
    console.error('Create record error:', error);
  } else {
    console.log('Record created with ID:', recordId);
  }
});

Reading Records

To read records from a specific model with a given domain:

const model = 'res.partner';
const domain = [['is_company', '=', true]];

odoo.readRecords(model, domain, (error, records) => {
  if (error) {
    console.error('Read records error:', error);
  } else {
    console.log('Records:', records);
  }
});

Updating a Record

To update a specific record in a model:

const model = 'res.partner';
const recordId = 1;  // Replace with the actual record ID
const data = {
  email: 'Your odoo email'
};

odoo.updateRecord(model, recordId, data, (error, success) => {
  if (error) {
    console.error('Update record error:', error);
  } else {
    console.log('Record updated:', success);
  }
});

Deleting a Record

To delete a specific record from a model:

const model = 'res.partner';
const recordId = 1;  // Replace with the actual record ID

odoo.deleteRecord(model, recordId, (error, success) => {
  if (error) {
    console.error('Delete record error:', error);
  } else {
    console.log('Record deleted:', success);
  }
});

License

This project is licensed under the MIT License.

Notes

Ensure that the node-odoo-crud package is installed and available in your project.
The config object should contain valid credentials and URLs for your Odoo instance.
Adjust the model names and fields in the examples according to your Odoo setup.
Feel free to modify and expand the library to suit your specific needs.

Thank You !

0.1.1

1 year ago

0.0.1

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago