odoo

package module
v1.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 21, 2020 License: Apache-2.0 Imports: 6 Imported by: 0

README

go-odoo

An Odoo API client enabling Go programs to interact with Odoo in a simple and uniform way.

GitHub license GoDoc Go Report Card GitHub issues

Usage

Generate your models

Define the environment variables to be able to connect to your odoo instance :

(Don't set ODOO_MODELS if you want all your models to be generated)

export ODOO_ADMIN=admin
export ODOO_PASSWORD=password
export ODOO_DATABASE=odoo
export ODOO_URL=http://localhost:8069
export ODOO_MODELS="crm.lead"

ODOO_REPO_PATH is the path where the repository will be downloaded (by default its GOPATH):

export ODOO_REPO_PATH=$(echo $GOPATH | awk -F ':' '{ print $1 }')/src/github.com/ahuret/go-odoo

Download library and generate models :

go get github.com/ahuret/go-odoo
cd $ODOO_REPO_PATH
go generate

That's it ! Your models have been generated !

Enjoy coding!

(All exemples on this README are based on model crm.lead)

package main
	
import (
	odoo "github.com/ahuret/go-odoo"
)

func main() {
	c, err := odoo.NewClient(&odoo.ClientConfig{
		Admin:    "admin",
		Password: "password",
		Database: "odoo",
		URL:      "http://localhost:8069",
	})
	if err != nil {
		log.Fatal(err)
	}
	crm := &odoo.CrmLead{
		Name: odoo.NewString("my first opportunity"),
	}
	if id, err := c.CreateCrmLead(crm); err != nil {
		log.Fatal(err)
	} else {
		fmt.Printf("the id of the new crm.lead is %d", id)
	}
}

Models

Generated models contains high level functions to interact with models in an easy and golang way. It covers the most common usage and contains for each models those functions :

Create
func (c *Client) CreateCrmLead(cl *CrmLead) (int64, error) {}
Update
func (c *Client) UpdateCrmLead(cl *CrmLead) error {}
func (c *Client) UpdateCrmLeads(ids []int64, cl *CrmLead) error {}
Delete
func (c *Client) DeleteCrmLead(id int64) error {}
func (c *Client) DeleteCrmLeads(ids []int64) error {}
Get
func (c *Client) GetCrmLead(id int64) (*CrmLead, error) {}
func (c *Client) GetCrmLeads(ids []int64) (*CrmLeads, error) {}
Find

Find is powerful and allow you to query a model and filter results. Criteria and Options

func (c *Client) FindCrmLeads(criteria *Criteria, options *Options) (*CrmLeads, error) {}

Types

The library contains custom types to improve the usability :

Basic types
func NewString(v string) *String {}
func (s *String) Get() string {}

func NewInt(v int64) *Int {}
func (i *Int) Get() int64 {}

func NewBool(v bool) *Bool {}
func (b *Bool) Get() bool {}

func NewSelection(v interface{}) *Selection {}
func (s *Selection) Get() (interface{}) {}

func NewTime(v time.Time) *Time {}
func (t *Time) Get() time.Time {}

func NewFloat(v float64) *Float {}
func (f *Float) Get() float64 {}
Relational types
func NewMany2One(id int64, name string) *Many2One {}
func (m *Many2One) Get() int64 {}

func NewRelation() *Relation {}
func (r *Relation) Get() []int64 {}

one2many and many2many are represented by the Relation type and allow you to execute special actions as defined here.

Criteria and Options

Criteria is a set of criterion and allow you to query models. More informations

Options allow you to filter results.

cls, err := c.FindCrmLeads(odoo.NewCriteria().Add("user_id.name", "=", "John Doe"), odoo.NewOptions().Limit(2))

Low level functions

All high level functions are based on basic odoo webservices functions.

These functions give you more flexibility but less usability. We recommand you to use models functions (high level).

Here are available low level functions :

func (c *Client) Create(model string, values interface{}) (int64, error) {}
func (c *Client) Update(model string, ids []int64, values interface{}) error {}
func (c *Client) Delete(model string, ids []int64) error {}
func (c *Client) SearchRead(model string, criteria *Criteria, options *Options, elem interface{}) error {}
func (c *Client) Read(model string, ids []int64, options *Options, elem interface{}) error {}
func (c *Client) Count(model string, criteria *Criteria, options *Options) (int64, error) {}
func (c *Client) Search(model string, criteria *Criteria, options *Options) ([]int64, error) {}
func (c *Client) FieldsGet(model string, options *Options) (map[string]interface{}, error) {}
func (c *Client) ExecuteKw(method, model string, args []interface{}, options *Options) (interface{}, error) {}

Todo

  • Tests
  • Modular template

Issues

Contributors

Antoine Huret ([email protected])

Jean-Baptiste Guerraz ([email protected])

Documentation

Overview

Package odoo contains client code of library

Index

Constants

View Source
const IrModelFieldsModel = "ir.model.fields"

IrModelFieldsModel is the odoo model name

View Source
const IrModelModel = "ir.model"

IrModelModel is the odoo model name

Variables

This section is empty.

Functions

This section is empty.

Types

type Bool

type Bool struct {
	// contains filtered or unexported fields
}

Bool is a bool wrapper

func NewBool

func NewBool(v bool) *Bool

NewBool creates a new *Bool.

func (*Bool) Get

func (b *Bool) Get() bool

Get *Bool value.

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client provides high and low level functions to interact with odoo

func NewClient

func NewClient(cfg *ClientConfig) (*Client, error)

NewClient creates a new *Client.

func (*Client) Close

func (c *Client) Close()

Close closes all opened client connections.

func (*Client) Count

func (c *Client) Count(model string, criteria *Criteria, options *Options) (int64, error)

Count model records matching with *Criteria. https://www.odoo.com/documentation/13.0/webservices/odoo.html#count-records

func (*Client) Create

func (c *Client) Create(model string, values interface{}) (int64, error)

Create a new model. https://www.odoo.com/documentation/13.0/webservices/odoo.html#create-records

func (*Client) CreateIrModel

func (c *Client) CreateIrModel(im *IrModel) (int64, error)

CreateIrModel creates a new ir.model model and returns its id.

func (*Client) CreateIrModelFields

func (c *Client) CreateIrModelFields(imf *IrModelFields) (int64, error)

CreateIrModelFields creates a new ir.model.fields model and returns its id.

func (*Client) Delete

func (c *Client) Delete(model string, ids []int64) error

Delete existing model row(s). https://www.odoo.com/documentation/13.0/webservices/odoo.html#delete-records

func (*Client) DeleteIrModel

func (c *Client) DeleteIrModel(id int64) error

DeleteIrModel deletes an existing ir.model record.

func (*Client) DeleteIrModelFields

func (c *Client) DeleteIrModelFields(id int64) error

DeleteIrModelFields deletes an existing ir.model.fields record.

func (*Client) DeleteIrModelFieldss

func (c *Client) DeleteIrModelFieldss(ids []int64) error

DeleteIrModelFieldss deletes existing ir.model.fields records.

func (*Client) DeleteIrModels

func (c *Client) DeleteIrModels(ids []int64) error

DeleteIrModels deletes existing ir.model records.

func (*Client) ExecuteKw

func (c *Client) ExecuteKw(method, model string, args []interface{}, options *Options) (interface{}, error)

ExecuteKw is a RPC function. The lowest library function. It is use for all function related to "xmlrpc/2/object" endpoint.

func (*Client) FieldsGet

func (c *Client) FieldsGet(model string, options *Options) (map[string]interface{}, error)

FieldsGet inspect model fields. https://www.odoo.com/documentation/13.0/webservices/odoo.html#listing-record-fields

func (*Client) FindIrModelFieldss

func (c *Client) FindIrModelFieldss(criteria *Criteria, options *Options) (*IrModelFieldss, error)

FindIrModelFieldss finds ir.model.fields records by querying it and filtering it with criteria and options.

func (*Client) FindIrModels

func (c *Client) FindIrModels(criteria *Criteria, options *Options) (*IrModels, error)

FindIrModels finds ir.model records by querying it and filtering it with criteria and options.

func (*Client) GetIrModel

func (c *Client) GetIrModel(id int64) (*IrModel, error)

GetIrModel gets ir.model existing record.

func (*Client) GetIrModelFields

func (c *Client) GetIrModelFields(id int64) (*IrModelFields, error)

GetIrModelFields gets ir.model.fields existing record.

func (*Client) GetIrModelFieldss

func (c *Client) GetIrModelFieldss(ids []int64) (*IrModelFieldss, error)

GetIrModelFieldss gets ir.model.fields existing records.

func (*Client) GetIrModels

func (c *Client) GetIrModels(ids []int64) (*IrModels, error)

GetIrModels gets ir.model existing records.

func (*Client) Read

func (c *Client) Read(model string, ids []int64, options *Options, elem interface{}) error

Read model records matching with ids. https://www.odoo.com/documentation/13.0/webservices/odoo.html#read-records

func (*Client) Search

func (c *Client) Search(model string, criteria *Criteria, options *Options) ([]int64, error)

Search model record ids matching with *Criteria. https://www.odoo.com/documentation/13.0/webservices/odoo.html#list-records

func (*Client) SearchRead

func (c *Client) SearchRead(model string, criteria *Criteria, options *Options, elem interface{}) error

SearchRead search model records matching with *Criteria and read it. https://www.odoo.com/documentation/13.0/webservices/odoo.html#search-and-read

func (*Client) Update

func (c *Client) Update(model string, ids []int64, values interface{}) error

Update existing model row(s). https://www.odoo.com/documentation/13.0/webservices/odoo.html#update-records

func (*Client) UpdateIrModel

func (c *Client) UpdateIrModel(im *IrModel) error

UpdateIrModel pdates an existing ir.model record.

func (*Client) UpdateIrModelFields

func (c *Client) UpdateIrModelFields(imf *IrModelFields) error

UpdateIrModelFields pdates an existing ir.model.fields record.

func (*Client) UpdateIrModelFieldss

func (c *Client) UpdateIrModelFieldss(ids []int64, imf *IrModelFields) error

UpdateIrModelFieldss updates existing ir.model.fields records. All records (represented by ids) will be updated by imf values.

func (*Client) UpdateIrModels

func (c *Client) UpdateIrModels(ids []int64, im *IrModel) error

UpdateIrModels updates existing ir.model records. All records (represented by ids) will be updated by im values.

func (*Client) Version

func (c *Client) Version() (Version, error)

Version get informations about your odoo instance version.

type ClientConfig

type ClientConfig struct {
	Database string
	Admin    string
	Password string
	URL      string
}

ClientConfig is the configuration to create a new *Client by givin connection infomations.

type Criteria

type Criteria []*criterion

Criteria is a set of criterion, each criterion is a triple (field_name, operator, value). It allow you to search models. see documentation: https://www.odoo.com/documentation/13.0/reference/orm.html#reference-orm-domains

func NewCriteria

func NewCriteria() *Criteria

NewCriteria creates a new *Criteria.

func (*Criteria) Add

func (c *Criteria) Add(field, operator string, value interface{}) *Criteria

Add a new criterion to a *Criteria.

type Float

type Float struct {
	// contains filtered or unexported fields
}

Float is a float64 wrapper

func NewFloat

func NewFloat(v float64) *Float

NewFloat creates a new *Float.

func (*Float) Get

func (f *Float) Get() float64

Get *Float value.

type Int

type Int struct {
	// contains filtered or unexported fields
}

Int is an int64 wrapper

func NewInt

func NewInt(v int64) *Int

NewInt creates a new *Int.

func (*Int) Get

func (i *Int) Get() int64

Get *Int value.

type IrModel

type IrModel struct {
	LastUpdate        *Time      `xmlrpc:"__last_update,omptempty"`
	AccessIds         *Relation  `xmlrpc:"access_ids,omptempty"`
	Count             *Int       `xmlrpc:"count,omptempty"`
	CreateDate        *Time      `xmlrpc:"create_date,omptempty"`
	CreateUid         *Many2One  `xmlrpc:"create_uid,omptempty"`
	DisplayName       *String    `xmlrpc:"display_name,omptempty"`
	FieldId           *Relation  `xmlrpc:"field_id,omptempty"`
	Id                *Int       `xmlrpc:"id,omptempty"`
	Info              *String    `xmlrpc:"info,omptempty"`
	InheritedModelIds *Relation  `xmlrpc:"inherited_model_ids,omptempty"`
	Model             *String    `xmlrpc:"model,omptempty"`
	Modules           *String    `xmlrpc:"modules,omptempty"`
	Name              *String    `xmlrpc:"name,omptempty"`
	RuleIds           *Relation  `xmlrpc:"rule_ids,omptempty"`
	State             *Selection `xmlrpc:"state,omptempty"`
	Transient         *Bool      `xmlrpc:"transient,omptempty"`
	ViewIds           *Relation  `xmlrpc:"view_ids,omptempty"`
	WriteDate         *Time      `xmlrpc:"write_date,omptempty"`
	WriteUid          *Many2One  `xmlrpc:"write_uid,omptempty"`
}

IrModel represents ir.model model

type IrModelFields

type IrModelFields struct {
	LastUpdate       *Time      `xmlrpc:"__last_update,omptempty"`
	Column1          *String    `xmlrpc:"column1,omptempty"`
	Column2          *String    `xmlrpc:"column2,omptempty"`
	CompleteName     *String    `xmlrpc:"complete_name,omptempty"`
	Compute          *String    `xmlrpc:"compute,omptempty"`
	Copied           *Bool      `xmlrpc:"copied,omptempty"`
	CreateDate       *Time      `xmlrpc:"create_date,omptempty"`
	CreateUid        *Many2One  `xmlrpc:"create_uid,omptempty"`
	Depends          *String    `xmlrpc:"depends,omptempty"`
	DisplayName      *String    `xmlrpc:"display_name,omptempty"`
	Domain           *String    `xmlrpc:"domain,omptempty"`
	FieldDescription *String    `xmlrpc:"field_description,omptempty"`
	Groups           *Relation  `xmlrpc:"groups,omptempty"`
	Help             *String    `xmlrpc:"help,omptempty"`
	Id               *Int       `xmlrpc:"id,omptempty"`
	Index            *Bool      `xmlrpc:"index,omptempty"`
	Model            *String    `xmlrpc:"model,omptempty"`
	ModelId          *Many2One  `xmlrpc:"model_id,omptempty"`
	Modules          *String    `xmlrpc:"modules,omptempty"`
	Name             *String    `xmlrpc:"name,omptempty"`
	OnDelete         *Selection `xmlrpc:"on_delete,omptempty"`
	Readonly         *Bool      `xmlrpc:"readonly,omptempty"`
	Related          *String    `xmlrpc:"related,omptempty"`
	RelatedFieldId   *Many2One  `xmlrpc:"related_field_id,omptempty"`
	Relation         *String    `xmlrpc:"relation,omptempty"`
	RelationField    *String    `xmlrpc:"relation_field,omptempty"`
	RelationFieldId  *Many2One  `xmlrpc:"relation_field_id,omptempty"`
	RelationTable    *String    `xmlrpc:"relation_table,omptempty"`
	Required         *Bool      `xmlrpc:"required,omptempty"`
	Selectable       *Bool      `xmlrpc:"selectable,omptempty"`
	Selection        *String    `xmlrpc:"selection,omptempty"`
	SelectionIds     *Relation  `xmlrpc:"selection_ids,omptempty"`
	Size             *Int       `xmlrpc:"size,omptempty"`
	State            *Selection `xmlrpc:"state,omptempty"`
	Store            *Bool      `xmlrpc:"store,omptempty"`
	Translate        *Bool      `xmlrpc:"translate,omptempty"`
	Ttype            *Selection `xmlrpc:"ttype,omptempty"`
	WriteDate        *Time      `xmlrpc:"write_date,omptempty"`
	WriteUid         *Many2One  `xmlrpc:"write_uid,omptempty"`
}

IrModelFields represents ir.model.fields model

type IrModelFieldss

type IrModelFieldss []IrModelFields

IrModelFieldss represents array of ir.model.fields model

type IrModels

type IrModels []IrModel

IrModels represents array of ir.model model

type Many2One

type Many2One struct {
	ID   int64
	Name string
}

Many2One represents odoo many2one type. https://www.odoo.com/documentation/13.0/reference/orm.html#relational-fields

func NewMany2One

func NewMany2One(id int64, name string) *Many2One

NewMany2One create a new *Many2One.

func (*Many2One) Get

func (m *Many2One) Get() int64

Get *Many2One value.

type Options

type Options map[string]interface{}

Options allow you to filter search results.

func NewOptions

func NewOptions() *Options

NewOptions creates a new *Options

func (*Options) Add

func (o *Options) Add(opt string, v interface{}) *Options

Add on option by providing option name and value.

func (*Options) AllFields

func (o *Options) AllFields(fields ...string) *Options

AllFields is useful for FieldsGet function. It represents the fields to document you want odoo to return. https://www.odoo.com/documentation/13.0/reference/orm.html#fields-views

func (*Options) Attributes

func (o *Options) Attributes(attributes ...string) *Options

Attributes is useful for FieldsGet function. It represents the attributes to document you want odoo to return. https://www.odoo.com/documentation/13.0/reference/orm.html#fields-views

func (*Options) FetchFields

func (o *Options) FetchFields(fields ...string) *Options

FetchFields allow you to precise the model fields you want odoo to return. https://www.odoo.com/documentation/13.0/webservices/odoo.html#search-and-read

func (*Options) Limit

func (o *Options) Limit(limit int) *Options

Limit adds the limit options. https://www.odoo.com/documentation/13.0/webservices/odoo.html#pagination

func (*Options) Offset

func (o *Options) Offset(offset int) *Options

Offset adds the offset options. https://www.odoo.com/documentation/13.0/webservices/odoo.html#pagination

type Relation

type Relation struct {
	// contains filtered or unexported fields
}

Relation represents odoo one2many and many2many types. https://www.odoo.com/documentation/13.0/reference/orm.html#relational-fields

func NewRelation

func NewRelation() *Relation

NewRelation creates a new *Relation.

func (*Relation) AddNewRecord

func (r *Relation) AddNewRecord(values interface{})

AddNewRecord is an helper to create a new record of one2many or many2many. https://www.odoo.com/documentation/13.0/reference/orm.html#odoo.models.Model.write

func (*Relation) AddRecord

func (r *Relation) AddRecord(record int)

AddRecord is an helper to add an existing record of one2many or many2many. https://www.odoo.com/documentation/13.0/reference/orm.html#odoo.models.Model.write

func (*Relation) DeleteRecord

func (r *Relation) DeleteRecord(record int64)

DeleteRecord is an helper to delete an existing record of one2many or many2many. https://www.odoo.com/documentation/13.0/reference/orm.html#odoo.models.Model.write

func (*Relation) Get

func (r *Relation) Get() []int64

Get *Relation value.

func (*Relation) RemoveAllRecords

func (r *Relation) RemoveAllRecords()

RemoveAllRecords is an helper to remove all records of one2many or many2many. https://www.odoo.com/documentation/13.0/reference/orm.html#odoo.models.Model.write

func (*Relation) RemoveRecord

func (r *Relation) RemoveRecord(record int64)

RemoveRecord is an helper to remove an existing record of one2many or many2many. https://www.odoo.com/documentation/13.0/reference/orm.html#odoo.models.Model.write

func (*Relation) ReplaceAllRecords

func (r *Relation) ReplaceAllRecords(newRecords []int64)

ReplaceAllRecords is an helper to replace all records of one2many or many2many. https://www.odoo.com/documentation/13.0/reference/orm.html#odoo.models.Model.write

func (*Relation) UpdateRecord

func (r *Relation) UpdateRecord(record int64, values interface{})

UpdateRecord is an helper to update an existing record of one2many or many2many. https://www.odoo.com/documentation/13.0/reference/orm.html#odoo.models.Model.write

type Selection

type Selection struct {
	// contains filtered or unexported fields
}

Selection represents selection odoo type.

func NewSelection

func NewSelection(v interface{}) *Selection

NewSelection creates a new *Selection.

func (*Selection) Get

func (s *Selection) Get() interface{}

Get *Selection value.

type String

type String struct {
	// contains filtered or unexported fields
}

String is a string wrapper

func NewString

func NewString(v string) *String

NewString creates a new *String.

func (*String) Get

func (s *String) Get() string

Get *String value.

type Time

type Time struct {
	// contains filtered or unexported fields
}

Time is a time.Time wrapper.

func NewTime

func NewTime(v time.Time) *Time

NewTime creates a new *Time.

func (*Time) Get

func (t *Time) Get() time.Time

Get *Time value.

type Version

type Version struct {
	ServerVersion     *String     `xmlrpc:"server_version"`
	ServerVersionInfo interface{} `xmlrpc:"server_version_info"`
	ServerSerie       *String     `xmlrpc:"server_serie"`
	ProtocolVersion   *Int        `xmlrpc:"protocol_version"`
}

Version describes odoo instance version.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL