-
Notifications
You must be signed in to change notification settings - Fork 68
/
Copy pathcrm_merge_opportunity.go
121 lines (105 loc) · 4.49 KB
/
crm_merge_opportunity.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"
)
// CrmMergeOpportunity represents crm.merge.opportunity model.
type CrmMergeOpportunity struct {
LastUpdate *Time `xmlrpc:"__last_update,omptempty"`
CreateDate *Time `xmlrpc:"create_date,omptempty"`
CreateUid *Many2One `xmlrpc:"create_uid,omptempty"`
DisplayName *String `xmlrpc:"display_name,omptempty"`
Id *Int `xmlrpc:"id,omptempty"`
OpportunityIds *Relation `xmlrpc:"opportunity_ids,omptempty"`
TeamId *Many2One `xmlrpc:"team_id,omptempty"`
UserId *Many2One `xmlrpc:"user_id,omptempty"`
WriteDate *Time `xmlrpc:"write_date,omptempty"`
WriteUid *Many2One `xmlrpc:"write_uid,omptempty"`
}
// CrmMergeOpportunitys represents array of crm.merge.opportunity model.
type CrmMergeOpportunitys []CrmMergeOpportunity
// CrmMergeOpportunityModel is the odoo model name.
const CrmMergeOpportunityModel = "crm.merge.opportunity"
// Many2One convert CrmMergeOpportunity to *Many2One.
func (cmo *CrmMergeOpportunity) Many2One() *Many2One {
return NewMany2One(cmo.Id.Get(), "")
}
// CreateCrmMergeOpportunity creates a new crm.merge.opportunity model and returns its id.
func (c *Client) CreateCrmMergeOpportunity(cmo *CrmMergeOpportunity) (int64, error) {
return c.Create(CrmMergeOpportunityModel, cmo)
}
// UpdateCrmMergeOpportunity updates an existing crm.merge.opportunity record.
func (c *Client) UpdateCrmMergeOpportunity(cmo *CrmMergeOpportunity) error {
return c.UpdateCrmMergeOpportunitys([]int64{cmo.Id.Get()}, cmo)
}
// UpdateCrmMergeOpportunitys updates existing crm.merge.opportunity records.
// All records (represented by ids) will be updated by cmo values.
func (c *Client) UpdateCrmMergeOpportunitys(ids []int64, cmo *CrmMergeOpportunity) error {
return c.Update(CrmMergeOpportunityModel, ids, cmo)
}
// DeleteCrmMergeOpportunity deletes an existing crm.merge.opportunity record.
func (c *Client) DeleteCrmMergeOpportunity(id int64) error {
return c.DeleteCrmMergeOpportunitys([]int64{id})
}
// DeleteCrmMergeOpportunitys deletes existing crm.merge.opportunity records.
func (c *Client) DeleteCrmMergeOpportunitys(ids []int64) error {
return c.Delete(CrmMergeOpportunityModel, ids)
}
// GetCrmMergeOpportunity gets crm.merge.opportunity existing record.
func (c *Client) GetCrmMergeOpportunity(id int64) (*CrmMergeOpportunity, error) {
cmos, err := c.GetCrmMergeOpportunitys([]int64{id})
if err != nil {
return nil, err
}
if cmos != nil && len(*cmos) > 0 {
return &((*cmos)[0]), nil
}
return nil, fmt.Errorf("id %v of crm.merge.opportunity not found", id)
}
// GetCrmMergeOpportunitys gets crm.merge.opportunity existing records.
func (c *Client) GetCrmMergeOpportunitys(ids []int64) (*CrmMergeOpportunitys, error) {
cmos := &CrmMergeOpportunitys{}
if err := c.Read(CrmMergeOpportunityModel, ids, nil, cmos); err != nil {
return nil, err
}
return cmos, nil
}
// FindCrmMergeOpportunity finds crm.merge.opportunity record by querying it with criteria.
func (c *Client) FindCrmMergeOpportunity(criteria *Criteria) (*CrmMergeOpportunity, error) {
cmos := &CrmMergeOpportunitys{}
if err := c.SearchRead(CrmMergeOpportunityModel, criteria, NewOptions().Limit(1), cmos); err != nil {
return nil, err
}
if cmos != nil && len(*cmos) > 0 {
return &((*cmos)[0]), nil
}
return nil, fmt.Errorf("no crm.merge.opportunity was found with criteria %v", criteria)
}
// FindCrmMergeOpportunitys finds crm.merge.opportunity records by querying it
// and filtering it with criteria and options.
func (c *Client) FindCrmMergeOpportunitys(criteria *Criteria, options *Options) (*CrmMergeOpportunitys, error) {
cmos := &CrmMergeOpportunitys{}
if err := c.SearchRead(CrmMergeOpportunityModel, criteria, options, cmos); err != nil {
return nil, err
}
return cmos, nil
}
// FindCrmMergeOpportunityIds finds records ids by querying it
// and filtering it with criteria and options.
func (c *Client) FindCrmMergeOpportunityIds(criteria *Criteria, options *Options) ([]int64, error) {
ids, err := c.Search(CrmMergeOpportunityModel, criteria, options)
if err != nil {
return []int64{}, err
}
return ids, nil
}
// FindCrmMergeOpportunityId finds record id by querying it with criteria.
func (c *Client) FindCrmMergeOpportunityId(criteria *Criteria, options *Options) (int64, error) {
ids, err := c.Search(CrmMergeOpportunityModel, criteria, options)
if err != nil {
return -1, err
}
if len(ids) > 0 {
return ids[0], nil
}
return -1, fmt.Errorf("no crm.merge.opportunity was found with criteria %v and options %v", criteria, options)
}