-
Notifications
You must be signed in to change notification settings - Fork 68
/
Copy pathir_model.go
130 lines (114 loc) · 4.23 KB
/
ir_model.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
package odoo
import (
"fmt"
)
// IrModel represents ir.model model.
type IrModel struct {
LastUpdate *Time `xmlrpc:"__last_update,omptempty"`
AccessIds *Relation `xmlrpc:"access_ids,omptempty"`
Count *Int `xmlrpc:"count,omptempty"`
CreateDate *Time `xmlrpc:"create_date,omptempty"`
CreateUid *Many2One `xmlrpc:"create_uid,omptempty"`
DisplayName *String `xmlrpc:"display_name,omptempty"`
FieldId *Relation `xmlrpc:"field_id,omptempty"`
Id *Int `xmlrpc:"id,omptempty"`
Info *String `xmlrpc:"info,omptempty"`
InheritedModelIds *Relation `xmlrpc:"inherited_model_ids,omptempty"`
IsMailThread *Bool `xmlrpc:"is_mail_thread,omptempty"`
Model *String `xmlrpc:"model,omptempty"`
Modules *String `xmlrpc:"modules,omptempty"`
Name *String `xmlrpc:"name,omptempty"`
State *Selection `xmlrpc:"state,omptempty"`
Transient *Bool `xmlrpc:"transient,omptempty"`
ViewIds *Relation `xmlrpc:"view_ids,omptempty"`
WriteDate *Time `xmlrpc:"write_date,omptempty"`
WriteUid *Many2One `xmlrpc:"write_uid,omptempty"`
}
// IrModels represents array of ir.model model.
type IrModels []IrModel
// IrModelModel is the odoo model name.
const IrModelModel = "ir.model"
// Many2One convert IrModel to *Many2One.
func (im *IrModel) Many2One() *Many2One {
return NewMany2One(im.Id.Get(), "")
}
// CreateIrModel creates a new ir.model model and returns its id.
func (c *Client) CreateIrModel(im *IrModel) (int64, error) {
return c.Create(IrModelModel, im)
}
// UpdateIrModel updates an existing ir.model record.
func (c *Client) UpdateIrModel(im *IrModel) error {
return c.UpdateIrModels([]int64{im.Id.Get()}, im)
}
// UpdateIrModels updates existing ir.model records.
// All records (represented by ids) will be updated by im values.
func (c *Client) UpdateIrModels(ids []int64, im *IrModel) error {
return c.Update(IrModelModel, ids, im)
}
// DeleteIrModel deletes an existing ir.model record.
func (c *Client) DeleteIrModel(id int64) error {
return c.DeleteIrModels([]int64{id})
}
// DeleteIrModels deletes existing ir.model records.
func (c *Client) DeleteIrModels(ids []int64) error {
return c.Delete(IrModelModel, ids)
}
// GetIrModel gets ir.model existing record.
func (c *Client) GetIrModel(id int64) (*IrModel, error) {
ims, err := c.GetIrModels([]int64{id})
if err != nil {
return nil, err
}
if ims != nil && len(*ims) > 0 {
return &((*ims)[0]), nil
}
return nil, fmt.Errorf("id %v of ir.model not found", id)
}
// GetIrModels gets ir.model existing records.
func (c *Client) GetIrModels(ids []int64) (*IrModels, error) {
ims := &IrModels{}
if err := c.Read(IrModelModel, ids, nil, ims); err != nil {
return nil, err
}
return ims, nil
}
// FindIrModel finds ir.model record by querying it with criteria.
func (c *Client) FindIrModel(criteria *Criteria) (*IrModel, error) {
ims := &IrModels{}
if err := c.SearchRead(IrModelModel, criteria, NewOptions().Limit(1), ims); err != nil {
return nil, err
}
if ims != nil && len(*ims) > 0 {
return &((*ims)[0]), nil
}
return nil, fmt.Errorf("no ir.model was found with criteria %v", criteria)
}
// FindIrModels finds ir.model records by querying it
// and filtering it with criteria and options.
func (c *Client) FindIrModels(criteria *Criteria, options *Options) (*IrModels, error) {
ims := &IrModels{}
if err := c.SearchRead(IrModelModel, criteria, options, ims); err != nil {
return nil, err
}
return ims, nil
}
// FindIrModelIds finds records ids by querying it
// and filtering it with criteria and options.
func (c *Client) FindIrModelIds(criteria *Criteria, options *Options) ([]int64, error) {
ids, err := c.Search(IrModelModel, criteria, options)
if err != nil {
return []int64{}, err
}
return ids, nil
}
// FindIrModelId finds record id by querying it with criteria.
func (c *Client) FindIrModelId(criteria *Criteria, options *Options) (int64, error) {
ids, err := c.Search(IrModelModel, criteria, options)
if err != nil {
return -1, err
}
if len(ids) > 0 {
return ids[0], nil
}
return -1, fmt.Errorf("no ir.model was found with criteria %v and options %v", criteria, options)
}