Bluntly stripped down (forked) to the rightful minimum expression from https://github.com/skilld-labs/go-odoo
A Odoo API client enabling Go programs to interact with Odoo in a simple and uniform way.
Release v0.0.1 (released on 26-07-2017).
This API client package covers all basic functions from the odoo API. This include all calls to the following services :
- Login
- Create
- Update
- Delete
- Search
- Read
- SearchRead
- SearchCount
- DoRequest
Services listed above are basic low-level functions from Odoo API, there accessible by any client.
There also are high-level functions based on these low-level functions. Each model has its own functions. Actually we got:
- GetIdsByName
- GetByIds
- GetByName
- GetAll
- Create
- Update
- Delete
Direct model bindings and api functions can be automatically generated by the model2types.py
, model2api.py
files
in combination with a models.csv
.
import "github.com/xoes/go-odoo/api"
You have to construct a new client.
c := api.Config{"http://localhost:8069", nil, nil}
client, err := c.NewClient()
if err != nil {
fmt.Println(err.Error())
}
s := api.Session{"dbName", "user", "password"}
err = c.Login(s)
if err != nil {
fmt.Prinln(err.Error())
}
If you want to generate your own model bindings, you have to generate a models.csv file with the following
export structure: id model field_id/name
directly taken from the ir_model_model
table.
Put this file in the same file as the python scripts, then, you generate all models with the python command
python model2types.py
python model2api.py
Those commands will create as many files as you defined models in the models.csv
in ./api
and ./types
,
respectively.
go build
and you should be good to go...
This is an example of how to create a new sale order (after loading bindings from your database):
package main
import (
"fmt"
"github.com/xoes/go-odoo/api"
)
func main() {
c, err := api.NewClient("http://localhost:8069", nil)
if err != nil {
fmt.Println(err.Error())
}
err = c.Login("dbName", "admin", "password")
if err != nil {
fmt.Println(err.Error())
}
//get the sale order service
s := api.NewSaleOrderService(c)
//call the function GetAll() linked to the sale order service
so, err := s.GetAll()
if err != nil {
fmt.Println(err.Error())
}
fmt.Println(so)
}
- Tests
- New Odoo API functions (ex: report printing)
- If you have an issue, please report it on the issue tracker
Antoine Huret ([email protected])
Jean-Baptiste Guerraz ([email protected])