forked from skilld-labs/go-odoo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
account_analytic_tag.go
121 lines (105 loc) · 4.3 KB
/
account_analytic_tag.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
package odoo
import (
"fmt"
)
// AccountAnalyticTag represents account.analytic.tag model.
type AccountAnalyticTag struct {
LastUpdate *Time `xmlrpc:"__last_update,omptempty"`
Active *Bool `xmlrpc:"active,omptempty"`
Color *Int `xmlrpc:"color,omptempty"`
CreateDate *Time `xmlrpc:"create_date,omptempty"`
CreateUid *Many2One `xmlrpc:"create_uid,omptempty"`
DisplayName *String `xmlrpc:"display_name,omptempty"`
Id *Int `xmlrpc:"id,omptempty"`
Name *String `xmlrpc:"name,omptempty"`
WriteDate *Time `xmlrpc:"write_date,omptempty"`
WriteUid *Many2One `xmlrpc:"write_uid,omptempty"`
}
// AccountAnalyticTags represents array of account.analytic.tag model.
type AccountAnalyticTags []AccountAnalyticTag
// AccountAnalyticTagModel is the odoo model name.
const AccountAnalyticTagModel = "account.analytic.tag"
// Many2One convert AccountAnalyticTag to *Many2One.
func (aat *AccountAnalyticTag) Many2One() *Many2One {
return NewMany2One(aat.Id.Get(), "")
}
// CreateAccountAnalyticTag creates a new account.analytic.tag model and returns its id.
func (c *Client) CreateAccountAnalyticTag(aat *AccountAnalyticTag) (int64, error) {
return c.Create(AccountAnalyticTagModel, aat)
}
// UpdateAccountAnalyticTag updates an existing account.analytic.tag record.
func (c *Client) UpdateAccountAnalyticTag(aat *AccountAnalyticTag) error {
return c.UpdateAccountAnalyticTags([]int64{aat.Id.Get()}, aat)
}
// UpdateAccountAnalyticTags updates existing account.analytic.tag records.
// All records (represented by ids) will be updated by aat values.
func (c *Client) UpdateAccountAnalyticTags(ids []int64, aat *AccountAnalyticTag) error {
return c.Update(AccountAnalyticTagModel, ids, aat)
}
// DeleteAccountAnalyticTag deletes an existing account.analytic.tag record.
func (c *Client) DeleteAccountAnalyticTag(id int64) error {
return c.DeleteAccountAnalyticTags([]int64{id})
}
// DeleteAccountAnalyticTags deletes existing account.analytic.tag records.
func (c *Client) DeleteAccountAnalyticTags(ids []int64) error {
return c.Delete(AccountAnalyticTagModel, ids)
}
// GetAccountAnalyticTag gets account.analytic.tag existing record.
func (c *Client) GetAccountAnalyticTag(id int64) (*AccountAnalyticTag, error) {
aats, err := c.GetAccountAnalyticTags([]int64{id})
if err != nil {
return nil, err
}
if aats != nil && len(*aats) > 0 {
return &((*aats)[0]), nil
}
return nil, fmt.Errorf("id %v of account.analytic.tag not found", id)
}
// GetAccountAnalyticTags gets account.analytic.tag existing records.
func (c *Client) GetAccountAnalyticTags(ids []int64) (*AccountAnalyticTags, error) {
aats := &AccountAnalyticTags{}
if err := c.Read(AccountAnalyticTagModel, ids, nil, aats); err != nil {
return nil, err
}
return aats, nil
}
// FindAccountAnalyticTag finds account.analytic.tag record by querying it with criteria.
func (c *Client) FindAccountAnalyticTag(criteria *Criteria) (*AccountAnalyticTag, error) {
aats := &AccountAnalyticTags{}
if err := c.SearchRead(AccountAnalyticTagModel, criteria, NewOptions().Limit(1), aats); err != nil {
return nil, err
}
if aats != nil && len(*aats) > 0 {
return &((*aats)[0]), nil
}
return nil, fmt.Errorf("account.analytic.tag was not found")
}
// FindAccountAnalyticTags finds account.analytic.tag records by querying it
// and filtering it with criteria and options.
func (c *Client) FindAccountAnalyticTags(criteria *Criteria, options *Options) (*AccountAnalyticTags, error) {
aats := &AccountAnalyticTags{}
if err := c.SearchRead(AccountAnalyticTagModel, criteria, options, aats); err != nil {
return nil, err
}
return aats, nil
}
// FindAccountAnalyticTagIds finds records ids by querying it
// and filtering it with criteria and options.
func (c *Client) FindAccountAnalyticTagIds(criteria *Criteria, options *Options) ([]int64, error) {
ids, err := c.Search(AccountAnalyticTagModel, criteria, options)
if err != nil {
return []int64{}, err
}
return ids, nil
}
// FindAccountAnalyticTagId finds record id by querying it with criteria.
func (c *Client) FindAccountAnalyticTagId(criteria *Criteria, options *Options) (int64, error) {
ids, err := c.Search(AccountAnalyticTagModel, criteria, options)
if err != nil {
return -1, err
}
if len(ids) > 0 {
return ids[0], nil
}
return -1, fmt.Errorf("account.analytic.tag was not found")
}