-
Notifications
You must be signed in to change notification settings - Fork 0
/
calendar_attendee.go
141 lines (124 loc) · 4.86 KB
/
calendar_attendee.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
package odoo
import (
"fmt"
)
// CalendarAttendee represents calendar.attendee model.
type CalendarAttendee struct {
LastUpdate *Time `xmlrpc:"__last_update,omptempty"`
AccessToken *String `xmlrpc:"access_token,omptempty"`
Availability *Selection `xmlrpc:"availability,omptempty"`
CommonName *String `xmlrpc:"common_name,omptempty"`
CreateDate *Time `xmlrpc:"create_date,omptempty"`
CreateUid *Many2One `xmlrpc:"create_uid,omptempty"`
DisplayName *String `xmlrpc:"display_name,omptempty"`
Email *String `xmlrpc:"email,omptempty"`
EventId *Many2One `xmlrpc:"event_id,omptempty"`
Id *Int `xmlrpc:"id,omptempty"`
PartnerId *Many2One `xmlrpc:"partner_id,omptempty"`
State *Selection `xmlrpc:"state,omptempty"`
WriteDate *Time `xmlrpc:"write_date,omptempty"`
WriteUid *Many2One `xmlrpc:"write_uid,omptempty"`
}
// CalendarAttendees represents array of calendar.attendee model.
type CalendarAttendees []CalendarAttendee
// CalendarAttendeeModel is the odoo model name.
const CalendarAttendeeModel = "calendar.attendee"
// Many2One convert CalendarAttendee to *Many2One.
func (ca *CalendarAttendee) Many2One() *Many2One {
return NewMany2One(ca.Id.Get(), "")
}
// CreateCalendarAttendee creates a new calendar.attendee model and returns its id.
func (c *Client) CreateCalendarAttendee(ca *CalendarAttendee) (int64, error) {
ids, err := c.CreateCalendarAttendees([]*CalendarAttendee{ca})
if err != nil {
return -1, err
}
if len(ids) == 0 {
return -1, nil
}
return ids[0], nil
}
// CreateCalendarAttendee creates a new calendar.attendee model and returns its id.
func (c *Client) CreateCalendarAttendees(cas []*CalendarAttendee) ([]int64, error) {
var vv []interface{}
for _, v := range cas {
vv = append(vv, v)
}
return c.Create(CalendarAttendeeModel, vv)
}
// UpdateCalendarAttendee updates an existing calendar.attendee record.
func (c *Client) UpdateCalendarAttendee(ca *CalendarAttendee) error {
return c.UpdateCalendarAttendees([]int64{ca.Id.Get()}, ca)
}
// UpdateCalendarAttendees updates existing calendar.attendee records.
// All records (represented by ids) will be updated by ca values.
func (c *Client) UpdateCalendarAttendees(ids []int64, ca *CalendarAttendee) error {
return c.Update(CalendarAttendeeModel, ids, ca)
}
// DeleteCalendarAttendee deletes an existing calendar.attendee record.
func (c *Client) DeleteCalendarAttendee(id int64) error {
return c.DeleteCalendarAttendees([]int64{id})
}
// DeleteCalendarAttendees deletes existing calendar.attendee records.
func (c *Client) DeleteCalendarAttendees(ids []int64) error {
return c.Delete(CalendarAttendeeModel, ids)
}
// GetCalendarAttendee gets calendar.attendee existing record.
func (c *Client) GetCalendarAttendee(id int64) (*CalendarAttendee, error) {
cas, err := c.GetCalendarAttendees([]int64{id})
if err != nil {
return nil, err
}
if cas != nil && len(*cas) > 0 {
return &((*cas)[0]), nil
}
return nil, fmt.Errorf("id %v of calendar.attendee not found", id)
}
// GetCalendarAttendees gets calendar.attendee existing records.
func (c *Client) GetCalendarAttendees(ids []int64) (*CalendarAttendees, error) {
cas := &CalendarAttendees{}
if err := c.Read(CalendarAttendeeModel, ids, nil, cas); err != nil {
return nil, err
}
return cas, nil
}
// FindCalendarAttendee finds calendar.attendee record by querying it with criteria.
func (c *Client) FindCalendarAttendee(criteria *Criteria) (*CalendarAttendee, error) {
cas := &CalendarAttendees{}
if err := c.SearchRead(CalendarAttendeeModel, criteria, NewOptions().Limit(1), cas); err != nil {
return nil, err
}
if cas != nil && len(*cas) > 0 {
return &((*cas)[0]), nil
}
return nil, fmt.Errorf("calendar.attendee was not found with criteria %v", criteria)
}
// FindCalendarAttendees finds calendar.attendee records by querying it
// and filtering it with criteria and options.
func (c *Client) FindCalendarAttendees(criteria *Criteria, options *Options) (*CalendarAttendees, error) {
cas := &CalendarAttendees{}
if err := c.SearchRead(CalendarAttendeeModel, criteria, options, cas); err != nil {
return nil, err
}
return cas, nil
}
// FindCalendarAttendeeIds finds records ids by querying it
// and filtering it with criteria and options.
func (c *Client) FindCalendarAttendeeIds(criteria *Criteria, options *Options) ([]int64, error) {
ids, err := c.Search(CalendarAttendeeModel, criteria, options)
if err != nil {
return []int64{}, err
}
return ids, nil
}
// FindCalendarAttendeeId finds record id by querying it with criteria.
func (c *Client) FindCalendarAttendeeId(criteria *Criteria, options *Options) (int64, error) {
ids, err := c.Search(CalendarAttendeeModel, criteria, options)
if err != nil {
return -1, err
}
if len(ids) > 0 {
return ids[0], nil
}
return -1, fmt.Errorf("calendar.attendee was not found with criteria %v and options %v", criteria, options)
}