model

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Feb 7, 2022 License: BSD-3-Clause Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

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)

MarshalJSON implements json.Marshaler.

func (*ActionReason) String

func (reason *ActionReason) String() string

String implements fmt.Stringer.

func (*ActionReason) UnmarshalJSON

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

UnmarshalJSON implements json.Unmarshaler.

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 *odoo.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"`
}

Attendance is an entry or closing event of a shift.

type AttendanceList

type AttendanceList struct {
	Items []Attendance `json:"records,omitempty"`
}

AttendanceList list contains a slice of Attendance.

type Contract

type Contract struct {
	ID float64 `json:"id"`
	// Start is the first day of the contract in UTC.
	Start *odoo.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             *odoo.Date       `json:"date_end"`
	WorkingSchedule *WorkingSchedule `json:"working_hours"`
}

type ContractList

type ContractList struct {
	Items []Contract `json:"records,omitempty"`
}

ContractList contains a slice of Contract.

func (ContractList) GetFTERatioForDay

func (l ContractList) GetFTERatioForDay(day odoo.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 Employee

type Employee struct {
	ID   int    `json:"id"`
	Name string `json:"name"`
}

type EmployeeList

type EmployeeList struct {
	Items []Employee `json:"records,omitempty"`
}

EmployeeList contains a slice of Employee.

type Group added in v0.9.0

type Group struct {
	Name     string        `json:"name"`
	Category GroupCategory `json:"category_id"`
	UserIDs  []int         `json:"users"`
}

Group contains a list of users.

type GroupCategory added in v0.9.0

type GroupCategory struct {
	ID   int    `json:"id"`
	Name string `json:"name"`
}

GroupCategory is the parent group of a Group.

func (*GroupCategory) MarshalJSON added in v0.9.0

func (c *GroupCategory) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler.

func (*GroupCategory) String added in v0.9.0

func (c *GroupCategory) String() string

String implements fmt.Stringer.

func (*GroupCategory) UnmarshalJSON added in v0.9.0

func (c *GroupCategory) UnmarshalJSON(b []byte) error

UnmarshalJSON implements json.Unmarshaler.

type GroupList added in v0.9.0

type GroupList struct {
	Items []Group `json:"records,omitempty"`
}

GroupList contains a slice of Group.

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 *odoo.Date `json:"date_from"`

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

	// Type describes the "leave type" from Odoo.
	Type *odoo.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

func (l Leave) SplitByDay() []Leave

type LeaveList

type LeaveList struct {
	Items []Leave `json:"records,omitempty"`
}

LeaveList contains a slice of Leave.

type Odoo

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

Odoo is the developer-friendly odoo.Client with strongly-typed models.

func NewOdoo

func NewOdoo(querier odoo.QueryExecutor) *Odoo

NewOdoo creates a new Odoo client.

func (Odoo) FetchAllAttendances

func (o Odoo) FetchAllAttendances(_ string, employeeID int) (AttendanceList, error)

FetchAllAttendances retrieves all attendances associated with the given employee.

func (Odoo) FetchAllContracts

func (o Odoo) FetchAllContracts(employeeID int) (ContractList, error)

func (Odoo) FetchAllLeaves

func (o Odoo) FetchAllLeaves(employeeID int) (LeaveList, error)

func (Odoo) FetchAttendancesBetweenDates

func (o Odoo) FetchAttendancesBetweenDates(employeeID int, begin, end time.Time) (AttendanceList, error)

FetchAttendancesBetweenDates retrieves all attendances associated with the given employee between 2 dates (inclusive each).

func (Odoo) FetchEmployeeByID

func (o Odoo) FetchEmployeeByID(employeeID int) (*Employee, error)

FetchEmployeeByID fetches an Employee for the given employee ID. Returns nil if not found.

func (Odoo) FetchEmployeeByUserID

func (o Odoo) FetchEmployeeByUserID(userID int) (*Employee, error)

FetchEmployeeByUserID fetches the Employee for the given user ID (which might not be the same as Employee.ID. Returns nil if not found.

func (Odoo) FetchGroupByName added in v0.9.0

func (o Odoo) FetchGroupByName(category, name string) (*Group, error)

func (Odoo) FetchLeavesBetweenDates

func (o Odoo) FetchLeavesBetweenDates(employeeID int, begin, end time.Time) (LeaveList, error)

func (Odoo) FetchPayslipOfLastMonth

func (o Odoo) FetchPayslipOfLastMonth(employeeID int, lastDayOfMonth time.Time) (*Payslip, error)

func (Odoo) SearchEmployee

func (o Odoo) SearchEmployee(searchString 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 Payslip

type Payslip struct {
	ID       int         `json:"id"`
	Name     string      `json:"name"`
	Overtime interface{} `json:"x_overtime"`
	DateFrom odoo.Date   `json:"date_from"`
	DateTo   odoo.Date   `json:"date_to"`
}

func (Payslip) GetOvertime

func (p Payslip) GetOvertime() string

GetOvertime returns the plain field value as string.

func (Payslip) ParseOvertime

func (p Payslip) ParseOvertime() (time.Duration, error)

ParseOvertime tries to parse the currently inconsistently-formatted custom field to a duration. If the field is empty, 0 is returned without error. It parses the following formats:

  • hhh:mm (e.g. '15:54')
  • hhh:mm:ss (e.g. '153:54:45')
  • {1,2}d{1,2}h (e.g. '15d54m')

type PayslipList

type PayslipList struct {
	Items []Payslip `json:"records,omitempty"`
}

PayslipList contains a slice of Payslip.

type WorkingSchedule

type WorkingSchedule struct {
	ID   float64
	Name string
}

func (WorkingSchedule) GetFTERatio

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

func (s WorkingSchedule) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler.

func (*WorkingSchedule) String

func (s *WorkingSchedule) String() string

String implements fmt.Stringer.

func (*WorkingSchedule) UnmarshalJSON

func (s *WorkingSchedule) UnmarshalJSON(b []byte) error

UnmarshalJSON implements json.Unmarshaler.

Jump to

Keyboard shortcuts

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