godoorpc

package module
v0.0.0-...-16c9255 Latest Latest
Warning

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

Go to latest
Published: Apr 13, 2026 License: MIT Imports: 6 Imported by: 0

README

godoorpc

A minimal Go client library for the Odoo JSON-RPC API.

Overview

godoorpc provides a session-based connection to Odoo and a single RPC primitive that covers all operations: ExecuteKW. It stays close to the wire — no fake ORM, no proxy objects, no hidden network calls.

Install

go get github.com/lxkrmr/godoorpc

Usage

import "github.com/lxkrmr/godoorpc"

// Connect and authenticate
session, err := godoorpc.NewSession("http://localhost:8069", "mydb", "admin", "password")
if err != nil {
    // handle error
}

// Call any Odoo model method
result, err := session.ExecuteKW("res.partner", "search_read",
    godoorpc.Args{
        godoorpc.Domain{
            godoorpc.Condition{Field: "is_company", Op: "=", Value: true},
        },
    },
    godoorpc.KWArgs{
        "fields": []string{"name", "email"},
        "limit":  10,
    },
)

// Parse a domain from a string (useful for CLI tools)
domain, err := godoorpc.ParseDomain("[('is_company', '=', True)]")

Design

  • One RPC primitive — everything goes through ExecuteKW, which maps directly to Odoo's /web/dataset/call_kw endpoint.
  • Zero external dependencies — only Go stdlib.
  • Typed domainDomain, Condition, and Operator model Odoo's domain syntax with proper Go types.

See docs/adr/ for the reasoning behind key design decisions.

License

MIT

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Args

type Args []any

Args is a positional argument list for an RPC call.

type AuthError

type AuthError struct {
	Message string
}

AuthError is returned when Odoo rejects the login credentials.

func (*AuthError) Error

func (e *AuthError) Error() string

type Client

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

Client holds an authenticated session to Odoo.

func NewSession

func NewSession(url, db, user, password string) (*Client, error)

NewSession connects to Odoo at url, authenticates with the given credentials, and returns a Client ready to make RPC calls.

func (*Client) ExecuteKW

func (c *Client) ExecuteKW(model, method string, args Args, kwargs KWArgs) (any, error)

ExecuteKW calls method on model via /web/dataset/call_kw.

type Condition

type Condition struct {
	Field string
	Op    string
	Value any
}

Condition represents a single filter triple: (field, op, value). Op is a comparison operator such as "=", "!=", ">", "<", "ilike". This is distinct from Operator, which is a logical prefix operator.

func (Condition) MarshalJSON

func (c Condition) MarshalJSON() ([]byte, error)

MarshalJSON serializes Condition as a JSON array [field, op, value].

type Domain

type Domain []DomainNode

Domain is a list of DomainNodes used as a filter in Odoo RPC calls.

func ParseDomain

func ParseDomain(s string) (Domain, error)

ParseDomain parses an Odoo domain string into a Domain.

The input uses Python-style syntax with tuples and prefix operators:

[('is_company', '=', True)]
['|', ('name', 'ilike', 'foo'), ('name', 'ilike', 'bar')]

Supported Python literals: True, False, None, strings, integers, floats.

func (Domain) MarshalJSON

func (d Domain) MarshalJSON() ([]byte, error)

MarshalJSON serializes Domain as a JSON array. A nil or empty Domain marshals to [] — never null. Odoo expects an empty array for an unrestricted domain, not null.

type DomainNode

type DomainNode interface {
	// contains filtered or unexported methods
}

DomainNode is either a Condition or an Operator.

type KWArgs

type KWArgs map[string]any

KWArgs is a keyword argument map for an RPC call.

type Operator

type Operator string

Operator is a prefix domain operator.

const (
	Or  Operator = "|"
	And Operator = "&"
	Not Operator = "!"
)

type RPCError

type RPCError struct {
	Code    int
	Message string
}

RPCError is returned when Odoo responds with a JSON-RPC error.

func (*RPCError) Error

func (e *RPCError) Error() string

type Session

type Session interface {
	ExecuteKW(model, method string, args Args, kwargs KWArgs) (any, error)
}

Session is the interface for making RPC calls to Odoo.

Jump to

Keyboard shortcuts

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