model

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: May 27, 2022 License: BSD-3-Clause Imports: 9 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 odoo.List[Attendance]

func (AttendanceList) FilterAttendanceBetweenDates added in v1.0.0

func (l AttendanceList) FilterAttendanceBetweenDates(from, to time.Time) AttendanceList

FilterAttendanceBetweenDates returns a new list that only contains items within the specified time range. It uses `from`'s location to set the timezone.

func (AttendanceList) SortByDate added in v1.0.0

func (l AttendanceList) SortByDate()

SortByDate sorts the attendances by date ascending (oldest first).

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 odoo.List[Contract]

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 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 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 *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 LeaveType added in v0.11.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.11.0

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

func (*LeaveType) String added in v0.11.0

func (leaveType *LeaveType) String() string

func (*LeaveType) UnmarshalJSON added in v0.11.0

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

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) FetchAllContractsOfEmployee added in v1.0.0

func (o Odoo) FetchAllContractsOfEmployee(ctx context.Context, employeeID int) (ContractList, error)

func (Odoo) FetchAttendancesBetweenDates

func (o Odoo) FetchAttendancesBetweenDates(ctx context.Context, 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(ctx context.Context, 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(ctx context.Context, 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(ctx context.Context, category, name string) (*Group, error)

func (Odoo) FetchLeavesBetweenDates

func (o Odoo) FetchLeavesBetweenDates(ctx context.Context, employeeID int, begin, end time.Time) (odoo.List[Leave], error)

func (Odoo) FetchPayslipInMonth added in v0.11.0

func (o Odoo) FetchPayslipInMonth(ctx context.Context, employeeID int, firstDayOfMonth time.Time) (*Payslip, error)

func (Odoo) SearchEmployee

func (o Odoo) SearchEmployee(ctx context.Context, 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.

func (Odoo) UpdatePayslip added in v0.11.0

func (o Odoo) UpdatePayslip(ctx context.Context, payslip *Payslip) error

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 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