-
Notifications
You must be signed in to change notification settings - Fork 68
/
Copy pathresource_mixin.go
117 lines (101 loc) · 3.86 KB
/
resource_mixin.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
package odoo
import (
"fmt"
)
// ResourceMixin represents resource.mixin model.
type ResourceMixin struct {
LastUpdate *Time `xmlrpc:"__last_update,omptempty"`
CompanyId *Many2One `xmlrpc:"company_id,omptempty"`
DisplayName *String `xmlrpc:"display_name,omptempty"`
Id *Int `xmlrpc:"id,omptempty"`
ResourceCalendarId *Many2One `xmlrpc:"resource_calendar_id,omptempty"`
ResourceId *Many2One `xmlrpc:"resource_id,omptempty"`
}
// ResourceMixins represents array of resource.mixin model.
type ResourceMixins []ResourceMixin
// ResourceMixinModel is the odoo model name.
const ResourceMixinModel = "resource.mixin"
// Many2One convert ResourceMixin to *Many2One.
func (rm *ResourceMixin) Many2One() *Many2One {
return NewMany2One(rm.Id.Get(), "")
}
// CreateResourceMixin creates a new resource.mixin model and returns its id.
func (c *Client) CreateResourceMixin(rm *ResourceMixin) (int64, error) {
return c.Create(ResourceMixinModel, rm)
}
// UpdateResourceMixin updates an existing resource.mixin record.
func (c *Client) UpdateResourceMixin(rm *ResourceMixin) error {
return c.UpdateResourceMixins([]int64{rm.Id.Get()}, rm)
}
// UpdateResourceMixins updates existing resource.mixin records.
// All records (represented by ids) will be updated by rm values.
func (c *Client) UpdateResourceMixins(ids []int64, rm *ResourceMixin) error {
return c.Update(ResourceMixinModel, ids, rm)
}
// DeleteResourceMixin deletes an existing resource.mixin record.
func (c *Client) DeleteResourceMixin(id int64) error {
return c.DeleteResourceMixins([]int64{id})
}
// DeleteResourceMixins deletes existing resource.mixin records.
func (c *Client) DeleteResourceMixins(ids []int64) error {
return c.Delete(ResourceMixinModel, ids)
}
// GetResourceMixin gets resource.mixin existing record.
func (c *Client) GetResourceMixin(id int64) (*ResourceMixin, error) {
rms, err := c.GetResourceMixins([]int64{id})
if err != nil {
return nil, err
}
if rms != nil && len(*rms) > 0 {
return &((*rms)[0]), nil
}
return nil, fmt.Errorf("id %v of resource.mixin not found", id)
}
// GetResourceMixins gets resource.mixin existing records.
func (c *Client) GetResourceMixins(ids []int64) (*ResourceMixins, error) {
rms := &ResourceMixins{}
if err := c.Read(ResourceMixinModel, ids, nil, rms); err != nil {
return nil, err
}
return rms, nil
}
// FindResourceMixin finds resource.mixin record by querying it with criteria.
func (c *Client) FindResourceMixin(criteria *Criteria) (*ResourceMixin, error) {
rms := &ResourceMixins{}
if err := c.SearchRead(ResourceMixinModel, criteria, NewOptions().Limit(1), rms); err != nil {
return nil, err
}
if rms != nil && len(*rms) > 0 {
return &((*rms)[0]), nil
}
return nil, fmt.Errorf("no resource.mixin was found with criteria %v", criteria)
}
// FindResourceMixins finds resource.mixin records by querying it
// and filtering it with criteria and options.
func (c *Client) FindResourceMixins(criteria *Criteria, options *Options) (*ResourceMixins, error) {
rms := &ResourceMixins{}
if err := c.SearchRead(ResourceMixinModel, criteria, options, rms); err != nil {
return nil, err
}
return rms, nil
}
// FindResourceMixinIds finds records ids by querying it
// and filtering it with criteria and options.
func (c *Client) FindResourceMixinIds(criteria *Criteria, options *Options) ([]int64, error) {
ids, err := c.Search(ResourceMixinModel, criteria, options)
if err != nil {
return []int64{}, err
}
return ids, nil
}
// FindResourceMixinId finds record id by querying it with criteria.
func (c *Client) FindResourceMixinId(criteria *Criteria, options *Options) (int64, error) {
ids, err := c.Search(ResourceMixinModel, criteria, options)
if err != nil {
return -1, err
}
if len(ids) > 0 {
return ids[0], nil
}
return -1, fmt.Errorf("no resource.mixin was found with criteria %v and options %v", criteria, options)
}