-
Notifications
You must be signed in to change notification settings - Fork 68
/
Copy pathhr_department.go
144 lines (128 loc) · 5.72 KB
/
hr_department.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
package odoo
import (
"fmt"
)
// HrDepartment represents hr.department model.
type HrDepartment struct {
LastUpdate *Time `xmlrpc:"__last_update,omptempty"`
AbsenceOfToday *Int `xmlrpc:"absence_of_today,omptempty"`
Active *Bool `xmlrpc:"active,omptempty"`
AllocationToApproveCount *Int `xmlrpc:"allocation_to_approve_count,omptempty"`
ChildIds *Relation `xmlrpc:"child_ids,omptempty"`
Color *Int `xmlrpc:"color,omptempty"`
CompanyId *Many2One `xmlrpc:"company_id,omptempty"`
CompleteName *String `xmlrpc:"complete_name,omptempty"`
CreateDate *Time `xmlrpc:"create_date,omptempty"`
CreateUid *Many2One `xmlrpc:"create_uid,omptempty"`
DisplayName *String `xmlrpc:"display_name,omptempty"`
Id *Int `xmlrpc:"id,omptempty"`
JobsIds *Relation `xmlrpc:"jobs_ids,omptempty"`
LeaveToApproveCount *Int `xmlrpc:"leave_to_approve_count,omptempty"`
ManagerId *Many2One `xmlrpc:"manager_id,omptempty"`
MemberIds *Relation `xmlrpc:"member_ids,omptempty"`
MessageChannelIds *Relation `xmlrpc:"message_channel_ids,omptempty"`
MessageFollowerIds *Relation `xmlrpc:"message_follower_ids,omptempty"`
MessageIds *Relation `xmlrpc:"message_ids,omptempty"`
MessageIsFollower *Bool `xmlrpc:"message_is_follower,omptempty"`
MessageLastPost *Time `xmlrpc:"message_last_post,omptempty"`
MessageNeedaction *Bool `xmlrpc:"message_needaction,omptempty"`
MessageNeedactionCounter *Int `xmlrpc:"message_needaction_counter,omptempty"`
MessagePartnerIds *Relation `xmlrpc:"message_partner_ids,omptempty"`
MessageUnread *Bool `xmlrpc:"message_unread,omptempty"`
MessageUnreadCounter *Int `xmlrpc:"message_unread_counter,omptempty"`
Name *String `xmlrpc:"name,omptempty"`
Note *String `xmlrpc:"note,omptempty"`
ParentId *Many2One `xmlrpc:"parent_id,omptempty"`
TotalEmployee *Int `xmlrpc:"total_employee,omptempty"`
WebsiteMessageIds *Relation `xmlrpc:"website_message_ids,omptempty"`
WriteDate *Time `xmlrpc:"write_date,omptempty"`
WriteUid *Many2One `xmlrpc:"write_uid,omptempty"`
}
// HrDepartments represents array of hr.department model.
type HrDepartments []HrDepartment
// HrDepartmentModel is the odoo model name.
const HrDepartmentModel = "hr.department"
// Many2One convert HrDepartment to *Many2One.
func (hd *HrDepartment) Many2One() *Many2One {
return NewMany2One(hd.Id.Get(), "")
}
// CreateHrDepartment creates a new hr.department model and returns its id.
func (c *Client) CreateHrDepartment(hd *HrDepartment) (int64, error) {
return c.Create(HrDepartmentModel, hd)
}
// UpdateHrDepartment updates an existing hr.department record.
func (c *Client) UpdateHrDepartment(hd *HrDepartment) error {
return c.UpdateHrDepartments([]int64{hd.Id.Get()}, hd)
}
// UpdateHrDepartments updates existing hr.department records.
// All records (represented by ids) will be updated by hd values.
func (c *Client) UpdateHrDepartments(ids []int64, hd *HrDepartment) error {
return c.Update(HrDepartmentModel, ids, hd)
}
// DeleteHrDepartment deletes an existing hr.department record.
func (c *Client) DeleteHrDepartment(id int64) error {
return c.DeleteHrDepartments([]int64{id})
}
// DeleteHrDepartments deletes existing hr.department records.
func (c *Client) DeleteHrDepartments(ids []int64) error {
return c.Delete(HrDepartmentModel, ids)
}
// GetHrDepartment gets hr.department existing record.
func (c *Client) GetHrDepartment(id int64) (*HrDepartment, error) {
hds, err := c.GetHrDepartments([]int64{id})
if err != nil {
return nil, err
}
if hds != nil && len(*hds) > 0 {
return &((*hds)[0]), nil
}
return nil, fmt.Errorf("id %v of hr.department not found", id)
}
// GetHrDepartments gets hr.department existing records.
func (c *Client) GetHrDepartments(ids []int64) (*HrDepartments, error) {
hds := &HrDepartments{}
if err := c.Read(HrDepartmentModel, ids, nil, hds); err != nil {
return nil, err
}
return hds, nil
}
// FindHrDepartment finds hr.department record by querying it with criteria.
func (c *Client) FindHrDepartment(criteria *Criteria) (*HrDepartment, error) {
hds := &HrDepartments{}
if err := c.SearchRead(HrDepartmentModel, criteria, NewOptions().Limit(1), hds); err != nil {
return nil, err
}
if hds != nil && len(*hds) > 0 {
return &((*hds)[0]), nil
}
return nil, fmt.Errorf("no hr.department was found with criteria %v", criteria)
}
// FindHrDepartments finds hr.department records by querying it
// and filtering it with criteria and options.
func (c *Client) FindHrDepartments(criteria *Criteria, options *Options) (*HrDepartments, error) {
hds := &HrDepartments{}
if err := c.SearchRead(HrDepartmentModel, criteria, options, hds); err != nil {
return nil, err
}
return hds, nil
}
// FindHrDepartmentIds finds records ids by querying it
// and filtering it with criteria and options.
func (c *Client) FindHrDepartmentIds(criteria *Criteria, options *Options) ([]int64, error) {
ids, err := c.Search(HrDepartmentModel, criteria, options)
if err != nil {
return []int64{}, err
}
return ids, nil
}
// FindHrDepartmentId finds record id by querying it with criteria.
func (c *Client) FindHrDepartmentId(criteria *Criteria, options *Options) (int64, error) {
ids, err := c.Search(HrDepartmentModel, criteria, options)
if err != nil {
return -1, err
}
if len(ids) > 0 {
return ids[0], nil
}
return -1, fmt.Errorf("no hr.department was found with criteria %v and options %v", criteria, options)
}