-
Notifications
You must be signed in to change notification settings - Fork 0
/
format_address_mixin.go
130 lines (113 loc) · 4.42 KB
/
format_address_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
118
119
120
121
122
123
124
125
126
127
128
129
130
package odoo
import (
"fmt"
)
// FormatAddressMixin represents format.address.mixin model.
type FormatAddressMixin struct {
LastUpdate *Time `xmlrpc:"__last_update,omptempty"`
DisplayName *String `xmlrpc:"display_name,omptempty"`
Id *Int `xmlrpc:"id,omptempty"`
}
// FormatAddressMixins represents array of format.address.mixin model.
type FormatAddressMixins []FormatAddressMixin
// FormatAddressMixinModel is the odoo model name.
const FormatAddressMixinModel = "format.address.mixin"
// Many2One convert FormatAddressMixin to *Many2One.
func (fam *FormatAddressMixin) Many2One() *Many2One {
return NewMany2One(fam.Id.Get(), "")
}
// CreateFormatAddressMixin creates a new format.address.mixin model and returns its id.
func (c *Client) CreateFormatAddressMixin(fam *FormatAddressMixin) (int64, error) {
ids, err := c.CreateFormatAddressMixins([]*FormatAddressMixin{fam})
if err != nil {
return -1, err
}
if len(ids) == 0 {
return -1, nil
}
return ids[0], nil
}
// CreateFormatAddressMixin creates a new format.address.mixin model and returns its id.
func (c *Client) CreateFormatAddressMixins(fams []*FormatAddressMixin) ([]int64, error) {
var vv []interface{}
for _, v := range fams {
vv = append(vv, v)
}
return c.Create(FormatAddressMixinModel, vv)
}
// UpdateFormatAddressMixin updates an existing format.address.mixin record.
func (c *Client) UpdateFormatAddressMixin(fam *FormatAddressMixin) error {
return c.UpdateFormatAddressMixins([]int64{fam.Id.Get()}, fam)
}
// UpdateFormatAddressMixins updates existing format.address.mixin records.
// All records (represented by ids) will be updated by fam values.
func (c *Client) UpdateFormatAddressMixins(ids []int64, fam *FormatAddressMixin) error {
return c.Update(FormatAddressMixinModel, ids, fam)
}
// DeleteFormatAddressMixin deletes an existing format.address.mixin record.
func (c *Client) DeleteFormatAddressMixin(id int64) error {
return c.DeleteFormatAddressMixins([]int64{id})
}
// DeleteFormatAddressMixins deletes existing format.address.mixin records.
func (c *Client) DeleteFormatAddressMixins(ids []int64) error {
return c.Delete(FormatAddressMixinModel, ids)
}
// GetFormatAddressMixin gets format.address.mixin existing record.
func (c *Client) GetFormatAddressMixin(id int64) (*FormatAddressMixin, error) {
fams, err := c.GetFormatAddressMixins([]int64{id})
if err != nil {
return nil, err
}
if fams != nil && len(*fams) > 0 {
return &((*fams)[0]), nil
}
return nil, fmt.Errorf("id %v of format.address.mixin not found", id)
}
// GetFormatAddressMixins gets format.address.mixin existing records.
func (c *Client) GetFormatAddressMixins(ids []int64) (*FormatAddressMixins, error) {
fams := &FormatAddressMixins{}
if err := c.Read(FormatAddressMixinModel, ids, nil, fams); err != nil {
return nil, err
}
return fams, nil
}
// FindFormatAddressMixin finds format.address.mixin record by querying it with criteria.
func (c *Client) FindFormatAddressMixin(criteria *Criteria) (*FormatAddressMixin, error) {
fams := &FormatAddressMixins{}
if err := c.SearchRead(FormatAddressMixinModel, criteria, NewOptions().Limit(1), fams); err != nil {
return nil, err
}
if fams != nil && len(*fams) > 0 {
return &((*fams)[0]), nil
}
return nil, fmt.Errorf("format.address.mixin was not found with criteria %v", criteria)
}
// FindFormatAddressMixins finds format.address.mixin records by querying it
// and filtering it with criteria and options.
func (c *Client) FindFormatAddressMixins(criteria *Criteria, options *Options) (*FormatAddressMixins, error) {
fams := &FormatAddressMixins{}
if err := c.SearchRead(FormatAddressMixinModel, criteria, options, fams); err != nil {
return nil, err
}
return fams, nil
}
// FindFormatAddressMixinIds finds records ids by querying it
// and filtering it with criteria and options.
func (c *Client) FindFormatAddressMixinIds(criteria *Criteria, options *Options) ([]int64, error) {
ids, err := c.Search(FormatAddressMixinModel, criteria, options)
if err != nil {
return []int64{}, err
}
return ids, nil
}
// FindFormatAddressMixinId finds record id by querying it with criteria.
func (c *Client) FindFormatAddressMixinId(criteria *Criteria, options *Options) (int64, error) {
ids, err := c.Search(FormatAddressMixinModel, criteria, options)
if err != nil {
return -1, err
}
if len(ids) > 0 {
return ids[0], nil
}
return -1, fmt.Errorf("format.address.mixin was not found with criteria %v and options %v", criteria, options)
}