Skip to content

Commit

Permalink
added crm.lead and crm.lead.tag models
Browse files Browse the repository at this point in the history
  • Loading branch information
ahuret committed May 6, 2020
1 parent 0404e29 commit 1ada708
Show file tree
Hide file tree
Showing 3 changed files with 267 additions and 0 deletions.
168 changes: 168 additions & 0 deletions crm_lead.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,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
}
98 changes: 98 additions & 0 deletions crm_lead_tag.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
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 %s not found", id, CrmLeadTagModel)
}

// 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("crm.lead.tag was not found")
}

// 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
}
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3Ee
github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4=
github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA=
github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no=
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
Expand Down

0 comments on commit 1ada708

Please sign in to comment.