odoo

package
v0.3.3 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2021 License: BSD-3-Clause Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DateFormat     = "2006-01-02"
	TimeFormat     = "15:04:05"
	DateTimeFormat = DateFormat + " " + TimeFormat
)

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
}

ActionReason 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"]`

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 *Date `json:"name,omitempty"`

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

	// Reason describes the "action reason" from Odoo.
	// NOTE: This field has special meaning when calculating the overtime.
	Reason *ActionReason `json:"action_desc,omitempty"`
}

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) FetchAllAttendances added in v0.3.2

func (c Client) FetchAllAttendances(sid string, employeeID int) ([]Attendance, error)

func (*Client) FetchAllLeaves added in v0.3.2

func (c *Client) FetchAllLeaves(sid string, employeeID int) ([]Leave, error)

func (Client) FetchAttendancesBetweenDates added in v0.3.2

func (c Client) FetchAttendancesBetweenDates(sid string, employeeID int, begin, end Date) ([]Attendance, error)

func (*Client) FetchEmployee added in v0.3.0

func (c *Client) FetchEmployee(sid string, userId int) (*Employee, error)

FetchEmployee fetches an Employee for the given user ID. Returns nil if not found.

func (*Client) FetchLeavesBetweenDates added in v0.3.2

func (c *Client) FetchLeavesBetweenDates(sid string, employeeID int, begin, end Date) ([]Leave, error)

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) SearchEmployee added in v0.3.0

func (c *Client) SearchEmployee(searchString string, sid string) (*Employee, error)

SearchEmployee searches for an Employee with the given searchString in the Employee.Name. If multiple employees are found, the first is returned. Returns nil if none found.

type Date added in v0.2.0

type Date time.Time

Date is an Odoo-specific format of a timestamp

func (Date) IsWithinMonth added in v0.2.0

func (d Date) IsWithinMonth(year, month int) bool

func (Date) MarshalJSON added in v0.2.0

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

func (*Date) String added in v0.2.0

func (d *Date) String() string

func (*Date) ToTime added in v0.2.0

func (d *Date) ToTime() time.Time

func (*Date) UnmarshalJSON added in v0.2.0

func (d *Date) UnmarshalJSON(b []byte) error

type Employee added in v0.3.0

type Employee struct {
	ID   int    `json:"id"`
	Name string `json:"name"`
	// AttendanceAccess returns true if the requesting user id has access to read attendances of this employee.
	AttendanceAccess bool `json:"attendance_access"`
}

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 {
	// ID is an unique ID for each leave entry
	ID int `json:"id"`

	// DateFrom is the starting timestamp of the leave in UTC
	// Format: DateTimeFormat
	DateFrom *Date `json:"date_from"`

	// DateTo is the ending timestamp of the leave in UTC
	// Format: DateTimeFormat
	DateTo *Date `json:"date_to"`

	// Type describes the "leave type" from Odoo.
	Type *LeaveType `json:"holiday_status_id,omitempty"`

	// State is the leave request state.
	// Example raw values returned from Odoo:
	//  * `draft` (To Submit)
	//  * `confirm` (To Approve)
	//  * `validate` (Approved)
	State string `json:"state,omitempty"`
}

func (Leave) SplitByDay added in v0.2.0

func (l Leave) SplitByDay() []Leave

type LeaveType added in v0.2.0

type LeaveType struct {
	ID   float64
	Name string
}

LeaveType describes the "leave type" from Odoo.

Example raw values returned from Odoo:

  • `false` (if no specific reason given)
  • `[4, "Unpaid"]`
  • `[5, "Military Service"]`
  • `[7, "Special Occasions"]`
  • `[9, "Public Holiday"]`
  • `[16, "Legal Leaves 2020"]`
  • `[17, "Legal Leaves 2021"]`

func (LeaveType) MarshalJSON added in v0.2.0

func (leaveType LeaveType) MarshalJSON() ([]byte, error)

func (*LeaveType) String added in v0.2.0

func (leaveType *LeaveType) String() string

func (*LeaveType) UnmarshalJSON added in v0.2.0

func (leaveType *LeaveType) UnmarshalJSON(b []byte) error

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