-
Notifications
You must be signed in to change notification settings - Fork 68
/
Copy pathir_property.go
129 lines (113 loc) · 4.33 KB
/
ir_property.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
package odoo
import (
"fmt"
)
// IrProperty represents ir.property model.
type IrProperty struct {
LastUpdate *Time `xmlrpc:"__last_update,omptempty"`
CompanyId *Many2One `xmlrpc:"company_id,omptempty"`
CreateDate *Time `xmlrpc:"create_date,omptempty"`
CreateUid *Many2One `xmlrpc:"create_uid,omptempty"`
DisplayName *String `xmlrpc:"display_name,omptempty"`
FieldsId *Many2One `xmlrpc:"fields_id,omptempty"`
Id *Int `xmlrpc:"id,omptempty"`
Name *String `xmlrpc:"name,omptempty"`
ResId *String `xmlrpc:"res_id,omptempty"`
Type *Selection `xmlrpc:"type,omptempty"`
ValueBinary *String `xmlrpc:"value_binary,omptempty"`
ValueDatetime *Time `xmlrpc:"value_datetime,omptempty"`
ValueFloat *Float `xmlrpc:"value_float,omptempty"`
ValueInteger *Int `xmlrpc:"value_integer,omptempty"`
ValueReference *String `xmlrpc:"value_reference,omptempty"`
ValueText *String `xmlrpc:"value_text,omptempty"`
WriteDate *Time `xmlrpc:"write_date,omptempty"`
WriteUid *Many2One `xmlrpc:"write_uid,omptempty"`
}
// IrPropertys represents array of ir.property model.
type IrPropertys []IrProperty
// IrPropertyModel is the odoo model name.
const IrPropertyModel = "ir.property"
// Many2One convert IrProperty to *Many2One.
func (ip *IrProperty) Many2One() *Many2One {
return NewMany2One(ip.Id.Get(), "")
}
// CreateIrProperty creates a new ir.property model and returns its id.
func (c *Client) CreateIrProperty(ip *IrProperty) (int64, error) {
return c.Create(IrPropertyModel, ip)
}
// UpdateIrProperty updates an existing ir.property record.
func (c *Client) UpdateIrProperty(ip *IrProperty) error {
return c.UpdateIrPropertys([]int64{ip.Id.Get()}, ip)
}
// UpdateIrPropertys updates existing ir.property records.
// All records (represented by ids) will be updated by ip values.
func (c *Client) UpdateIrPropertys(ids []int64, ip *IrProperty) error {
return c.Update(IrPropertyModel, ids, ip)
}
// DeleteIrProperty deletes an existing ir.property record.
func (c *Client) DeleteIrProperty(id int64) error {
return c.DeleteIrPropertys([]int64{id})
}
// DeleteIrPropertys deletes existing ir.property records.
func (c *Client) DeleteIrPropertys(ids []int64) error {
return c.Delete(IrPropertyModel, ids)
}
// GetIrProperty gets ir.property existing record.
func (c *Client) GetIrProperty(id int64) (*IrProperty, error) {
ips, err := c.GetIrPropertys([]int64{id})
if err != nil {
return nil, err
}
if ips != nil && len(*ips) > 0 {
return &((*ips)[0]), nil
}
return nil, fmt.Errorf("id %v of ir.property not found", id)
}
// GetIrPropertys gets ir.property existing records.
func (c *Client) GetIrPropertys(ids []int64) (*IrPropertys, error) {
ips := &IrPropertys{}
if err := c.Read(IrPropertyModel, ids, nil, ips); err != nil {
return nil, err
}
return ips, nil
}
// FindIrProperty finds ir.property record by querying it with criteria.
func (c *Client) FindIrProperty(criteria *Criteria) (*IrProperty, error) {
ips := &IrPropertys{}
if err := c.SearchRead(IrPropertyModel, criteria, NewOptions().Limit(1), ips); err != nil {
return nil, err
}
if ips != nil && len(*ips) > 0 {
return &((*ips)[0]), nil
}
return nil, fmt.Errorf("no ir.property was found with criteria %v", criteria)
}
// FindIrPropertys finds ir.property records by querying it
// and filtering it with criteria and options.
func (c *Client) FindIrPropertys(criteria *Criteria, options *Options) (*IrPropertys, error) {
ips := &IrPropertys{}
if err := c.SearchRead(IrPropertyModel, criteria, options, ips); err != nil {
return nil, err
}
return ips, nil
}
// FindIrPropertyIds finds records ids by querying it
// and filtering it with criteria and options.
func (c *Client) FindIrPropertyIds(criteria *Criteria, options *Options) ([]int64, error) {
ids, err := c.Search(IrPropertyModel, criteria, options)
if err != nil {
return []int64{}, err
}
return ids, nil
}
// FindIrPropertyId finds record id by querying it with criteria.
func (c *Client) FindIrPropertyId(criteria *Criteria, options *Options) (int64, error) {
ids, err := c.Search(IrPropertyModel, criteria, options)
if err != nil {
return -1, err
}
if len(ids) > 0 {
return ids[0], nil
}
return -1, fmt.Errorf("no ir.property was found with criteria %v and options %v", criteria, options)
}