-
Notifications
You must be signed in to change notification settings - Fork 68
/
Copy pathcrm_lead_tag.go
120 lines (104 loc) · 3.81 KB
/
crm_lead_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
package odoo
import (
"fmt"
)
// CrmLeadTag represents crm.lead.tag model.
type CrmLeadTag struct {
LastUpdate *Time `xmlrpc:"__last_update,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"`
}
// CrmLeadTags represents array of crm.lead.tag model.
type CrmLeadTags []CrmLeadTag
// CrmLeadTagModel is the odoo model name.
const CrmLeadTagModel = "crm.lead.tag"
// Many2One convert CrmLeadTag to *Many2One.
func (clt *CrmLeadTag) Many2One() *Many2One {
return NewMany2One(clt.Id.Get(), "")
}
// CreateCrmLeadTag creates a new crm.lead.tag model and returns its id.
func (c *Client) CreateCrmLeadTag(clt *CrmLeadTag) (int64, error) {
return c.Create(CrmLeadTagModel, clt)
}
// UpdateCrmLeadTag updates an existing crm.lead.tag record.
func (c *Client) UpdateCrmLeadTag(clt *CrmLeadTag) error {
return c.UpdateCrmLeadTags([]int64{clt.Id.Get()}, clt)
}
// UpdateCrmLeadTags updates existing crm.lead.tag records.
// All records (represented by ids) will be updated by clt values.
func (c *Client) UpdateCrmLeadTags(ids []int64, clt *CrmLeadTag) error {
return c.Update(CrmLeadTagModel, ids, clt)
}
// DeleteCrmLeadTag deletes an existing crm.lead.tag record.
func (c *Client) DeleteCrmLeadTag(id int64) error {
return c.DeleteCrmLeadTags([]int64{id})
}
// DeleteCrmLeadTags deletes existing crm.lead.tag records.
func (c *Client) DeleteCrmLeadTags(ids []int64) error {
return c.Delete(CrmLeadTagModel, ids)
}
// GetCrmLeadTag gets crm.lead.tag existing record.
func (c *Client) GetCrmLeadTag(id int64) (*CrmLeadTag, error) {
clts, err := c.GetCrmLeadTags([]int64{id})
if err != nil {
return nil, err
}
if clts != nil && len(*clts) > 0 {
return &((*clts)[0]), nil
}
return nil, fmt.Errorf("id %v of crm.lead.tag not found", id)
}
// GetCrmLeadTags gets crm.lead.tag existing records.
func (c *Client) GetCrmLeadTags(ids []int64) (*CrmLeadTags, error) {
clts := &CrmLeadTags{}
if err := c.Read(CrmLeadTagModel, ids, nil, clts); err != nil {
return nil, err
}
return clts, nil
}
// FindCrmLeadTag finds crm.lead.tag record by querying it with criteria.
func (c *Client) FindCrmLeadTag(criteria *Criteria) (*CrmLeadTag, error) {
clts := &CrmLeadTags{}
if err := c.SearchRead(CrmLeadTagModel, criteria, NewOptions().Limit(1), clts); err != nil {
return nil, err
}
if clts != nil && len(*clts) > 0 {
return &((*clts)[0]), nil
}
return nil, fmt.Errorf("no crm.lead.tag was found with criteria %v", criteria)
}
// FindCrmLeadTags finds crm.lead.tag records by querying it
// and filtering it with criteria and options.
func (c *Client) FindCrmLeadTags(criteria *Criteria, options *Options) (*CrmLeadTags, error) {
clts := &CrmLeadTags{}
if err := c.SearchRead(CrmLeadTagModel, criteria, options, clts); err != nil {
return nil, err
}
return clts, nil
}
// FindCrmLeadTagIds finds records ids by querying it
// and filtering it with criteria and options.
func (c *Client) FindCrmLeadTagIds(criteria *Criteria, options *Options) ([]int64, error) {
ids, err := c.Search(CrmLeadTagModel, criteria, options)
if err != nil {
return []int64{}, err
}
return ids, nil
}
// FindCrmLeadTagId finds record id by querying it with criteria.
func (c *Client) FindCrmLeadTagId(criteria *Criteria, options *Options) (int64, error) {
ids, err := c.Search(CrmLeadTagModel, criteria, options)
if err != nil {
return -1, err
}
if len(ids) > 0 {
return ids[0], nil
}
return -1, fmt.Errorf("no crm.lead.tag was found with criteria %v and options %v", criteria, options)
}