-
Notifications
You must be signed in to change notification settings - Fork 68
/
Copy pathcalendar_event.go
180 lines (164 loc) · 8.14 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
180
package odoo
import (
"fmt"
)
// CalendarEvent represents calendar.event model.
type CalendarEvent struct {
LastUpdate *Time `xmlrpc:"__last_update,omptempty"`
Active *Bool `xmlrpc:"active,omptempty"`
ActivityIds *Relation `xmlrpc:"activity_ids,omptempty"`
AlarmIds *Relation `xmlrpc:"alarm_ids,omptempty"`
Allday *Bool `xmlrpc:"allday,omptempty"`
AttendeeIds *Relation `xmlrpc:"attendee_ids,omptempty"`
AttendeeStatus *Selection `xmlrpc:"attendee_status,omptempty"`
Byday *Selection `xmlrpc:"byday,omptempty"`
CategIds *Relation `xmlrpc:"categ_ids,omptempty"`
Count *Int `xmlrpc:"count,omptempty"`
CreateDate *Time `xmlrpc:"create_date,omptempty"`
CreateUid *Many2One `xmlrpc:"create_uid,omptempty"`
Day *Int `xmlrpc:"day,omptempty"`
Description *String `xmlrpc:"description,omptempty"`
DisplayName *String `xmlrpc:"display_name,omptempty"`
DisplayStart *String `xmlrpc:"display_start,omptempty"`
DisplayTime *String `xmlrpc:"display_time,omptempty"`
Duration *Float `xmlrpc:"duration,omptempty"`
EndType *Selection `xmlrpc:"end_type,omptempty"`
FinalDate *Time `xmlrpc:"final_date,omptempty"`
Fr *Bool `xmlrpc:"fr,omptempty"`
Id *Int `xmlrpc:"id,omptempty"`
Interval *Int `xmlrpc:"interval,omptempty"`
IsAttendee *Bool `xmlrpc:"is_attendee,omptempty"`
IsHighlighted *Bool `xmlrpc:"is_highlighted,omptempty"`
Location *String `xmlrpc:"location,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"`
Mo *Bool `xmlrpc:"mo,omptempty"`
MonthBy *Selection `xmlrpc:"month_by,omptempty"`
Name *String `xmlrpc:"name,omptempty"`
OpportunityId *Many2One `xmlrpc:"opportunity_id,omptempty"`
PartnerId *Many2One `xmlrpc:"partner_id,omptempty"`
PartnerIds *Relation `xmlrpc:"partner_ids,omptempty"`
Privacy *Selection `xmlrpc:"privacy,omptempty"`
Recurrency *Bool `xmlrpc:"recurrency,omptempty"`
RecurrentId *Int `xmlrpc:"recurrent_id,omptempty"`
RecurrentIdDate *Time `xmlrpc:"recurrent_id_date,omptempty"`
ResId *Int `xmlrpc:"res_id,omptempty"`
ResModel *String `xmlrpc:"res_model,omptempty"`
ResModelId *Many2One `xmlrpc:"res_model_id,omptempty"`
Rrule *String `xmlrpc:"rrule,omptempty"`
RruleType *Selection `xmlrpc:"rrule_type,omptempty"`
Sa *Bool `xmlrpc:"sa,omptempty"`
ShowAs *Selection `xmlrpc:"show_as,omptempty"`
Start *Time `xmlrpc:"start,omptempty"`
StartDate *Time `xmlrpc:"start_date,omptempty"`
StartDatetime *Time `xmlrpc:"start_datetime,omptempty"`
State *Selection `xmlrpc:"state,omptempty"`
Stop *Time `xmlrpc:"stop,omptempty"`
StopDate *Time `xmlrpc:"stop_date,omptempty"`
StopDatetime *Time `xmlrpc:"stop_datetime,omptempty"`
Su *Bool `xmlrpc:"su,omptempty"`
Th *Bool `xmlrpc:"th,omptempty"`
Tu *Bool `xmlrpc:"tu,omptempty"`
UserId *Many2One `xmlrpc:"user_id,omptempty"`
We *Bool `xmlrpc:"we,omptempty"`
WebsiteMessageIds *Relation `xmlrpc:"website_message_ids,omptempty"`
WeekList *Selection `xmlrpc:"week_list,omptempty"`
WriteDate *Time `xmlrpc:"write_date,omptempty"`
WriteUid *Many2One `xmlrpc:"write_uid,omptempty"`
}
// 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) {
return c.Create(CalendarEventModel, ce)
}
// 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)
}
// 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
}
if ces != nil && len(*ces) > 0 {
return &((*ces)[0]), nil
}
return nil, fmt.Errorf("id %v of calendar.event not found", id)
}
// 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
}
if ces != nil && len(*ces) > 0 {
return &((*ces)[0]), nil
}
return nil, fmt.Errorf("no calendar.event was found with criteria %v", criteria)
}
// 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) {
ids, err := c.Search(CalendarEventModel, criteria, options)
if err != nil {
return []int64{}, err
}
return ids, nil
}
// 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
}
if len(ids) > 0 {
return ids[0], nil
}
return -1, fmt.Errorf("no calendar.event was found with criteria %v and options %v", criteria, options)
}