|
| 1 | +package odoo |
| 2 | + |
| 3 | +import ( |
| 4 | + "fmt" |
| 5 | +) |
| 6 | + |
| 7 | +// CrmLead represents crm.lead model |
| 8 | +type CrmLead struct { |
| 9 | + LastUpdate *Time `xmlrpc:"__last_update,omptempty"` |
| 10 | + Active *Bool `xmlrpc:"active,omptempty"` |
| 11 | + ActivityDateDeadline *Time `xmlrpc:"activity_date_deadline,omptempty"` |
| 12 | + ActivityIds *Relation `xmlrpc:"activity_ids,omptempty"` |
| 13 | + ActivityState *Selection `xmlrpc:"activity_state,omptempty"` |
| 14 | + ActivitySummary *String `xmlrpc:"activity_summary,omptempty"` |
| 15 | + ActivityTypeId *Many2One `xmlrpc:"activity_type_id,omptempty"` |
| 16 | + ActivityUserId *Many2One `xmlrpc:"activity_user_id,omptempty"` |
| 17 | + CampaignId *Many2One `xmlrpc:"campaign_id,omptempty"` |
| 18 | + City *String `xmlrpc:"city,omptempty"` |
| 19 | + Color *Int `xmlrpc:"color,omptempty"` |
| 20 | + CompanyCurrency *Many2One `xmlrpc:"company_currency,omptempty"` |
| 21 | + CompanyId *Many2One `xmlrpc:"company_id,omptempty"` |
| 22 | + ContactName *String `xmlrpc:"contact_name,omptempty"` |
| 23 | + CountryId *Many2One `xmlrpc:"country_id,omptempty"` |
| 24 | + CreateDate *Time `xmlrpc:"create_date,omptempty"` |
| 25 | + CreateUid *Many2One `xmlrpc:"create_uid,omptempty"` |
| 26 | + DateActionLast *Time `xmlrpc:"date_action_last,omptempty"` |
| 27 | + DateClosed *Time `xmlrpc:"date_closed,omptempty"` |
| 28 | + DateConversion *Time `xmlrpc:"date_conversion,omptempty"` |
| 29 | + DateDeadline *Time `xmlrpc:"date_deadline,omptempty"` |
| 30 | + DateLastStageUpdate *Time `xmlrpc:"date_last_stage_update,omptempty"` |
| 31 | + DateOpen *Time `xmlrpc:"date_open,omptempty"` |
| 32 | + DayClose *Float `xmlrpc:"day_close,omptempty"` |
| 33 | + DayOpen *Float `xmlrpc:"day_open,omptempty"` |
| 34 | + Description *String `xmlrpc:"description,omptempty"` |
| 35 | + DisplayName *String `xmlrpc:"display_name,omptempty"` |
| 36 | + EmailCc *String `xmlrpc:"email_cc,omptempty"` |
| 37 | + EmailFrom *String `xmlrpc:"email_from,omptempty"` |
| 38 | + Function *String `xmlrpc:"function,omptempty"` |
| 39 | + Id *Int `xmlrpc:"id,omptempty"` |
| 40 | + KanbanState *Selection `xmlrpc:"kanban_state,omptempty"` |
| 41 | + LostReason *Many2One `xmlrpc:"lost_reason,omptempty"` |
| 42 | + MachineLeadName *String `xmlrpc:"machine_lead_name,omptempty"` |
| 43 | + MediumId *Many2One `xmlrpc:"medium_id,omptempty"` |
| 44 | + MeetingCount *Int `xmlrpc:"meeting_count,omptempty"` |
| 45 | + MessageBounce *Int `xmlrpc:"message_bounce,omptempty"` |
| 46 | + MessageChannelIds *Relation `xmlrpc:"message_channel_ids,omptempty"` |
| 47 | + MessageFollowerIds *Relation `xmlrpc:"message_follower_ids,omptempty"` |
| 48 | + MessageIds *Relation `xmlrpc:"message_ids,omptempty"` |
| 49 | + MessageIsFollower *Bool `xmlrpc:"message_is_follower,omptempty"` |
| 50 | + MessageLastPost *Time `xmlrpc:"message_last_post,omptempty"` |
| 51 | + MessageNeedaction *Bool `xmlrpc:"message_needaction,omptempty"` |
| 52 | + MessageNeedactionCounter *Int `xmlrpc:"message_needaction_counter,omptempty"` |
| 53 | + MessagePartnerIds *Relation `xmlrpc:"message_partner_ids,omptempty"` |
| 54 | + MessageUnread *Bool `xmlrpc:"message_unread,omptempty"` |
| 55 | + MessageUnreadCounter *Int `xmlrpc:"message_unread_counter,omptempty"` |
| 56 | + Mobile *String `xmlrpc:"mobile,omptempty"` |
| 57 | + Name *String `xmlrpc:"name,omptempty"` |
| 58 | + OptOut *Bool `xmlrpc:"opt_out,omptempty"` |
| 59 | + OrderIds *Relation `xmlrpc:"order_ids,omptempty"` |
| 60 | + PartnerAddressEmail *String `xmlrpc:"partner_address_email,omptempty"` |
| 61 | + PartnerAddressName *String `xmlrpc:"partner_address_name,omptempty"` |
| 62 | + PartnerId *Many2One `xmlrpc:"partner_id,omptempty"` |
| 63 | + PartnerName *String `xmlrpc:"partner_name,omptempty"` |
| 64 | + Phone *String `xmlrpc:"phone,omptempty"` |
| 65 | + PlannedRevenue *Float `xmlrpc:"planned_revenue,omptempty"` |
| 66 | + Priority *Selection `xmlrpc:"priority,omptempty"` |
| 67 | + Probability *Float `xmlrpc:"probability,omptempty"` |
| 68 | + Referred *String `xmlrpc:"referred,omptempty"` |
| 69 | + SaleAmountTotal *Float `xmlrpc:"sale_amount_total,omptempty"` |
| 70 | + SaleNumber *Int `xmlrpc:"sale_number,omptempty"` |
| 71 | + SourceId *Many2One `xmlrpc:"source_id,omptempty"` |
| 72 | + StageId *Many2One `xmlrpc:"stage_id,omptempty"` |
| 73 | + StateId *Many2One `xmlrpc:"state_id,omptempty"` |
| 74 | + Street *String `xmlrpc:"street,omptempty"` |
| 75 | + Street2 *String `xmlrpc:"street2,omptempty"` |
| 76 | + TagIds *Relation `xmlrpc:"tag_ids,omptempty"` |
| 77 | + TeamId *Many2One `xmlrpc:"team_id,omptempty"` |
| 78 | + Title *Many2One `xmlrpc:"title,omptempty"` |
| 79 | + Type *Selection `xmlrpc:"type,omptempty"` |
| 80 | + UserEmail *String `xmlrpc:"user_email,omptempty"` |
| 81 | + UserId *Many2One `xmlrpc:"user_id,omptempty"` |
| 82 | + UserLogin *String `xmlrpc:"user_login,omptempty"` |
| 83 | + Website *String `xmlrpc:"website,omptempty"` |
| 84 | + WebsiteMessageIds *Relation `xmlrpc:"website_message_ids,omptempty"` |
| 85 | + WriteDate *Time `xmlrpc:"write_date,omptempty"` |
| 86 | + WriteUid *Many2One `xmlrpc:"write_uid,omptempty"` |
| 87 | + Zip *String `xmlrpc:"zip,omptempty"` |
| 88 | +} |
| 89 | + |
| 90 | +// CrmLeads represents array of crm.lead model |
| 91 | +type CrmLeads []CrmLead |
| 92 | + |
| 93 | +// CrmLeadModel is the odoo model name |
| 94 | +const CrmLeadModel = "crm.lead" |
| 95 | + |
| 96 | +// Many2One convert CrmLead to *Many2One. |
| 97 | +func (cl *CrmLead) Many2One() *Many2One { |
| 98 | + return NewMany2One(cl.Id.Get(), "") |
| 99 | +} |
| 100 | + |
| 101 | +// CreateCrmLead creates a new crm.lead model and returns its id. |
| 102 | +func (c *Client) CreateCrmLead(cl *CrmLead) (int64, error) { |
| 103 | + return c.Create(CrmLeadModel, cl) |
| 104 | +} |
| 105 | + |
| 106 | +// UpdateCrmLead updates an existing crm.lead record. |
| 107 | +func (c *Client) UpdateCrmLead(cl *CrmLead) error { |
| 108 | + return c.UpdateCrmLeads([]int64{cl.Id.Get()}, cl) |
| 109 | +} |
| 110 | + |
| 111 | +// UpdateCrmLeads updates existing crm.lead records. |
| 112 | +// All records (represented by ids) will be updated by cl values. |
| 113 | +func (c *Client) UpdateCrmLeads(ids []int64, cl *CrmLead) error { |
| 114 | + return c.Update(CrmLeadModel, ids, cl) |
| 115 | +} |
| 116 | + |
| 117 | +// DeleteCrmLead deletes an existing crm.lead record. |
| 118 | +func (c *Client) DeleteCrmLead(id int64) error { |
| 119 | + return c.DeleteCrmLeads([]int64{id}) |
| 120 | +} |
| 121 | + |
| 122 | +// DeleteCrmLeads deletes existing crm.lead records. |
| 123 | +func (c *Client) DeleteCrmLeads(ids []int64) error { |
| 124 | + return c.Delete(CrmLeadModel, ids) |
| 125 | +} |
| 126 | + |
| 127 | +// GetCrmLead gets crm.lead existing record. |
| 128 | +func (c *Client) GetCrmLead(id int64) (*CrmLead, error) { |
| 129 | + cls, err := c.GetCrmLeads([]int64{id}) |
| 130 | + if err != nil { |
| 131 | + return nil, err |
| 132 | + } |
| 133 | + if cls != nil && len(*cls) > 0 { |
| 134 | + return &((*cls)[0]), nil |
| 135 | + } |
| 136 | + return nil, fmt.Errorf("id %v of %s not found", id, CrmLeadModel) |
| 137 | +} |
| 138 | + |
| 139 | +// GetCrmLeads gets crm.lead existing records. |
| 140 | +func (c *Client) GetCrmLeads(ids []int64) (*CrmLeads, error) { |
| 141 | + cls := &CrmLeads{} |
| 142 | + if err := c.Read(CrmLeadModel, ids, nil, cls); err != nil { |
| 143 | + return nil, err |
| 144 | + } |
| 145 | + return cls, nil |
| 146 | +} |
| 147 | + |
| 148 | +// FindCrmLead finds crm.lead record by querying it with criteria |
| 149 | +func (c *Client) FindCrmLead(criteria *Criteria) (*CrmLead, error) { |
| 150 | + cls := &CrmLeads{} |
| 151 | + if err := c.SearchRead(CrmLeadModel, criteria, NewOptions().Limit(1), cls); err != nil { |
| 152 | + return nil, err |
| 153 | + } |
| 154 | + if cls != nil && len(*cls) > 0 { |
| 155 | + return &((*cls)[0]), nil |
| 156 | + } |
| 157 | + return nil, fmt.Errorf("crm.lead was not found") |
| 158 | +} |
| 159 | + |
| 160 | +// FindCrmLeads finds crm.lead records by querying it |
| 161 | +// and filtering it with criteria and options. |
| 162 | +func (c *Client) FindCrmLeads(criteria *Criteria, options *Options) (*CrmLeads, error) { |
| 163 | + cls := &CrmLeads{} |
| 164 | + if err := c.SearchRead(CrmLeadModel, criteria, options, cls); err != nil { |
| 165 | + return nil, err |
| 166 | + } |
| 167 | + return cls, nil |
| 168 | +} |
0 commit comments