odoo

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2021 License: BSD-3-Clause Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AttendanceDateFormat     = "2006-01-02"
	AttendanceTimeFormat     = "15:04:05"
	AttendanceDateTimeFormat = AttendanceDateFormat + " " + AttendanceTimeFormat
)

Variables

View Source
var (
	ErrInvalidCredentials = errors.New("invalid credentials")
)

Functions

func DecodeResult

func DecodeResult(buf io.Reader, result interface{}) error

DecodeResult takes a buffer, decodes the intermediate JsonRpcResponse and then the contained "result" field into "result".

Types

type ActionReason

type ActionReason struct {
	ID   float64
	Name string
}

func (ActionReason) MarshalJSON

func (reason ActionReason) MarshalJSON() ([]byte, error)

func (*ActionReason) String

func (reason *ActionReason) String() string

func (*ActionReason) UnmarshalJSON

func (reason *ActionReason) UnmarshalJSON(b []byte) error

type Attendance

type Attendance struct {
	// ID is an unique ID for each attendance entry
	ID int `json:"id,omitempty"`

	// DateTime is the entry timestamp in UTC
	// Format: '2006-01-02 15:04:05'
	DateTime *AttendanceTime `json:"name,omitempty"`

	// Action is either "sign_in" or "sign_out"
	Action string `json:"action,omitempty"`

	// Reason describes the "action reason" from Odoo.
	//
	// Example raw values returned from Odoo:
	// * `false` (if no specific reason given)
	// * `[1, "Outside office hours"]`
	// * `[2, "Outside office hours"]`
	// * `[3, "Sick / Medical Consultation"]`
	// * `[4, "Sick / Medical Consultation"]`
	// * `[5, "Authorities"]`
	// * `[6, "Authorities"]`
	// * `[27, "Requested Public Service"]`
	// * `[28, "Requested Public Service"]`
	//
	// NOTE: This field has special meaning when calculating the overtime.
	Reason *ActionReason `json:"action_desc,omitempty"`

	// WorkedHours is the amount of time Odoo determined.
	// Will always be "0.0" if "action" is "sign_in". Values DO NOT reflect
	// special boni like the 1.5x bonus for "Outside office hours".
	WorkedHours float64
}

type AttendanceTime

type AttendanceTime time.Time

func (AttendanceTime) MarshalJSON

func (at AttendanceTime) MarshalJSON() ([]byte, error)

func (*AttendanceTime) String

func (at *AttendanceTime) String() string

func (*AttendanceTime) ToTime

func (at *AttendanceTime) ToTime() time.Time

func (*AttendanceTime) UnmarshalJSON

func (at *AttendanceTime) UnmarshalJSON(b []byte) error

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, db string) *Client

NewClient returns a new client with its basic fields set

func (Client) Login

func (c Client) Login(login, password string) (*Session, error)

Login tries to authenticate the user against Odoo. It returns a session if authentication was successful, or an error if the credentials were wrong, encoding or sending the request, or decoding the request failed.

func (Client) ReadAllAttendances

func (c Client) ReadAllAttendances(sid string, uid int) ([]Attendance, error)

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

type JsonRpcError struct {
	Message string                 `json:"message,omitempty"`
	Code    int                    `json:"code,omitempty"`
	Data    map[string]interface{} `json:"data,omitempty"`
}

type JsonRpcRequest

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

func NewJsonRpcRequest(params interface{}) *JsonRpcRequest

NewJsonRpcRequest returns a JSON RPC request with its protocol fileds 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

func (*JsonRpcRequest) Encode

func (r *JsonRpcRequest) Encode() (io.Reader, error)

Encode encodes the request as JSON in a buffer and returns the buffer.

type JsonRpcResponse

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 eror field
	Error *JsonRpcError `json:"error,omitempty"`
}

type Leave

type Leave struct {
}

type ReadModelRequest

type ReadModelRequest 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"`
}

ReadModelRequest is used as "params" in requests to "dataset/search_read" endpoints.

type Session

type Session struct {
	// ID is the session ID.
	// Is always set, no matter the authentication outcome.
	ID 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"`
	// Username is usually set to the LoginName that was sent in the request.
	// Is always set, no matter the authentication outcome.
	Username string `json:"username,omitempty"`
}

Session information

Jump to

Keyboard shortcuts

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