model

package
v1.7.2 Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2023 License: BSD-3-Clause Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ActionSignOut = "sign_out"
	ActionSignIn  = "sign_in"
)

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.

func (Attendance) String added in v1.6.0

func (a Attendance) String() string

String implements fmt.Stringer.

type AttendanceList

type AttendanceList odoo.List[Attendance]

func (AttendanceList) AddCurrentTimeAsSignOut added in v1.3.0

func (l AttendanceList) AddCurrentTimeAsSignOut(tz *time.Location) AttendanceList

AddCurrentTimeAsSignOut adds an Attendance with timesheet.ActionSignOut reason and with the current time. An attendance is only added if the last Attendance in the list is ActionSignIn.

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) Sort added in v1.6.0

func (l AttendanceList) Sort()

Sort sorts the attendances by date ascending (oldest first). Dates are compared by Unix time (ignoring nanoseconds). If two attendances have the same date then they're sorted by Attendance.Action.

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 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) GetEarliestStartContractDate added in v1.6.0

func (l ContractList) GetEarliestStartContractDate() time.Time

GetEarliestStartContractDate gets the date where the first contract is valid from. Returns time.Time{} if no contract has a start date.

func (ContractList) GetFTERatioForDay

func (l ContractList) GetFTERatioForDay(date time.Time) (float64, error)

GetFTERatioForDay returns the workload ratio that is active for the given day. All involved dates are expected to be in UTC.

func (ContractList) Sort added in v1.6.0

func (l ContractList) Sort()

Sort sorts the contracts

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,omitempty"`

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

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

SplitByDay splits the Leave into multiple leaves separated by day. The given Leave can span multiple days, but with arbitrary start and end times. This function also normalizes the leaves, so that each Leave spans a full day, from midnight to 23:59:59.

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 NoContractCoversDateErr added in v1.1.3

type NoContractCoversDateErr struct {
	Err  error
	Date time.Time
}

NoContractCoversDateErr is an error that indicates a contract doesn't cover a date.

func (*NoContractCoversDateErr) Error added in v1.1.3

func (e *NoContractCoversDateErr) Error() string

Error implements error.

func (*NoContractCoversDateErr) Unwrap added in v1.1.3

func (e *NoContractCoversDateErr) Unwrap() error

Unwrap implements Wrapper.

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) FetchPayslipBetween added in v1.2.0

func (o Odoo) FetchPayslipBetween(ctx context.Context, employeeID int, firstDay, lastDay time.Time) (PayslipList, error)

FetchPayslipBetween returns all payslips that are between the given dates. It may return empty list if none found. If multiple found, they are sorted ascending by to their Payslip.DateFrom (earliest first).

func (Odoo) FetchPayslipInMonth added in v0.11.0

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

func (Odoo) FetchUserByID added in v1.3.0

func (o Odoo) FetchUserByID(ctx context.Context, id int) (*User, 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"`
	DateFrom  odoo.Date      `json:"date_from"`
	DateTo    odoo.Date      `json:"date_to"`
	XOvertime interface{}    `json:"x_overtime"`
	TimeZone  *odoo.TimeZone `json:"x_timezone"`
}

func (Payslip) Overtime

func (p Payslip) Overtime() string

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

func (PayslipList) FilterInMonth added in v1.5.0

func (l PayslipList) FilterInMonth(dayInMonth time.Time) *Payslip

FilterInMonth returns the payslip that covers the given date. Returns nil if no matching payslip found. Respects time.Location if the given date has also a time.Location set.

func (PayslipList) Len added in v1.5.0

func (l PayslipList) Len() int

type User added in v1.3.0

type User struct {
	ID       int            `json:"id"`
	Name     string         `json:"name"`
	TimeZone *odoo.TimeZone `json:"tz,omitempty"`
	Email    string         `json:"email"`
}

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