-
Notifications
You must be signed in to change notification settings - Fork 68
/
Copy pathcalendar_event.go
179 lines (163 loc) · 8.1 KB
/
calendar_event.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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
package odoo
// CalendarEvent represents calendar.event model.
type CalendarEvent struct {
LastUpdate *Time `xmlrpc:"__last_update,omitempty"`
Active *Bool `xmlrpc:"active,omitempty"`
ActivityIds *Relation `xmlrpc:"activity_ids,omitempty"`
AlarmIds *Relation `xmlrpc:"alarm_ids,omitempty"`
Allday *Bool `xmlrpc:"allday,omitempty"`
AttendeeIds *Relation `xmlrpc:"attendee_ids,omitempty"`
AttendeeStatus *Selection `xmlrpc:"attendee_status,omitempty"`
Byday *Selection `xmlrpc:"byday,omitempty"`
CategIds *Relation `xmlrpc:"categ_ids,omitempty"`
Count *Int `xmlrpc:"count,omitempty"`
CreateDate *Time `xmlrpc:"create_date,omitempty"`
CreateUid *Many2One `xmlrpc:"create_uid,omitempty"`
Day *Int `xmlrpc:"day,omitempty"`
Description *String `xmlrpc:"description,omitempty"`
DisplayName *String `xmlrpc:"display_name,omitempty"`
DisplayStart *String `xmlrpc:"display_start,omitempty"`
DisplayTime *String `xmlrpc:"display_time,omitempty"`
Duration *Float `xmlrpc:"duration,omitempty"`
EndType *Selection `xmlrpc:"end_type,omitempty"`
FinalDate *Time `xmlrpc:"final_date,omitempty"`
Fr *Bool `xmlrpc:"fr,omitempty"`
Id *Int `xmlrpc:"id,omitempty"`
Interval *Int `xmlrpc:"interval,omitempty"`
IsAttendee *Bool `xmlrpc:"is_attendee,omitempty"`
IsHighlighted *Bool `xmlrpc:"is_highlighted,omitempty"`
Location *String `xmlrpc:"location,omitempty"`
MessageChannelIds *Relation `xmlrpc:"message_channel_ids,omitempty"`
MessageFollowerIds *Relation `xmlrpc:"message_follower_ids,omitempty"`
MessageIds *Relation `xmlrpc:"message_ids,omitempty"`
MessageIsFollower *Bool `xmlrpc:"message_is_follower,omitempty"`
MessageLastPost *Time `xmlrpc:"message_last_post,omitempty"`
MessageNeedaction *Bool `xmlrpc:"message_needaction,omitempty"`
MessageNeedactionCounter *Int `xmlrpc:"message_needaction_counter,omitempty"`
MessagePartnerIds *Relation `xmlrpc:"message_partner_ids,omitempty"`
MessageUnread *Bool `xmlrpc:"message_unread,omitempty"`
MessageUnreadCounter *Int `xmlrpc:"message_unread_counter,omitempty"`
Mo *Bool `xmlrpc:"mo,omitempty"`
MonthBy *Selection `xmlrpc:"month_by,omitempty"`
Name *String `xmlrpc:"name,omitempty"`
OpportunityId *Many2One `xmlrpc:"opportunity_id,omitempty"`
PartnerId *Many2One `xmlrpc:"partner_id,omitempty"`
PartnerIds *Relation `xmlrpc:"partner_ids,omitempty"`
Privacy *Selection `xmlrpc:"privacy,omitempty"`
Recurrency *Bool `xmlrpc:"recurrency,omitempty"`
RecurrentId *Int `xmlrpc:"recurrent_id,omitempty"`
RecurrentIdDate *Time `xmlrpc:"recurrent_id_date,omitempty"`
ResId *Int `xmlrpc:"res_id,omitempty"`
ResModel *String `xmlrpc:"res_model,omitempty"`
ResModelId *Many2One `xmlrpc:"res_model_id,omitempty"`
Rrule *String `xmlrpc:"rrule,omitempty"`
RruleType *Selection `xmlrpc:"rrule_type,omitempty"`
Sa *Bool `xmlrpc:"sa,omitempty"`
ShowAs *Selection `xmlrpc:"show_as,omitempty"`
Start *Time `xmlrpc:"start,omitempty"`
StartDate *Time `xmlrpc:"start_date,omitempty"`
StartDatetime *Time `xmlrpc:"start_datetime,omitempty"`
State *Selection `xmlrpc:"state,omitempty"`
Stop *Time `xmlrpc:"stop,omitempty"`
StopDate *Time `xmlrpc:"stop_date,omitempty"`
StopDatetime *Time `xmlrpc:"stop_datetime,omitempty"`
Su *Bool `xmlrpc:"su,omitempty"`
Th *Bool `xmlrpc:"th,omitempty"`
Tu *Bool `xmlrpc:"tu,omitempty"`
UserId *Many2One `xmlrpc:"user_id,omitempty"`
We *Bool `xmlrpc:"we,omitempty"`
WebsiteMessageIds *Relation `xmlrpc:"website_message_ids,omitempty"`
WeekList *Selection `xmlrpc:"week_list,omitempty"`
WriteDate *Time `xmlrpc:"write_date,omitempty"`
WriteUid *Many2One `xmlrpc:"write_uid,omitempty"`
}
// CalendarEvents represents array of calendar.event model.
type CalendarEvents []CalendarEvent
// CalendarEventModel is the odoo model name.
const CalendarEventModel = "calendar.event"
// Many2One convert CalendarEvent to *Many2One.
func (ce *CalendarEvent) Many2One() *Many2One {
return NewMany2One(ce.Id.Get(), "")
}
// CreateCalendarEvent creates a new calendar.event model and returns its id.
func (c *Client) CreateCalendarEvent(ce *CalendarEvent) (int64, error) {
ids, err := c.CreateCalendarEvents([]*CalendarEvent{ce})
if err != nil {
return -1, err
}
if len(ids) == 0 {
return -1, nil
}
return ids[0], nil
}
// CreateCalendarEvents creates a new calendar.event model and returns its id.
func (c *Client) CreateCalendarEvents(ces []*CalendarEvent) ([]int64, error) {
var vv []interface{}
for _, v := range ces {
vv = append(vv, v)
}
return c.Create(CalendarEventModel, vv, nil)
}
// UpdateCalendarEvent updates an existing calendar.event record.
func (c *Client) UpdateCalendarEvent(ce *CalendarEvent) error {
return c.UpdateCalendarEvents([]int64{ce.Id.Get()}, ce)
}
// UpdateCalendarEvents updates existing calendar.event records.
// All records (represented by ids) will be updated by ce values.
func (c *Client) UpdateCalendarEvents(ids []int64, ce *CalendarEvent) error {
return c.Update(CalendarEventModel, ids, ce, nil)
}
// DeleteCalendarEvent deletes an existing calendar.event record.
func (c *Client) DeleteCalendarEvent(id int64) error {
return c.DeleteCalendarEvents([]int64{id})
}
// DeleteCalendarEvents deletes existing calendar.event records.
func (c *Client) DeleteCalendarEvents(ids []int64) error {
return c.Delete(CalendarEventModel, ids)
}
// GetCalendarEvent gets calendar.event existing record.
func (c *Client) GetCalendarEvent(id int64) (*CalendarEvent, error) {
ces, err := c.GetCalendarEvents([]int64{id})
if err != nil {
return nil, err
}
return &((*ces)[0]), nil
}
// GetCalendarEvents gets calendar.event existing records.
func (c *Client) GetCalendarEvents(ids []int64) (*CalendarEvents, error) {
ces := &CalendarEvents{}
if err := c.Read(CalendarEventModel, ids, nil, ces); err != nil {
return nil, err
}
return ces, nil
}
// FindCalendarEvent finds calendar.event record by querying it with criteria.
func (c *Client) FindCalendarEvent(criteria *Criteria) (*CalendarEvent, error) {
ces := &CalendarEvents{}
if err := c.SearchRead(CalendarEventModel, criteria, NewOptions().Limit(1), ces); err != nil {
return nil, err
}
return &((*ces)[0]), nil
}
// FindCalendarEvents finds calendar.event records by querying it
// and filtering it with criteria and options.
func (c *Client) FindCalendarEvents(criteria *Criteria, options *Options) (*CalendarEvents, error) {
ces := &CalendarEvents{}
if err := c.SearchRead(CalendarEventModel, criteria, options, ces); err != nil {
return nil, err
}
return ces, nil
}
// FindCalendarEventIds finds records ids by querying it
// and filtering it with criteria and options.
func (c *Client) FindCalendarEventIds(criteria *Criteria, options *Options) ([]int64, error) {
return c.Search(CalendarEventModel, criteria, options)
}
// FindCalendarEventId finds record id by querying it with criteria.
func (c *Client) FindCalendarEventId(criteria *Criteria, options *Options) (int64, error) {
ids, err := c.Search(CalendarEventModel, criteria, options)
if err != nil {
return -1, err
}
return ids[0], nil
}