Code Monkey home page Code Monkey logo

odoo-api's Introduction

odoo-api

Odoo REST API

It provides a simple REST API for odoo server.

getOne  => GET    /:model/:id
getMany => GET    /:model/?id=100&id=200
getMany => GET    /:model/?domain=[["ref", "=", "33117579"]]&fields=["name", "category_id", "customer"])
getMany => GET    /:model/?filter={ company_id: 1, "name": { "ilike": "%John%" }}&fields=["name", "display_name"]&pagination={ "page": 1 , "perPage": 5 }&sort={ "field": "name", "order": "desc" }
create  => POST   /:model
update  => PUT    /:model/:id
delete  => DELETE /:model/:id

Magic ORM syntax

  • ORM syntax
  • For create or update method you can apply the magic ORM syntax to manipulate the relation objects.
  • For Example if you want to add/update a category (many2many) for a res.partner
{
  name: 'Muster Mann',
  ref: 100,
  category_id: [[0, 0, { name: 'test', display_name: 'Mocha Test', color: 1}]] // create a new category
}
# category_id = 20, color = 1
{
  name: 'Muster Mann',
  ref: 100,
  category_id: [[1, 20, { name: 'test', display_name: 'Mocha Test', color: 2}]] // update color to 2
}
# category_id = 8, an existing category
{
  name: 'Muster Mann',
  ref: 100,
  category_id: [[4, 8, 0]] // add category (8) to the current set of categories
}
# category_id = 8, an existing category
{
  name: 'Muster Mann',
  ref: 100,
  category_id: [[5, 0, 0]] // remove all categories
}
# category_id = 8, an existing category
{
  name: 'Muster Mann',
  ref: 100,
  category_id: [[6, 0, [8]]] // replace the current set of categories with 8
}

Create sale.order

# partner_id = 100, product_id_1 = 50, uom_id_1 = 2, product_id_2 = 51, uom_id_2 = 3
let saleOrderLine1 = {
  name: 'iPhone 7 Plus 128GB',
  price_unit: 103000,
  product_id: product_id_1,
  uom_id: uom_id_1,
  product_uom_qty: 1
}

let saleOrderLine2 = {
  name: 'Remote keyboard for iPad - Bluetooth',
  price_unit: 60,
  product_id: product_id_2,
  uom_id: uom_id_2,
  product_uom_qty: 1
}

let saleOrder = {
  partner_id,
  name: '[e-commerce] 20200419/SO100',
  client_order_ref: '20200419',
  create_date: '2020-04-19',
  date_order: '2020-04-19',
  order_line: [[0, 0, saleOrderLine1], [0, 0, saleOrderLine2]], // (0, _, values) syntax
  state: 'draft'
}

Tests

Before running tests, you need to provide the host address of odoo server, an valid login and password. Make sure that this login has permission to make rpc calls.

# test/settings.js

const settings = {
  baseURL: '',
  db: '',
  login: '',
  password: ''
} 
  • Start server
yarn build

export ODOO_HOST=http://0.0.0.0:8069
export PORT=9000

node lib/index.js

# Starting Odoo REST API... 9000
  • Start postgres, odoo and odoo REST API with docker
docker-compose up
curl -d '{"db": "odoo", "login": "a.user", "password": "secret" }' -H 'Content-Type: application/json'  http://localhost:9000/auth

# prettier print JSON response from curl
curl -d '{"db": "odoo", "login": "a.user", "password": "secret" }' -H 'Content-Type: application/json'  http://localhost:9000/auth | json_pp

odoo-api's People

Contributors

dependabot[bot] avatar toantraz avatar tools-utils avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.