Documentation ¶
Index ¶
- Constants
- Variables
- func DecodeResult(buf io.Reader, result interface{}) error
- type ActionReason
- type Attendance
- type Client
- func (c Client) FetchAllAttendances(sid string, employeeID int) ([]Attendance, error)
- func (c Client) FetchAllContracts(sid string, employeeID int) (ContractList, error)
- func (c *Client) FetchAllLeaves(sid string, employeeID int) ([]Leave, error)
- func (c Client) FetchAttendancesBetweenDates(sid string, employeeID int, begin, end Date) ([]Attendance, error)
- func (c *Client) FetchEmployeeByID(sid string, employeeID int) (*Employee, error)
- func (c *Client) FetchEmployeeBySession(session *Session) (*Employee, error)
- func (c *Client) FetchLeavesBetweenDates(sid string, employeeID int, begin, end Date) ([]Leave, error)
- func (c Client) Login(login, password string) (*Session, error)
- func (c *Client) SearchEmployee(searchString string, sid string) (*Employee, error)
- type Contract
- type ContractList
- type Date
- type Employee
- type Filter
- type JsonRpcError
- type JsonRpcRequest
- type JsonRpcResponse
- type Leave
- type LeaveType
- type ReadModelRequest
- type Session
- type WorkingSchedule
Constants ¶
const ( DateFormat = "2006-01-02" TimeFormat = "15:04:05" DateTimeFormat = DateFormat + " " + TimeFormat )
Variables ¶
var (
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 ActionReason ¶
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 (Client) FetchAllAttendances ¶ added in v0.3.2
func (c Client) FetchAllAttendances(sid string, employeeID int) ([]Attendance, error)
func (Client) FetchAllContracts ¶ added in v0.4.0
func (c Client) FetchAllContracts(sid string, employeeID int) (ContractList, error)
func (*Client) FetchAllLeaves ¶ added in v0.3.2
func (Client) FetchAttendancesBetweenDates ¶ added in v0.3.2
func (*Client) FetchEmployeeByID ¶ added in v0.5.0
FetchEmployeeByID fetches an Employee for the given employee ID. Returns nil if not found.
func (*Client) FetchEmployeeBySession ¶ added in v0.5.0
FetchEmployeeBySession fetches the Employee for the given session. Returns nil if not found.
func (*Client) FetchLeavesBetweenDates ¶ added in v0.3.2
func (Client) Login ¶
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
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 Contract ¶ added in v0.4.0
type Contract struct { ID float64 `json:"id"` // Start is the first day of the contract in UTC. Start *Date `json:"date_start"` // Start is the last day of the contract in UTC. // It is nil or Zero if the contract hasn't ended yet. End *Date `json:"date_end"` WorkingSchedule *WorkingSchedule `json:"working_hours"` }
type ContractList ¶ added in v0.4.0
type ContractList []Contract
func (ContractList) GetFTERatioForDay ¶ added in v0.4.0
func (l ContractList) GetFTERatioForDay(day Date) (float64, error)
GetFTERatioForDay returns the workload ratio that is active for the given day. All involved dates are expected to be in UTC.
type Date ¶ added in v0.2.0
Date is an Odoo-specific format of a timestamp
func (Date) IsWithinMonth ¶ added in v0.2.0
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 ¶
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
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
type LeaveType ¶ added in v0.2.0
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) UnmarshalJSON ¶ added in v0.2.0
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
type WorkingSchedule ¶ added in v0.4.0
func (*WorkingSchedule) GetFTERatio ¶ added in v0.4.0
func (s *WorkingSchedule) GetFTERatio() (float64, error)
GetFTERatio tries to extract the FTE ratio from the name of the schedule. It returns an error if it could not find a match
func (WorkingSchedule) MarshalJSON ¶ added in v0.4.0
func (s WorkingSchedule) MarshalJSON() ([]byte, error)
func (*WorkingSchedule) String ¶ added in v0.4.0
func (s *WorkingSchedule) String() string
func (*WorkingSchedule) UnmarshalJSON ¶ added in v0.4.0
func (s *WorkingSchedule) UnmarshalJSON(b []byte) error