Documentation ¶
Index ¶
- Constants
- Variables
- func DecodeResult(buf io.Reader, result interface{}) error
- type Client
- type ClientOptions
- type Date
- func (d Date) IsWithinMonth(year, month int) bool
- func (d Date) IsWithinTimeRange(from, to time.Time) bool
- func (d *Date) IsZero() bool
- func (d Date) MarshalJSON() ([]byte, error)
- func (d *Date) String() string
- func (d Date) ToTime() time.Time
- func (d *Date) UnmarshalJSON(b []byte) error
- func (d Date) WithLocation(loc *time.Location) Date
- type Filter
- type JSONRPCError
- type JSONRPCRequest
- type JSONRPCResponse
- type List
- type LoginOptions
- type Method
- type QueryExecutor
- type SearchReadModel
- type Session
- func (s *Session) CreateGenericModel(ctx context.Context, model string, data interface{}) (int, error)
- func (s *Session) DeleteGenericModel(ctx context.Context, model string, ids []int) error
- func (s *Session) ExecuteQuery(ctx context.Context, path string, model interface{}, into interface{}) error
- func (s *Session) SearchGenericModel(ctx context.Context, model SearchReadModel, into interface{}) error
- func (s *Session) UpdateGenericModel(ctx context.Context, model string, id int, data interface{}) error
- type WriteModel
Constants ¶
const ( DateFormat = "2006-01-02" TimeFormat = "15:04:05" DateTimeFormat = DateFormat + " " + TimeFormat )
Variables ¶
var ( // ErrInvalidCredentials is an error that indicates an authentication error due to missing or invalid credentials. ErrInvalidCredentials = errors.New("invalid credentials") )
Functions ¶
func DecodeResult ¶
DecodeResult takes a buffer, decodes the intermediate JSONRPCResponse and then the contained "result" field into "result".
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is the base struct that holds information required to talk to Odoo
func NewClient ¶
func NewClient(baseURL string, options ClientOptions) (*Client, error)
NewClient returns a new Client.
type ClientOptions ¶ added in v0.8.0
type ClientOptions struct { // UseDebugLogger sets the http.Transport field of the internal http client with a transport implementation that logs the raw contents of requests and responses. // The logger is retrieved from the request's context via logr.FromContextOrDiscard. // The log level used is '2'. // Any "password":"..." byte content is replaced with a placeholder to avoid leaking credentials. // Still, this should not be called in production as other sensitive information might be leaked. // This method is meant to be called before any requests are made (for example after setting up the Client). UseDebugLogger bool }
ClientOptions configures the Odoo client.
type Date ¶ added in v0.2.0
Date is an Odoo-specific format of a timestamp
func MustParseDate ¶ added in v0.8.0
MustParseDate parses the given value in DateFormat or panics if it fails.
func MustParseDateTime ¶ added in v0.8.0
MustParseDateTime parses the given value in DateTimeFormat or panics if it fails.
func (Date) IsWithinMonth ¶ added in v0.2.0
func (Date) IsWithinTimeRange ¶ added in v1.0.0
IsWithinTimeRange returns true if the date is between the given times. The date is considered in the range if from and to equal to the date respectively.
func (Date) MarshalJSON ¶ added in v0.2.0
func (*Date) UnmarshalJSON ¶ added in v0.2.0
type Filter ¶
type Filter interface{}
Filter to use in queries, usually in the format of [predicate, operator, value], eg ["employee_id.user_id.id", "=", 123]
type JSONRPCError ¶ added in v0.8.0
type JSONRPCError struct { Message string `json:"message,omitempty"` Code int `json:"code,omitempty"` Data map[string]interface{} `json:"data,omitempty"` }
JSONRPCError holds error information.
type JSONRPCRequest ¶ added in v0.8.0
type JSONRPCRequest struct { // ID should be a randomly generated value, either as a string or int. // The server will return this value in the response. ID string `json:"id,omitempty"` // JSONRPC is always set to "2.0" JSONRPC string `json:"jsonrpc,omitempty"` // Method to call, usually just "call" Method string `json:"method,omitempty"` // Params includes the actual request payload. Params interface{} `json:"params,omitempty"` }
JSONRPCRequest represents a generic json-rpc request
func NewJSONRPCRequest ¶ added in v0.8.0
func NewJSONRPCRequest(params interface{}) *JSONRPCRequest
NewJSONRPCRequest returns a JSON RPC request with its protocol fields populated:
* "id" will be set to a random UUID * "jsonrpc" will be set to "2.0" * "method" will be set to "call" * "params" will be set to whatever was passed in
type JSONRPCResponse ¶ added in v0.8.0
type JSONRPCResponse struct { // ID that was sent with the request ID string `json:"id,omitempty"` // JSONRPC is always set to "2.0" JSONRPC string `json:"jsonrpc,omitempty"` // Result payload Result *json.RawMessage `json:"result,omitempty"` // Optional error field Error *JSONRPCError `json:"error,omitempty"` }
JSONRPCResponse holds the JSONRPC response.
type List ¶ added in v0.11.0
type List[T any] struct { Items []T `json:"records,omitempty"` }
List contains a slice of T.
type LoginOptions ¶ added in v0.8.0
type LoginOptions struct { DatabaseName string `json:"db,omitempty"` Username string `json:"login,omitempty"` Password string `json:"password,omitempty"` }
LoginOptions contains all necessary authentication parameters.
type Method ¶ added in v0.8.0
type Method string
Method identifies the type of write operation.
const ( // MethodWrite is used to update existing records. MethodWrite Method = "write" // MethodCreate is used to create new records. MethodCreate Method = "create" // MethodRead is used to read records. MethodRead Method = "read" // MethodDelete is used to delete existing records. MethodDelete Method = "unlink" )
type QueryExecutor ¶ added in v0.8.0
type QueryExecutor interface { // SearchGenericModel accepts a SearchReadModel and unmarshal the response into the given pointer. // Depending on the JSON fields returned a custom json.Unmarshaler needs to be written since Odoo sets undefined fields to `false` instead of null. SearchGenericModel(ctx context.Context, model SearchReadModel, into interface{}) error // CreateGenericModel accepts a payload and executes a query to create the new data record. CreateGenericModel(ctx context.Context, model string, data interface{}) (int, error) // UpdateGenericModel accepts a payload and executes a query to update an existing data record. UpdateGenericModel(ctx context.Context, model string, id int, data interface{}) error // DeleteGenericModel accepts a model identifier and data records IDs as payload and executes a query to delete multiple existing data records. // At least one ID is required. DeleteGenericModel(ctx context.Context, model string, ids []int) error // ExecuteQuery runs a generic JSONRPC query with the given model as payload and deserializes the response. ExecuteQuery(ctx context.Context, path string, model interface{}, into interface{}) error }
QueryExecutor runs queries against Odoo API.
type SearchReadModel ¶ added in v0.8.0
type SearchReadModel struct { Model string `json:"model,omitempty"` Domain []Filter `json:"domain,omitempty"` Fields []string `json:"fields,omitempty"` Limit int `json:"limit,omitempty"` Offset int `json:"offset,omitempty"` }
SearchReadModel is used as "params" in requests to "dataset/search_read" endpoints.
type Session ¶
type Session struct { // SessionID is the session SessionID. // Is always set, no matter the authentication outcome. SessionID string `json:"session_id,omitempty"` // UID is the user's ID as an int, or the boolean `false` if authentication failed. UID int `json:"uid,omitempty"` // contains filtered or unexported fields }
Session information
func Open ¶ added in v0.8.0
Open returns a new Session by trying to log in. The URL must be in the format of `https://user:pass@host[:port]/db-name`. It returns error if baseURL is not parseable with url.Parse or if the Login failed.
func RestoreSession ¶ added in v0.8.0
RestoreSession restores a Session based on existing Session.SessionID and Session.UID. It's not validated if the session is valid.
func (*Session) CreateGenericModel ¶ added in v0.8.0
func (s *Session) CreateGenericModel(ctx context.Context, model string, data interface{}) (int, error)
CreateGenericModel implements QueryExecutor.
func (*Session) DeleteGenericModel ¶ added in v0.8.0
DeleteGenericModel implements QueryExecutor.
func (*Session) ExecuteQuery ¶ added in v0.8.0
func (s *Session) ExecuteQuery(ctx context.Context, path string, model interface{}, into interface{}) error
ExecuteQuery implements QueryExecutor.
func (*Session) SearchGenericModel ¶ added in v0.8.0
func (s *Session) SearchGenericModel(ctx context.Context, model SearchReadModel, into interface{}) error
SearchGenericModel implements QueryExecutor.
type WriteModel ¶ added in v0.8.0
type WriteModel struct { Model string `json:"model"` Method Method `json:"method"` // Args contains the record to create or update. // If Method is MethodCreate, then the slice may contain a single entity without an ID parameter. // Example: // Args[0] = {Name: "New Name"} // If Method is MethodWrite, then the first item has to be an array of the numeric ID of the existing record. // Example: // Args[0] = [221] // Args[1] = {Name: "Updated Name"} Args []interface{} `json:"args"` // KWArgs is an additional object required to be non-nil, otherwise the request simply fails. // In most cases it's enough to set it to `map[string]interface{}{}`. KWArgs map[string]interface{} `json:"kwargs"` }
WriteModel is used as "params" in requests to "dataset/create", "dataset/write" or "dataset/unlinke" endpoints.