forked from skilld-labs/go-odoo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcrm_lead.go
168 lines (154 loc) · 7.85 KB
/
crm_lead.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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
package odoo
import (
"fmt"
)
// CrmLead represents crm.lead model
type CrmLead struct {
LastUpdate *Time `xmlrpc:"__last_update,omptempty"`
Active *Bool `xmlrpc:"active,omptempty"`
ActivityDateDeadline *Time `xmlrpc:"activity_date_deadline,omptempty"`
ActivityIds *Relation `xmlrpc:"activity_ids,omptempty"`
ActivityState *Selection `xmlrpc:"activity_state,omptempty"`
ActivitySummary *String `xmlrpc:"activity_summary,omptempty"`
ActivityTypeId *Many2One `xmlrpc:"activity_type_id,omptempty"`
ActivityUserId *Many2One `xmlrpc:"activity_user_id,omptempty"`
CampaignId *Many2One `xmlrpc:"campaign_id,omptempty"`
City *String `xmlrpc:"city,omptempty"`
Color *Int `xmlrpc:"color,omptempty"`
CompanyCurrency *Many2One `xmlrpc:"company_currency,omptempty"`
CompanyId *Many2One `xmlrpc:"company_id,omptempty"`
ContactName *String `xmlrpc:"contact_name,omptempty"`
CountryId *Many2One `xmlrpc:"country_id,omptempty"`
CreateDate *Time `xmlrpc:"create_date,omptempty"`
CreateUid *Many2One `xmlrpc:"create_uid,omptempty"`
DateActionLast *Time `xmlrpc:"date_action_last,omptempty"`
DateClosed *Time `xmlrpc:"date_closed,omptempty"`
DateConversion *Time `xmlrpc:"date_conversion,omptempty"`
DateDeadline *Time `xmlrpc:"date_deadline,omptempty"`
DateLastStageUpdate *Time `xmlrpc:"date_last_stage_update,omptempty"`
DateOpen *Time `xmlrpc:"date_open,omptempty"`
DayClose *Float `xmlrpc:"day_close,omptempty"`
DayOpen *Float `xmlrpc:"day_open,omptempty"`
Description *String `xmlrpc:"description,omptempty"`
DisplayName *String `xmlrpc:"display_name,omptempty"`
EmailCc *String `xmlrpc:"email_cc,omptempty"`
EmailFrom *String `xmlrpc:"email_from,omptempty"`
Function *String `xmlrpc:"function,omptempty"`
Id *Int `xmlrpc:"id,omptempty"`
KanbanState *Selection `xmlrpc:"kanban_state,omptempty"`
LostReason *Many2One `xmlrpc:"lost_reason,omptempty"`
MachineLeadName *String `xmlrpc:"machine_lead_name,omptempty"`
MediumId *Many2One `xmlrpc:"medium_id,omptempty"`
MeetingCount *Int `xmlrpc:"meeting_count,omptempty"`
MessageBounce *Int `xmlrpc:"message_bounce,omptempty"`
MessageChannelIds *Relation `xmlrpc:"message_channel_ids,omptempty"`
MessageFollowerIds *Relation `xmlrpc:"message_follower_ids,omptempty"`
MessageIds *Relation `xmlrpc:"message_ids,omptempty"`
MessageIsFollower *Bool `xmlrpc:"message_is_follower,omptempty"`
MessageLastPost *Time `xmlrpc:"message_last_post,omptempty"`
MessageNeedaction *Bool `xmlrpc:"message_needaction,omptempty"`
MessageNeedactionCounter *Int `xmlrpc:"message_needaction_counter,omptempty"`
MessagePartnerIds *Relation `xmlrpc:"message_partner_ids,omptempty"`
MessageUnread *Bool `xmlrpc:"message_unread,omptempty"`
MessageUnreadCounter *Int `xmlrpc:"message_unread_counter,omptempty"`
Mobile *String `xmlrpc:"mobile,omptempty"`
Name *String `xmlrpc:"name,omptempty"`
OptOut *Bool `xmlrpc:"opt_out,omptempty"`
OrderIds *Relation `xmlrpc:"order_ids,omptempty"`
PartnerAddressEmail *String `xmlrpc:"partner_address_email,omptempty"`
PartnerAddressName *String `xmlrpc:"partner_address_name,omptempty"`
PartnerId *Many2One `xmlrpc:"partner_id,omptempty"`
PartnerName *String `xmlrpc:"partner_name,omptempty"`
Phone *String `xmlrpc:"phone,omptempty"`
PlannedRevenue *Float `xmlrpc:"planned_revenue,omptempty"`
Priority *Selection `xmlrpc:"priority,omptempty"`
Probability *Float `xmlrpc:"probability,omptempty"`
Referred *String `xmlrpc:"referred,omptempty"`
SaleAmountTotal *Float `xmlrpc:"sale_amount_total,omptempty"`
SaleNumber *Int `xmlrpc:"sale_number,omptempty"`
SourceId *Many2One `xmlrpc:"source_id,omptempty"`
StageId *Many2One `xmlrpc:"stage_id,omptempty"`
StateId *Many2One `xmlrpc:"state_id,omptempty"`
Street *String `xmlrpc:"street,omptempty"`
Street2 *String `xmlrpc:"street2,omptempty"`
TagIds *Relation `xmlrpc:"tag_ids,omptempty"`
TeamId *Many2One `xmlrpc:"team_id,omptempty"`
Title *Many2One `xmlrpc:"title,omptempty"`
Type *Selection `xmlrpc:"type,omptempty"`
UserEmail *String `xmlrpc:"user_email,omptempty"`
UserId *Many2One `xmlrpc:"user_id,omptempty"`
UserLogin *String `xmlrpc:"user_login,omptempty"`
Website *String `xmlrpc:"website,omptempty"`
WebsiteMessageIds *Relation `xmlrpc:"website_message_ids,omptempty"`
WriteDate *Time `xmlrpc:"write_date,omptempty"`
WriteUid *Many2One `xmlrpc:"write_uid,omptempty"`
Zip *String `xmlrpc:"zip,omptempty"`
}
// CrmLeads represents array of crm.lead model
type CrmLeads []CrmLead
// CrmLeadModel is the odoo model name
const CrmLeadModel = "crm.lead"
// Many2One convert CrmLead to *Many2One.
func (cl *CrmLead) Many2One() *Many2One {
return NewMany2One(cl.Id.Get(), "")
}
// CreateCrmLead creates a new crm.lead model and returns its id.
func (c *Client) CreateCrmLead(cl *CrmLead) (int64, error) {
return c.Create(CrmLeadModel, cl)
}
// UpdateCrmLead updates an existing crm.lead record.
func (c *Client) UpdateCrmLead(cl *CrmLead) error {
return c.UpdateCrmLeads([]int64{cl.Id.Get()}, cl)
}
// UpdateCrmLeads updates existing crm.lead records.
// All records (represented by ids) will be updated by cl values.
func (c *Client) UpdateCrmLeads(ids []int64, cl *CrmLead) error {
return c.Update(CrmLeadModel, ids, cl)
}
// DeleteCrmLead deletes an existing crm.lead record.
func (c *Client) DeleteCrmLead(id int64) error {
return c.DeleteCrmLeads([]int64{id})
}
// DeleteCrmLeads deletes existing crm.lead records.
func (c *Client) DeleteCrmLeads(ids []int64) error {
return c.Delete(CrmLeadModel, ids)
}
// GetCrmLead gets crm.lead existing record.
func (c *Client) GetCrmLead(id int64) (*CrmLead, error) {
cls, err := c.GetCrmLeads([]int64{id})
if err != nil {
return nil, err
}
if cls != nil && len(*cls) > 0 {
return &((*cls)[0]), nil
}
return nil, fmt.Errorf("id %v of %s not found", id, CrmLeadModel)
}
// GetCrmLeads gets crm.lead existing records.
func (c *Client) GetCrmLeads(ids []int64) (*CrmLeads, error) {
cls := &CrmLeads{}
if err := c.Read(CrmLeadModel, ids, nil, cls); err != nil {
return nil, err
}
return cls, nil
}
// FindCrmLead finds crm.lead record by querying it with criteria
func (c *Client) FindCrmLead(criteria *Criteria) (*CrmLead, error) {
cls := &CrmLeads{}
if err := c.SearchRead(CrmLeadModel, criteria, NewOptions().Limit(1), cls); err != nil {
return nil, err
}
if cls != nil && len(*cls) > 0 {
return &((*cls)[0]), nil
}
return nil, fmt.Errorf("crm.lead was not found")
}
// FindCrmLeads finds crm.lead records by querying it
// and filtering it with criteria and options.
func (c *Client) FindCrmLeads(criteria *Criteria, options *Options) (*CrmLeads, error) {
cls := &CrmLeads{}
if err := c.SearchRead(CrmLeadModel, criteria, options, cls); err != nil {
return nil, err
}
return cls, nil
}