-
Notifications
You must be signed in to change notification settings - Fork 68
/
Copy pathir_attachment.go
138 lines (122 loc) · 4.89 KB
/
ir_attachment.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
package odoo
import (
"fmt"
)
// IrAttachment represents ir.attachment model.
type IrAttachment struct {
LastUpdate *Time `xmlrpc:"__last_update,omptempty"`
AccessToken *String `xmlrpc:"access_token,omptempty"`
Checksum *String `xmlrpc:"checksum,omptempty"`
CompanyId *Many2One `xmlrpc:"company_id,omptempty"`
CreateDate *Time `xmlrpc:"create_date,omptempty"`
CreateUid *Many2One `xmlrpc:"create_uid,omptempty"`
Datas *String `xmlrpc:"datas,omptempty"`
DatasFname *String `xmlrpc:"datas_fname,omptempty"`
DbDatas *String `xmlrpc:"db_datas,omptempty"`
Description *String `xmlrpc:"description,omptempty"`
DisplayName *String `xmlrpc:"display_name,omptempty"`
FileSize *Int `xmlrpc:"file_size,omptempty"`
Id *Int `xmlrpc:"id,omptempty"`
IndexContent *String `xmlrpc:"index_content,omptempty"`
LocalUrl *String `xmlrpc:"local_url,omptempty"`
Mimetype *String `xmlrpc:"mimetype,omptempty"`
Name *String `xmlrpc:"name,omptempty"`
Public *Bool `xmlrpc:"public,omptempty"`
ResField *String `xmlrpc:"res_field,omptempty"`
ResId *Int `xmlrpc:"res_id,omptempty"`
ResModel *String `xmlrpc:"res_model,omptempty"`
ResName *String `xmlrpc:"res_name,omptempty"`
StoreFname *String `xmlrpc:"store_fname,omptempty"`
Type *Selection `xmlrpc:"type,omptempty"`
Url *String `xmlrpc:"url,omptempty"`
WriteDate *Time `xmlrpc:"write_date,omptempty"`
WriteUid *Many2One `xmlrpc:"write_uid,omptempty"`
}
// IrAttachments represents array of ir.attachment model.
type IrAttachments []IrAttachment
// IrAttachmentModel is the odoo model name.
const IrAttachmentModel = "ir.attachment"
// Many2One convert IrAttachment to *Many2One.
func (ia *IrAttachment) Many2One() *Many2One {
return NewMany2One(ia.Id.Get(), "")
}
// CreateIrAttachment creates a new ir.attachment model and returns its id.
func (c *Client) CreateIrAttachment(ia *IrAttachment) (int64, error) {
return c.Create(IrAttachmentModel, ia)
}
// UpdateIrAttachment updates an existing ir.attachment record.
func (c *Client) UpdateIrAttachment(ia *IrAttachment) error {
return c.UpdateIrAttachments([]int64{ia.Id.Get()}, ia)
}
// UpdateIrAttachments updates existing ir.attachment records.
// All records (represented by ids) will be updated by ia values.
func (c *Client) UpdateIrAttachments(ids []int64, ia *IrAttachment) error {
return c.Update(IrAttachmentModel, ids, ia)
}
// DeleteIrAttachment deletes an existing ir.attachment record.
func (c *Client) DeleteIrAttachment(id int64) error {
return c.DeleteIrAttachments([]int64{id})
}
// DeleteIrAttachments deletes existing ir.attachment records.
func (c *Client) DeleteIrAttachments(ids []int64) error {
return c.Delete(IrAttachmentModel, ids)
}
// GetIrAttachment gets ir.attachment existing record.
func (c *Client) GetIrAttachment(id int64) (*IrAttachment, error) {
ias, err := c.GetIrAttachments([]int64{id})
if err != nil {
return nil, err
}
if ias != nil && len(*ias) > 0 {
return &((*ias)[0]), nil
}
return nil, fmt.Errorf("id %v of ir.attachment not found", id)
}
// GetIrAttachments gets ir.attachment existing records.
func (c *Client) GetIrAttachments(ids []int64) (*IrAttachments, error) {
ias := &IrAttachments{}
if err := c.Read(IrAttachmentModel, ids, nil, ias); err != nil {
return nil, err
}
return ias, nil
}
// FindIrAttachment finds ir.attachment record by querying it with criteria.
func (c *Client) FindIrAttachment(criteria *Criteria) (*IrAttachment, error) {
ias := &IrAttachments{}
if err := c.SearchRead(IrAttachmentModel, criteria, NewOptions().Limit(1), ias); err != nil {
return nil, err
}
if ias != nil && len(*ias) > 0 {
return &((*ias)[0]), nil
}
return nil, fmt.Errorf("no ir.attachment was found with criteria %v", criteria)
}
// FindIrAttachments finds ir.attachment records by querying it
// and filtering it with criteria and options.
func (c *Client) FindIrAttachments(criteria *Criteria, options *Options) (*IrAttachments, error) {
ias := &IrAttachments{}
if err := c.SearchRead(IrAttachmentModel, criteria, options, ias); err != nil {
return nil, err
}
return ias, nil
}
// FindIrAttachmentIds finds records ids by querying it
// and filtering it with criteria and options.
func (c *Client) FindIrAttachmentIds(criteria *Criteria, options *Options) ([]int64, error) {
ids, err := c.Search(IrAttachmentModel, criteria, options)
if err != nil {
return []int64{}, err
}
return ids, nil
}
// FindIrAttachmentId finds record id by querying it with criteria.
func (c *Client) FindIrAttachmentId(criteria *Criteria, options *Options) (int64, error) {
ids, err := c.Search(IrAttachmentModel, criteria, options)
if err != nil {
return -1, err
}
if len(ids) > 0 {
return ids[0], nil
}
return -1, fmt.Errorf("no ir.attachment was found with criteria %v and options %v", criteria, options)
}