From bd966f4578f8226c529e9c7111a86cf5b2b834d1 Mon Sep 17 00:00:00 2001 From: Antoine Huret Date: Wed, 20 May 2020 10:35:46 +0200 Subject: [PATCH] added find ids & find id function in templates + regenerated models --- account_account.go | 32 +++++++++++++++++++++++++++----- account_analytic_account.go | 32 +++++++++++++++++++++++++++----- account_analytic_line.go | 32 +++++++++++++++++++++++++++----- account_analytic_tag.go | 32 +++++++++++++++++++++++++++----- account_invoice.go | 32 +++++++++++++++++++++++++++----- account_invoice_line.go | 32 +++++++++++++++++++++++++++----- account_journal.go | 32 +++++++++++++++++++++++++++----- crm_lead.go | 32 +++++++++++++++++++++++++++----- crm_lead_tag.go | 32 +++++++++++++++++++++++++++----- generator/cmd/tmpl/model.tmpl | 32 +++++++++++++++++++++++++++----- go.mod | 1 - go.sum | 28 ---------------------------- product_product.go | 32 +++++++++++++++++++++++++++----- product_supplierinfo.go | 32 +++++++++++++++++++++++++++----- project_project.go | 32 +++++++++++++++++++++++++++----- project_task.go | 32 +++++++++++++++++++++++++++----- res_company.go | 32 +++++++++++++++++++++++++++----- res_partner.go | 32 +++++++++++++++++++++++++++----- res_partner_category.go | 32 +++++++++++++++++++++++++++----- res_users.go | 32 +++++++++++++++++++++++++++----- 20 files changed, 486 insertions(+), 119 deletions(-) diff --git a/account_account.go b/account_account.go index b5604564..41e53537 100644 --- a/account_account.go +++ b/account_account.go @@ -4,7 +4,7 @@ import ( "fmt" ) -// AccountAccount represents account.account model +// AccountAccount represents account.account model. type AccountAccount struct { LastUpdate *Time `xmlrpc:"__last_update,omptempty"` Code *String `xmlrpc:"code,omptempty"` @@ -30,10 +30,10 @@ type AccountAccount struct { WriteUid *Many2One `xmlrpc:"write_uid,omptempty"` } -// AccountAccounts represents array of account.account model +// AccountAccounts represents array of account.account model. type AccountAccounts []AccountAccount -// AccountAccountModel is the odoo model name +// AccountAccountModel is the odoo model name. const AccountAccountModel = "account.account" // Many2One convert AccountAccount to *Many2One. @@ -76,7 +76,7 @@ func (c *Client) GetAccountAccount(id int64) (*AccountAccount, error) { if aas != nil && len(*aas) > 0 { return &((*aas)[0]), nil } - return nil, fmt.Errorf("id %v of %s not found", id, AccountAccountModel) + return nil, fmt.Errorf("id %v of account.account was not found", id) } // GetAccountAccounts gets account.account existing records. @@ -88,7 +88,7 @@ func (c *Client) GetAccountAccounts(ids []int64) (*AccountAccounts, error) { return aas, nil } -// FindAccountAccount finds account.account record by querying it with criteria +// FindAccountAccount finds account.account record by querying it with criteria. func (c *Client) FindAccountAccount(criteria *Criteria) (*AccountAccount, error) { aas := &AccountAccounts{} if err := c.SearchRead(AccountAccountModel, criteria, NewOptions().Limit(1), aas); err != nil { @@ -109,3 +109,25 @@ func (c *Client) FindAccountAccounts(criteria *Criteria, options *Options) (*Acc } return aas, nil } + +// FindAccountAccountIds finds records ids by querying it +// and filtering it with criteria and options. +func (c *Client) FindAccountAccountIds(criteria *Criteria, options *Options) ([]int64, error) { + ids, err := c.Search(AccountAccountModel, criteria, options) + if err != nil { + return []int64{}, err + } + return ids, nil +} + +// FindAccountAccountId finds record id by querying it with criteria. +func (c *Client) FindAccountAccountId(criteria *Criteria) (int64, error) { + ids, err := c.Search(AccountAccountModel, criteria, NewOptions().Limit(1)) + if err != nil { + return -1, err + } + if len(ids) > 0 { + return ids[0], nil + } + return -1, fmt.Errorf("account.account was not found") +} diff --git a/account_analytic_account.go b/account_analytic_account.go index 10e0642a..b56a6255 100644 --- a/account_analytic_account.go +++ b/account_analytic_account.go @@ -4,7 +4,7 @@ import ( "fmt" ) -// AccountAnalyticAccount represents account.analytic.account model +// AccountAnalyticAccount represents account.analytic.account model. type AccountAnalyticAccount struct { LastUpdate *Time `xmlrpc:"__last_update,omptempty"` Active *Bool `xmlrpc:"active,omptempty"` @@ -42,10 +42,10 @@ type AccountAnalyticAccount struct { WriteUid *Many2One `xmlrpc:"write_uid,omptempty"` } -// AccountAnalyticAccounts represents array of account.analytic.account model +// AccountAnalyticAccounts represents array of account.analytic.account model. type AccountAnalyticAccounts []AccountAnalyticAccount -// AccountAnalyticAccountModel is the odoo model name +// AccountAnalyticAccountModel is the odoo model name. const AccountAnalyticAccountModel = "account.analytic.account" // Many2One convert AccountAnalyticAccount to *Many2One. @@ -88,7 +88,7 @@ func (c *Client) GetAccountAnalyticAccount(id int64) (*AccountAnalyticAccount, e if aaas != nil && len(*aaas) > 0 { return &((*aaas)[0]), nil } - return nil, fmt.Errorf("id %v of %s not found", id, AccountAnalyticAccountModel) + return nil, fmt.Errorf("id %v of account.analytic.account was not found", id) } // GetAccountAnalyticAccounts gets account.analytic.account existing records. @@ -100,7 +100,7 @@ func (c *Client) GetAccountAnalyticAccounts(ids []int64) (*AccountAnalyticAccoun return aaas, nil } -// FindAccountAnalyticAccount finds account.analytic.account record by querying it with criteria +// FindAccountAnalyticAccount finds account.analytic.account record by querying it with criteria. func (c *Client) FindAccountAnalyticAccount(criteria *Criteria) (*AccountAnalyticAccount, error) { aaas := &AccountAnalyticAccounts{} if err := c.SearchRead(AccountAnalyticAccountModel, criteria, NewOptions().Limit(1), aaas); err != nil { @@ -121,3 +121,25 @@ func (c *Client) FindAccountAnalyticAccounts(criteria *Criteria, options *Option } return aaas, nil } + +// FindAccountAnalyticAccountIds finds records ids by querying it +// and filtering it with criteria and options. +func (c *Client) FindAccountAnalyticAccountIds(criteria *Criteria, options *Options) ([]int64, error) { + ids, err := c.Search(AccountAnalyticAccountModel, criteria, options) + if err != nil { + return []int64{}, err + } + return ids, nil +} + +// FindAccountAnalyticAccountId finds record id by querying it with criteria. +func (c *Client) FindAccountAnalyticAccountId(criteria *Criteria) (int64, error) { + ids, err := c.Search(AccountAnalyticAccountModel, criteria, NewOptions().Limit(1)) + if err != nil { + return -1, err + } + if len(ids) > 0 { + return ids[0], nil + } + return -1, fmt.Errorf("account.analytic.account was not found") +} diff --git a/account_analytic_line.go b/account_analytic_line.go index 27bb35be..bef756e7 100644 --- a/account_analytic_line.go +++ b/account_analytic_line.go @@ -4,7 +4,7 @@ import ( "fmt" ) -// AccountAnalyticLine represents account.analytic.line model +// AccountAnalyticLine represents account.analytic.line model. type AccountAnalyticLine struct { LastUpdate *Time `xmlrpc:"__last_update,omptempty"` AccountId *Many2One `xmlrpc:"account_id,omptempty"` @@ -43,10 +43,10 @@ type AccountAnalyticLine struct { WriteUid *Many2One `xmlrpc:"write_uid,omptempty"` } -// AccountAnalyticLines represents array of account.analytic.line model +// AccountAnalyticLines represents array of account.analytic.line model. type AccountAnalyticLines []AccountAnalyticLine -// AccountAnalyticLineModel is the odoo model name +// AccountAnalyticLineModel is the odoo model name. const AccountAnalyticLineModel = "account.analytic.line" // Many2One convert AccountAnalyticLine to *Many2One. @@ -89,7 +89,7 @@ func (c *Client) GetAccountAnalyticLine(id int64) (*AccountAnalyticLine, error) if aals != nil && len(*aals) > 0 { return &((*aals)[0]), nil } - return nil, fmt.Errorf("id %v of %s not found", id, AccountAnalyticLineModel) + return nil, fmt.Errorf("id %v of account.analytic.line was not found", id) } // GetAccountAnalyticLines gets account.analytic.line existing records. @@ -101,7 +101,7 @@ func (c *Client) GetAccountAnalyticLines(ids []int64) (*AccountAnalyticLines, er return aals, nil } -// FindAccountAnalyticLine finds account.analytic.line record by querying it with criteria +// FindAccountAnalyticLine finds account.analytic.line record by querying it with criteria. func (c *Client) FindAccountAnalyticLine(criteria *Criteria) (*AccountAnalyticLine, error) { aals := &AccountAnalyticLines{} if err := c.SearchRead(AccountAnalyticLineModel, criteria, NewOptions().Limit(1), aals); err != nil { @@ -122,3 +122,25 @@ func (c *Client) FindAccountAnalyticLines(criteria *Criteria, options *Options) } return aals, nil } + +// FindAccountAnalyticLineIds finds records ids by querying it +// and filtering it with criteria and options. +func (c *Client) FindAccountAnalyticLineIds(criteria *Criteria, options *Options) ([]int64, error) { + ids, err := c.Search(AccountAnalyticLineModel, criteria, options) + if err != nil { + return []int64{}, err + } + return ids, nil +} + +// FindAccountAnalyticLineId finds record id by querying it with criteria. +func (c *Client) FindAccountAnalyticLineId(criteria *Criteria) (int64, error) { + ids, err := c.Search(AccountAnalyticLineModel, criteria, NewOptions().Limit(1)) + if err != nil { + return -1, err + } + if len(ids) > 0 { + return ids[0], nil + } + return -1, fmt.Errorf("account.analytic.line was not found") +} diff --git a/account_analytic_tag.go b/account_analytic_tag.go index 9646499a..d27694b0 100644 --- a/account_analytic_tag.go +++ b/account_analytic_tag.go @@ -4,7 +4,7 @@ import ( "fmt" ) -// AccountAnalyticTag represents account.analytic.tag model +// AccountAnalyticTag represents account.analytic.tag model. type AccountAnalyticTag struct { LastUpdate *Time `xmlrpc:"__last_update,omptempty"` Active *Bool `xmlrpc:"active,omptempty"` @@ -18,10 +18,10 @@ type AccountAnalyticTag struct { WriteUid *Many2One `xmlrpc:"write_uid,omptempty"` } -// AccountAnalyticTags represents array of account.analytic.tag model +// AccountAnalyticTags represents array of account.analytic.tag model. type AccountAnalyticTags []AccountAnalyticTag -// AccountAnalyticTagModel is the odoo model name +// AccountAnalyticTagModel is the odoo model name. const AccountAnalyticTagModel = "account.analytic.tag" // Many2One convert AccountAnalyticTag to *Many2One. @@ -64,7 +64,7 @@ func (c *Client) GetAccountAnalyticTag(id int64) (*AccountAnalyticTag, error) { if aats != nil && len(*aats) > 0 { return &((*aats)[0]), nil } - return nil, fmt.Errorf("id %v of %s not found", id, AccountAnalyticTagModel) + return nil, fmt.Errorf("id %v of account.analytic.tag was not found", id) } // GetAccountAnalyticTags gets account.analytic.tag existing records. @@ -76,7 +76,7 @@ func (c *Client) GetAccountAnalyticTags(ids []int64) (*AccountAnalyticTags, erro return aats, nil } -// FindAccountAnalyticTag finds account.analytic.tag record by querying it with criteria +// FindAccountAnalyticTag finds account.analytic.tag record by querying it with criteria. func (c *Client) FindAccountAnalyticTag(criteria *Criteria) (*AccountAnalyticTag, error) { aats := &AccountAnalyticTags{} if err := c.SearchRead(AccountAnalyticTagModel, criteria, NewOptions().Limit(1), aats); err != nil { @@ -97,3 +97,25 @@ func (c *Client) FindAccountAnalyticTags(criteria *Criteria, options *Options) ( } return aats, nil } + +// FindAccountAnalyticTagIds finds records ids by querying it +// and filtering it with criteria and options. +func (c *Client) FindAccountAnalyticTagIds(criteria *Criteria, options *Options) ([]int64, error) { + ids, err := c.Search(AccountAnalyticTagModel, criteria, options) + if err != nil { + return []int64{}, err + } + return ids, nil +} + +// FindAccountAnalyticTagId finds record id by querying it with criteria. +func (c *Client) FindAccountAnalyticTagId(criteria *Criteria) (int64, error) { + ids, err := c.Search(AccountAnalyticTagModel, criteria, NewOptions().Limit(1)) + if err != nil { + return -1, err + } + if len(ids) > 0 { + return ids[0], nil + } + return -1, fmt.Errorf("account.analytic.tag was not found") +} diff --git a/account_invoice.go b/account_invoice.go index ec39d006..ffe47327 100644 --- a/account_invoice.go +++ b/account_invoice.go @@ -4,7 +4,7 @@ import ( "fmt" ) -// AccountInvoice represents account.invoice model +// AccountInvoice represents account.invoice model. type AccountInvoice struct { LastUpdate *Time `xmlrpc:"__last_update,omptempty"` AccessToken *String `xmlrpc:"access_token,omptempty"` @@ -96,10 +96,10 @@ type AccountInvoice struct { WriteUid *Many2One `xmlrpc:"write_uid,omptempty"` } -// AccountInvoices represents array of account.invoice model +// AccountInvoices represents array of account.invoice model. type AccountInvoices []AccountInvoice -// AccountInvoiceModel is the odoo model name +// AccountInvoiceModel is the odoo model name. const AccountInvoiceModel = "account.invoice" // Many2One convert AccountInvoice to *Many2One. @@ -142,7 +142,7 @@ func (c *Client) GetAccountInvoice(id int64) (*AccountInvoice, error) { if ais != nil && len(*ais) > 0 { return &((*ais)[0]), nil } - return nil, fmt.Errorf("id %v of %s not found", id, AccountInvoiceModel) + return nil, fmt.Errorf("id %v of account.invoice was not found", id) } // GetAccountInvoices gets account.invoice existing records. @@ -154,7 +154,7 @@ func (c *Client) GetAccountInvoices(ids []int64) (*AccountInvoices, error) { return ais, nil } -// FindAccountInvoice finds account.invoice record by querying it with criteria +// FindAccountInvoice finds account.invoice record by querying it with criteria. func (c *Client) FindAccountInvoice(criteria *Criteria) (*AccountInvoice, error) { ais := &AccountInvoices{} if err := c.SearchRead(AccountInvoiceModel, criteria, NewOptions().Limit(1), ais); err != nil { @@ -175,3 +175,25 @@ func (c *Client) FindAccountInvoices(criteria *Criteria, options *Options) (*Acc } return ais, nil } + +// FindAccountInvoiceIds finds records ids by querying it +// and filtering it with criteria and options. +func (c *Client) FindAccountInvoiceIds(criteria *Criteria, options *Options) ([]int64, error) { + ids, err := c.Search(AccountInvoiceModel, criteria, options) + if err != nil { + return []int64{}, err + } + return ids, nil +} + +// FindAccountInvoiceId finds record id by querying it with criteria. +func (c *Client) FindAccountInvoiceId(criteria *Criteria) (int64, error) { + ids, err := c.Search(AccountInvoiceModel, criteria, NewOptions().Limit(1)) + if err != nil { + return -1, err + } + if len(ids) > 0 { + return ids[0], nil + } + return -1, fmt.Errorf("account.invoice was not found") +} diff --git a/account_invoice_line.go b/account_invoice_line.go index 00f030f8..74a83a5c 100644 --- a/account_invoice_line.go +++ b/account_invoice_line.go @@ -4,7 +4,7 @@ import ( "fmt" ) -// AccountInvoiceLine represents account.invoice.line model +// AccountInvoiceLine represents account.invoice.line model. type AccountInvoiceLine struct { LastUpdate *Time `xmlrpc:"__last_update,omptempty"` AccountAnalyticId *Many2One `xmlrpc:"account_analytic_id,omptempty"` @@ -42,10 +42,10 @@ type AccountInvoiceLine struct { WriteUid *Many2One `xmlrpc:"write_uid,omptempty"` } -// AccountInvoiceLines represents array of account.invoice.line model +// AccountInvoiceLines represents array of account.invoice.line model. type AccountInvoiceLines []AccountInvoiceLine -// AccountInvoiceLineModel is the odoo model name +// AccountInvoiceLineModel is the odoo model name. const AccountInvoiceLineModel = "account.invoice.line" // Many2One convert AccountInvoiceLine to *Many2One. @@ -88,7 +88,7 @@ func (c *Client) GetAccountInvoiceLine(id int64) (*AccountInvoiceLine, error) { if ails != nil && len(*ails) > 0 { return &((*ails)[0]), nil } - return nil, fmt.Errorf("id %v of %s not found", id, AccountInvoiceLineModel) + return nil, fmt.Errorf("id %v of account.invoice.line was not found", id) } // GetAccountInvoiceLines gets account.invoice.line existing records. @@ -100,7 +100,7 @@ func (c *Client) GetAccountInvoiceLines(ids []int64) (*AccountInvoiceLines, erro return ails, nil } -// FindAccountInvoiceLine finds account.invoice.line record by querying it with criteria +// FindAccountInvoiceLine finds account.invoice.line record by querying it with criteria. func (c *Client) FindAccountInvoiceLine(criteria *Criteria) (*AccountInvoiceLine, error) { ails := &AccountInvoiceLines{} if err := c.SearchRead(AccountInvoiceLineModel, criteria, NewOptions().Limit(1), ails); err != nil { @@ -121,3 +121,25 @@ func (c *Client) FindAccountInvoiceLines(criteria *Criteria, options *Options) ( } return ails, nil } + +// FindAccountInvoiceLineIds finds records ids by querying it +// and filtering it with criteria and options. +func (c *Client) FindAccountInvoiceLineIds(criteria *Criteria, options *Options) ([]int64, error) { + ids, err := c.Search(AccountInvoiceLineModel, criteria, options) + if err != nil { + return []int64{}, err + } + return ids, nil +} + +// FindAccountInvoiceLineId finds record id by querying it with criteria. +func (c *Client) FindAccountInvoiceLineId(criteria *Criteria) (int64, error) { + ids, err := c.Search(AccountInvoiceLineModel, criteria, NewOptions().Limit(1)) + if err != nil { + return -1, err + } + if len(ids) > 0 { + return ids[0], nil + } + return -1, fmt.Errorf("account.invoice.line was not found") +} diff --git a/account_journal.go b/account_journal.go index 9e3e41fc..5346ac7e 100644 --- a/account_journal.go +++ b/account_journal.go @@ -4,7 +4,7 @@ import ( "fmt" ) -// AccountJournal represents account.journal model +// AccountJournal represents account.journal model. type AccountJournal struct { LastUpdate *Time `xmlrpc:"__last_update,omptempty"` AccountControlIds *Relation `xmlrpc:"account_control_ids,omptempty"` @@ -49,10 +49,10 @@ type AccountJournal struct { WriteUid *Many2One `xmlrpc:"write_uid,omptempty"` } -// AccountJournals represents array of account.journal model +// AccountJournals represents array of account.journal model. type AccountJournals []AccountJournal -// AccountJournalModel is the odoo model name +// AccountJournalModel is the odoo model name. const AccountJournalModel = "account.journal" // Many2One convert AccountJournal to *Many2One. @@ -95,7 +95,7 @@ func (c *Client) GetAccountJournal(id int64) (*AccountJournal, error) { if ajs != nil && len(*ajs) > 0 { return &((*ajs)[0]), nil } - return nil, fmt.Errorf("id %v of %s not found", id, AccountJournalModel) + return nil, fmt.Errorf("id %v of account.journal was not found", id) } // GetAccountJournals gets account.journal existing records. @@ -107,7 +107,7 @@ func (c *Client) GetAccountJournals(ids []int64) (*AccountJournals, error) { return ajs, nil } -// FindAccountJournal finds account.journal record by querying it with criteria +// FindAccountJournal finds account.journal record by querying it with criteria. func (c *Client) FindAccountJournal(criteria *Criteria) (*AccountJournal, error) { ajs := &AccountJournals{} if err := c.SearchRead(AccountJournalModel, criteria, NewOptions().Limit(1), ajs); err != nil { @@ -128,3 +128,25 @@ func (c *Client) FindAccountJournals(criteria *Criteria, options *Options) (*Acc } return ajs, nil } + +// FindAccountJournalIds finds records ids by querying it +// and filtering it with criteria and options. +func (c *Client) FindAccountJournalIds(criteria *Criteria, options *Options) ([]int64, error) { + ids, err := c.Search(AccountJournalModel, criteria, options) + if err != nil { + return []int64{}, err + } + return ids, nil +} + +// FindAccountJournalId finds record id by querying it with criteria. +func (c *Client) FindAccountJournalId(criteria *Criteria) (int64, error) { + ids, err := c.Search(AccountJournalModel, criteria, NewOptions().Limit(1)) + if err != nil { + return -1, err + } + if len(ids) > 0 { + return ids[0], nil + } + return -1, fmt.Errorf("account.journal was not found") +} diff --git a/crm_lead.go b/crm_lead.go index 68d31ca2..4bf808f4 100644 --- a/crm_lead.go +++ b/crm_lead.go @@ -4,7 +4,7 @@ import ( "fmt" ) -// CrmLead represents crm.lead model +// CrmLead represents crm.lead model. type CrmLead struct { LastUpdate *Time `xmlrpc:"__last_update,omptempty"` Active *Bool `xmlrpc:"active,omptempty"` @@ -87,10 +87,10 @@ type CrmLead struct { Zip *String `xmlrpc:"zip,omptempty"` } -// CrmLeads represents array of crm.lead model +// CrmLeads represents array of crm.lead model. type CrmLeads []CrmLead -// CrmLeadModel is the odoo model name +// CrmLeadModel is the odoo model name. const CrmLeadModel = "crm.lead" // Many2One convert CrmLead to *Many2One. @@ -133,7 +133,7 @@ func (c *Client) GetCrmLead(id int64) (*CrmLead, error) { if cls != nil && len(*cls) > 0 { return &((*cls)[0]), nil } - return nil, fmt.Errorf("id %v of %s not found", id, CrmLeadModel) + return nil, fmt.Errorf("id %v of crm.lead was not found", id) } // GetCrmLeads gets crm.lead existing records. @@ -145,7 +145,7 @@ func (c *Client) GetCrmLeads(ids []int64) (*CrmLeads, error) { return cls, nil } -// FindCrmLead finds crm.lead record by querying it with criteria +// 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 { @@ -166,3 +166,25 @@ func (c *Client) FindCrmLeads(criteria *Criteria, options *Options) (*CrmLeads, } return cls, nil } + +// FindCrmLeadIds finds records ids by querying it +// and filtering it with criteria and options. +func (c *Client) FindCrmLeadIds(criteria *Criteria, options *Options) ([]int64, error) { + ids, err := c.Search(CrmLeadModel, criteria, options) + if err != nil { + return []int64{}, err + } + return ids, nil +} + +// FindCrmLeadId finds record id by querying it with criteria. +func (c *Client) FindCrmLeadId(criteria *Criteria) (int64, error) { + ids, err := c.Search(CrmLeadModel, criteria, NewOptions().Limit(1)) + if err != nil { + return -1, err + } + if len(ids) > 0 { + return ids[0], nil + } + return -1, fmt.Errorf("crm.lead was not found") +} diff --git a/crm_lead_tag.go b/crm_lead_tag.go index bd5d92ea..b1791c61 100644 --- a/crm_lead_tag.go +++ b/crm_lead_tag.go @@ -4,7 +4,7 @@ import ( "fmt" ) -// CrmLeadTag represents crm.lead.tag model +// CrmLeadTag represents crm.lead.tag model. type CrmLeadTag struct { LastUpdate *Time `xmlrpc:"__last_update,omptempty"` Color *Int `xmlrpc:"color,omptempty"` @@ -17,10 +17,10 @@ type CrmLeadTag struct { WriteUid *Many2One `xmlrpc:"write_uid,omptempty"` } -// CrmLeadTags represents array of crm.lead.tag model +// CrmLeadTags represents array of crm.lead.tag model. type CrmLeadTags []CrmLeadTag -// CrmLeadTagModel is the odoo model name +// CrmLeadTagModel is the odoo model name. const CrmLeadTagModel = "crm.lead.tag" // Many2One convert CrmLeadTag to *Many2One. @@ -63,7 +63,7 @@ func (c *Client) GetCrmLeadTag(id int64) (*CrmLeadTag, error) { if clts != nil && len(*clts) > 0 { return &((*clts)[0]), nil } - return nil, fmt.Errorf("id %v of %s not found", id, CrmLeadTagModel) + return nil, fmt.Errorf("id %v of crm.lead.tag was not found", id) } // GetCrmLeadTags gets crm.lead.tag existing records. @@ -75,7 +75,7 @@ func (c *Client) GetCrmLeadTags(ids []int64) (*CrmLeadTags, error) { return clts, nil } -// FindCrmLeadTag finds crm.lead.tag record by querying it with criteria +// 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 { @@ -96,3 +96,25 @@ func (c *Client) FindCrmLeadTags(criteria *Criteria, options *Options) (*CrmLead } 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) (int64, error) { + ids, err := c.Search(CrmLeadTagModel, criteria, NewOptions().Limit(1)) + if err != nil { + return -1, err + } + if len(ids) > 0 { + return ids[0], nil + } + return -1, fmt.Errorf("crm.lead.tag was not found") +} diff --git a/generator/cmd/tmpl/model.tmpl b/generator/cmd/tmpl/model.tmpl index ba64c07b..1cc50e79 100644 --- a/generator/cmd/tmpl/model.tmpl +++ b/generator/cmd/tmpl/model.tmpl @@ -4,15 +4,15 @@ import ( "fmt" ) -// {{.StructName}} represents {{ .Name }} model +// {{.StructName}} represents {{ .Name }} model. type {{.StructName}} struct { {{range .Fields}} {{.VarName}} {{.Type}} `xmlrpc:"{{.Name}},omptempty"`{{end }} } -// {{.StructName}}s represents array of {{ .Name }} model +// {{.StructName}}s represents array of {{ .Name }} model. type {{.StructName}}s []{{.StructName}} -// {{.StructName}}Model is the odoo model name +// {{.StructName}}Model is the odoo model name. const {{.StructName}}Model = "{{ .Name }}" // Many2One convert {{.StructName}} to *Many2One. @@ -55,7 +55,7 @@ func (c *Client) Get{{.StructName}}(id int64) (*{{.StructName}}, error) { if {{.VarsName}} != nil && len(*{{.VarsName}}) > 0 { return &((*{{.VarsName}})[0]), nil } - return nil, fmt.Errorf("id %v of %s not found", id, {{.StructName}}Model) + return nil, fmt.Errorf("id %v of {{ .Name }} was not found", id) } // Get{{.StructName}}s gets {{ .Name }} existing records. @@ -67,7 +67,7 @@ func (c *Client) Get{{.StructName}}s(ids []int64) (*{{.StructName}}s, error) { return {{.VarsName}}, nil } -// Find{{.StructName}} finds {{ .Name }} record by querying it with criteria +// Find{{.StructName}} finds {{ .Name }} record by querying it with criteria. func (c *Client) Find{{.StructName}}(criteria *Criteria) (*{{.StructName}}, error) { {{.VarsName}} := &{{.StructName}}s{} if err := c.SearchRead({{.StructName}}Model, criteria, NewOptions().Limit(1), {{.VarsName}}); err != nil { @@ -88,3 +88,25 @@ func (c *Client) Find{{.StructName}}s(criteria *Criteria, options *Options) (*{{ } return {{.VarsName}}, nil } + +// Find{{.StructName}}Ids finds records ids by querying it +// and filtering it with criteria and options. +func (c *Client) Find{{.StructName}}Ids(criteria *Criteria, options *Options) ([]int64, error) { + ids, err := c.Search({{.StructName}}Model, criteria, options) + if err != nil { + return []int64{}, err + } + return ids, nil +} + +// Find{{.StructName}}Id finds record id by querying it with criteria. +func (c *Client) Find{{.StructName}}Id(criteria *Criteria) (int64, error) { + ids, err := c.Search({{.StructName}}Model, criteria, NewOptions().Limit(1)) + if err != nil { + return -1, err + } + if len(ids) > 0 { + return ids[0], nil + } + return -1, fmt.Errorf("{{ .Name }} was not found") +} diff --git a/go.mod b/go.mod index 1e569138..0e99f0e3 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,6 @@ module github.com/skilld-labs/go-odoo go 1.14 require ( - github.com/ahuret/go-odoo v1.0.0 // indirect github.com/iancoleman/strcase v0.0.0-20191112232945-16388991a334 github.com/kolo/xmlrpc v0.0.0-20200310150728-e0350524596b github.com/spf13/cobra v0.0.7 diff --git a/go.sum b/go.sum index 707d8a42..0af2d3ab 100644 --- a/go.sum +++ b/go.sum @@ -1,10 +1,6 @@ cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU= -github.com/ahuret/go-odoo v1.0.0 h1:k2yR0QSUM/F2RmkXcZ1fIoPLcgFy6qOHk5MrhjMae6A= -github.com/ahuret/go-odoo v1.0.0/go.mod h1:iYp8VIKyh3f/lxINxKXNq391aEJmWoDBOOWKr+UBlsE= -github.com/ahuret/go-odoo v1.0.2 h1:2b1edtr89ocmedZ5FipSsm7xbKeVZSwuJQhZZR5/hFw= -github.com/ahuret/go-odoo v1.0.2/go.mod h1:iYp8VIKyh3f/lxINxKXNq391aEJmWoDBOOWKr+UBlsE= github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8= @@ -88,8 +84,6 @@ github.com/spf13/cobra v0.0.7/go.mod h1:/6GTrnGXV9HjY+aR4k0oJ5tcvakLuG6EuKReYlHN github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo= github.com/spf13/pflag v1.0.3 h1:zPAT6CGy6wXeQ7NtTnaTerfKOsV6V6F8agHXFiazDkg= github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= -github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= -github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= github.com/spf13/viper v1.4.0/go.mod h1:PTJ7Z/lr49W6bUbkmS1V3by4uWynFiR9p7+dSq/yZzE= github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= @@ -97,58 +91,36 @@ github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1 github.com/ugorji/go v1.1.4/go.mod h1:uQMGLiO92mf5W77hV/PUCpI3pbzQx3CRekS0kk+RGrc= github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU= github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q= -github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= go.etcd.io/bbolt v1.3.2/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU= go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0= go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q= golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= -golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3 h1:XQyxROzUlZH+WIQwySDgnISgOivlhjIEwaQaJEJrrN0= golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= -golang.org/x/lint v0.0.0-20200302205851-738671d3881b h1:Wh+f8QHJXR411sJR8/vRBTZ7YapZaRvUcLFFJhusH0k= -golang.org/x/lint v0.0.0-20200302205851-738671d3881b/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY= -golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg= -golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20181220203305-927f97764cc3/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= -golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190522155817-f3200d17e092/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= -golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20181107165924-66b7b1311ac8/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs= -golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= -golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20190311212946-11955173bddd h1:/e+gpKk9r3dJobndpTytxS2gOy6m5uvpg+ISQoEcusQ= golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= -golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.0.0-20200130002326-2f3ba24bd6e7/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= -golang.org/x/tools v0.0.0-20200331202046-9d5940d49312 h1:2PHG+Ia3gK1K2kjxZnSylizb//eyaMG8gDFbOG7wLV8= -golang.org/x/tools v0.0.0-20200331202046-9d5940d49312/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= -golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= diff --git a/product_product.go b/product_product.go index 7313d3f5..1f63ee17 100644 --- a/product_product.go +++ b/product_product.go @@ -4,7 +4,7 @@ import ( "fmt" ) -// ProductProduct represents product.product model +// ProductProduct represents product.product model. type ProductProduct struct { LastUpdate *Time `xmlrpc:"__last_update,omptempty"` Active *Bool `xmlrpc:"active,omptempty"` @@ -126,10 +126,10 @@ type ProductProduct struct { WriteUid *Many2One `xmlrpc:"write_uid,omptempty"` } -// ProductProducts represents array of product.product model +// ProductProducts represents array of product.product model. type ProductProducts []ProductProduct -// ProductProductModel is the odoo model name +// ProductProductModel is the odoo model name. const ProductProductModel = "product.product" // Many2One convert ProductProduct to *Many2One. @@ -172,7 +172,7 @@ func (c *Client) GetProductProduct(id int64) (*ProductProduct, error) { if pps != nil && len(*pps) > 0 { return &((*pps)[0]), nil } - return nil, fmt.Errorf("id %v of %s not found", id, ProductProductModel) + return nil, fmt.Errorf("id %v of product.product was not found", id) } // GetProductProducts gets product.product existing records. @@ -184,7 +184,7 @@ func (c *Client) GetProductProducts(ids []int64) (*ProductProducts, error) { return pps, nil } -// FindProductProduct finds product.product record by querying it with criteria +// FindProductProduct finds product.product record by querying it with criteria. func (c *Client) FindProductProduct(criteria *Criteria) (*ProductProduct, error) { pps := &ProductProducts{} if err := c.SearchRead(ProductProductModel, criteria, NewOptions().Limit(1), pps); err != nil { @@ -205,3 +205,25 @@ func (c *Client) FindProductProducts(criteria *Criteria, options *Options) (*Pro } return pps, nil } + +// FindProductProductIds finds records ids by querying it +// and filtering it with criteria and options. +func (c *Client) FindProductProductIds(criteria *Criteria, options *Options) ([]int64, error) { + ids, err := c.Search(ProductProductModel, criteria, options) + if err != nil { + return []int64{}, err + } + return ids, nil +} + +// FindProductProductId finds record id by querying it with criteria. +func (c *Client) FindProductProductId(criteria *Criteria) (int64, error) { + ids, err := c.Search(ProductProductModel, criteria, NewOptions().Limit(1)) + if err != nil { + return -1, err + } + if len(ids) > 0 { + return ids[0], nil + } + return -1, fmt.Errorf("product.product was not found") +} diff --git a/product_supplierinfo.go b/product_supplierinfo.go index 8663b812..646cd030 100644 --- a/product_supplierinfo.go +++ b/product_supplierinfo.go @@ -4,7 +4,7 @@ import ( "fmt" ) -// ProductSupplierinfo represents product.supplierinfo model +// ProductSupplierinfo represents product.supplierinfo model. type ProductSupplierinfo struct { LastUpdate *Time `xmlrpc:"__last_update,omptempty"` CompanyId *Many2One `xmlrpc:"company_id,omptempty"` @@ -30,10 +30,10 @@ type ProductSupplierinfo struct { WriteUid *Many2One `xmlrpc:"write_uid,omptempty"` } -// ProductSupplierinfos represents array of product.supplierinfo model +// ProductSupplierinfos represents array of product.supplierinfo model. type ProductSupplierinfos []ProductSupplierinfo -// ProductSupplierinfoModel is the odoo model name +// ProductSupplierinfoModel is the odoo model name. const ProductSupplierinfoModel = "product.supplierinfo" // Many2One convert ProductSupplierinfo to *Many2One. @@ -76,7 +76,7 @@ func (c *Client) GetProductSupplierinfo(id int64) (*ProductSupplierinfo, error) if pss != nil && len(*pss) > 0 { return &((*pss)[0]), nil } - return nil, fmt.Errorf("id %v of %s not found", id, ProductSupplierinfoModel) + return nil, fmt.Errorf("id %v of product.supplierinfo was not found", id) } // GetProductSupplierinfos gets product.supplierinfo existing records. @@ -88,7 +88,7 @@ func (c *Client) GetProductSupplierinfos(ids []int64) (*ProductSupplierinfos, er return pss, nil } -// FindProductSupplierinfo finds product.supplierinfo record by querying it with criteria +// FindProductSupplierinfo finds product.supplierinfo record by querying it with criteria. func (c *Client) FindProductSupplierinfo(criteria *Criteria) (*ProductSupplierinfo, error) { pss := &ProductSupplierinfos{} if err := c.SearchRead(ProductSupplierinfoModel, criteria, NewOptions().Limit(1), pss); err != nil { @@ -109,3 +109,25 @@ func (c *Client) FindProductSupplierinfos(criteria *Criteria, options *Options) } return pss, nil } + +// FindProductSupplierinfoIds finds records ids by querying it +// and filtering it with criteria and options. +func (c *Client) FindProductSupplierinfoIds(criteria *Criteria, options *Options) ([]int64, error) { + ids, err := c.Search(ProductSupplierinfoModel, criteria, options) + if err != nil { + return []int64{}, err + } + return ids, nil +} + +// FindProductSupplierinfoId finds record id by querying it with criteria. +func (c *Client) FindProductSupplierinfoId(criteria *Criteria) (int64, error) { + ids, err := c.Search(ProductSupplierinfoModel, criteria, NewOptions().Limit(1)) + if err != nil { + return -1, err + } + if len(ids) > 0 { + return ids[0], nil + } + return -1, fmt.Errorf("product.supplierinfo was not found") +} diff --git a/project_project.go b/project_project.go index 8d1ee86d..9c4707bc 100644 --- a/project_project.go +++ b/project_project.go @@ -4,7 +4,7 @@ import ( "fmt" ) -// ProjectProject represents project.project model +// ProjectProject represents project.project model. type ProjectProject struct { LastUpdate *Time `xmlrpc:"__last_update,omptempty"` Active *Bool `xmlrpc:"active,omptempty"` @@ -73,10 +73,10 @@ type ProjectProject struct { WriteUid *Many2One `xmlrpc:"write_uid,omptempty"` } -// ProjectProjects represents array of project.project model +// ProjectProjects represents array of project.project model. type ProjectProjects []ProjectProject -// ProjectProjectModel is the odoo model name +// ProjectProjectModel is the odoo model name. const ProjectProjectModel = "project.project" // Many2One convert ProjectProject to *Many2One. @@ -119,7 +119,7 @@ func (c *Client) GetProjectProject(id int64) (*ProjectProject, error) { if pps != nil && len(*pps) > 0 { return &((*pps)[0]), nil } - return nil, fmt.Errorf("id %v of %s not found", id, ProjectProjectModel) + return nil, fmt.Errorf("id %v of project.project was not found", id) } // GetProjectProjects gets project.project existing records. @@ -131,7 +131,7 @@ func (c *Client) GetProjectProjects(ids []int64) (*ProjectProjects, error) { return pps, nil } -// FindProjectProject finds project.project record by querying it with criteria +// FindProjectProject finds project.project record by querying it with criteria. func (c *Client) FindProjectProject(criteria *Criteria) (*ProjectProject, error) { pps := &ProjectProjects{} if err := c.SearchRead(ProjectProjectModel, criteria, NewOptions().Limit(1), pps); err != nil { @@ -152,3 +152,25 @@ func (c *Client) FindProjectProjects(criteria *Criteria, options *Options) (*Pro } return pps, nil } + +// FindProjectProjectIds finds records ids by querying it +// and filtering it with criteria and options. +func (c *Client) FindProjectProjectIds(criteria *Criteria, options *Options) ([]int64, error) { + ids, err := c.Search(ProjectProjectModel, criteria, options) + if err != nil { + return []int64{}, err + } + return ids, nil +} + +// FindProjectProjectId finds record id by querying it with criteria. +func (c *Client) FindProjectProjectId(criteria *Criteria) (int64, error) { + ids, err := c.Search(ProjectProjectModel, criteria, NewOptions().Limit(1)) + if err != nil { + return -1, err + } + if len(ids) > 0 { + return ids[0], nil + } + return -1, fmt.Errorf("project.project was not found") +} diff --git a/project_task.go b/project_task.go index 79ca10e6..926d1da7 100644 --- a/project_task.go +++ b/project_task.go @@ -4,7 +4,7 @@ import ( "fmt" ) -// ProjectTask represents project.task model +// ProjectTask represents project.task model. type ProjectTask struct { LastUpdate *Time `xmlrpc:"__last_update,omptempty"` Active *Bool `xmlrpc:"active,omptempty"` @@ -80,10 +80,10 @@ type ProjectTask struct { WriteUid *Many2One `xmlrpc:"write_uid,omptempty"` } -// ProjectTasks represents array of project.task model +// ProjectTasks represents array of project.task model. type ProjectTasks []ProjectTask -// ProjectTaskModel is the odoo model name +// ProjectTaskModel is the odoo model name. const ProjectTaskModel = "project.task" // Many2One convert ProjectTask to *Many2One. @@ -126,7 +126,7 @@ func (c *Client) GetProjectTask(id int64) (*ProjectTask, error) { if pts != nil && len(*pts) > 0 { return &((*pts)[0]), nil } - return nil, fmt.Errorf("id %v of %s not found", id, ProjectTaskModel) + return nil, fmt.Errorf("id %v of project.task was not found", id) } // GetProjectTasks gets project.task existing records. @@ -138,7 +138,7 @@ func (c *Client) GetProjectTasks(ids []int64) (*ProjectTasks, error) { return pts, nil } -// FindProjectTask finds project.task record by querying it with criteria +// FindProjectTask finds project.task record by querying it with criteria. func (c *Client) FindProjectTask(criteria *Criteria) (*ProjectTask, error) { pts := &ProjectTasks{} if err := c.SearchRead(ProjectTaskModel, criteria, NewOptions().Limit(1), pts); err != nil { @@ -159,3 +159,25 @@ func (c *Client) FindProjectTasks(criteria *Criteria, options *Options) (*Projec } return pts, nil } + +// FindProjectTaskIds finds records ids by querying it +// and filtering it with criteria and options. +func (c *Client) FindProjectTaskIds(criteria *Criteria, options *Options) ([]int64, error) { + ids, err := c.Search(ProjectTaskModel, criteria, options) + if err != nil { + return []int64{}, err + } + return ids, nil +} + +// FindProjectTaskId finds record id by querying it with criteria. +func (c *Client) FindProjectTaskId(criteria *Criteria) (int64, error) { + ids, err := c.Search(ProjectTaskModel, criteria, NewOptions().Limit(1)) + if err != nil { + return -1, err + } + if len(ids) > 0 { + return ids[0], nil + } + return -1, fmt.Errorf("project.task was not found") +} diff --git a/res_company.go b/res_company.go index 625f95e9..c59352e5 100644 --- a/res_company.go +++ b/res_company.go @@ -4,7 +4,7 @@ import ( "fmt" ) -// ResCompany represents res.company model +// ResCompany represents res.company model. type ResCompany struct { LastUpdate *Time `xmlrpc:"__last_update,omptempty"` AccountInInvoiceNote *String `xmlrpc:"account_in_invoice_note,omptempty"` @@ -95,10 +95,10 @@ type ResCompany struct { Zip *String `xmlrpc:"zip,omptempty"` } -// ResCompanys represents array of res.company model +// ResCompanys represents array of res.company model. type ResCompanys []ResCompany -// ResCompanyModel is the odoo model name +// ResCompanyModel is the odoo model name. const ResCompanyModel = "res.company" // Many2One convert ResCompany to *Many2One. @@ -141,7 +141,7 @@ func (c *Client) GetResCompany(id int64) (*ResCompany, error) { if rcs != nil && len(*rcs) > 0 { return &((*rcs)[0]), nil } - return nil, fmt.Errorf("id %v of %s not found", id, ResCompanyModel) + return nil, fmt.Errorf("id %v of res.company was not found", id) } // GetResCompanys gets res.company existing records. @@ -153,7 +153,7 @@ func (c *Client) GetResCompanys(ids []int64) (*ResCompanys, error) { return rcs, nil } -// FindResCompany finds res.company record by querying it with criteria +// FindResCompany finds res.company record by querying it with criteria. func (c *Client) FindResCompany(criteria *Criteria) (*ResCompany, error) { rcs := &ResCompanys{} if err := c.SearchRead(ResCompanyModel, criteria, NewOptions().Limit(1), rcs); err != nil { @@ -174,3 +174,25 @@ func (c *Client) FindResCompanys(criteria *Criteria, options *Options) (*ResComp } return rcs, nil } + +// FindResCompanyIds finds records ids by querying it +// and filtering it with criteria and options. +func (c *Client) FindResCompanyIds(criteria *Criteria, options *Options) ([]int64, error) { + ids, err := c.Search(ResCompanyModel, criteria, options) + if err != nil { + return []int64{}, err + } + return ids, nil +} + +// FindResCompanyId finds record id by querying it with criteria. +func (c *Client) FindResCompanyId(criteria *Criteria) (int64, error) { + ids, err := c.Search(ResCompanyModel, criteria, NewOptions().Limit(1)) + if err != nil { + return -1, err + } + if len(ids) > 0 { + return ids[0], nil + } + return -1, fmt.Errorf("res.company was not found") +} diff --git a/res_partner.go b/res_partner.go index 8bb567be..3f35339f 100644 --- a/res_partner.go +++ b/res_partner.go @@ -4,7 +4,7 @@ import ( "fmt" ) -// ResPartner represents res.partner model +// ResPartner represents res.partner model. type ResPartner struct { LastUpdate *Time `xmlrpc:"__last_update,omptempty"` Active *Bool `xmlrpc:"active,omptempty"` @@ -139,10 +139,10 @@ type ResPartner struct { Zip *String `xmlrpc:"zip,omptempty"` } -// ResPartners represents array of res.partner model +// ResPartners represents array of res.partner model. type ResPartners []ResPartner -// ResPartnerModel is the odoo model name +// ResPartnerModel is the odoo model name. const ResPartnerModel = "res.partner" // Many2One convert ResPartner to *Many2One. @@ -185,7 +185,7 @@ func (c *Client) GetResPartner(id int64) (*ResPartner, error) { if rps != nil && len(*rps) > 0 { return &((*rps)[0]), nil } - return nil, fmt.Errorf("id %v of %s not found", id, ResPartnerModel) + return nil, fmt.Errorf("id %v of res.partner was not found", id) } // GetResPartners gets res.partner existing records. @@ -197,7 +197,7 @@ func (c *Client) GetResPartners(ids []int64) (*ResPartners, error) { return rps, nil } -// FindResPartner finds res.partner record by querying it with criteria +// FindResPartner finds res.partner record by querying it with criteria. func (c *Client) FindResPartner(criteria *Criteria) (*ResPartner, error) { rps := &ResPartners{} if err := c.SearchRead(ResPartnerModel, criteria, NewOptions().Limit(1), rps); err != nil { @@ -218,3 +218,25 @@ func (c *Client) FindResPartners(criteria *Criteria, options *Options) (*ResPart } return rps, nil } + +// FindResPartnerIds finds records ids by querying it +// and filtering it with criteria and options. +func (c *Client) FindResPartnerIds(criteria *Criteria, options *Options) ([]int64, error) { + ids, err := c.Search(ResPartnerModel, criteria, options) + if err != nil { + return []int64{}, err + } + return ids, nil +} + +// FindResPartnerId finds record id by querying it with criteria. +func (c *Client) FindResPartnerId(criteria *Criteria) (int64, error) { + ids, err := c.Search(ResPartnerModel, criteria, NewOptions().Limit(1)) + if err != nil { + return -1, err + } + if len(ids) > 0 { + return ids[0], nil + } + return -1, fmt.Errorf("res.partner was not found") +} diff --git a/res_partner_category.go b/res_partner_category.go index 7f2c345f..6476a3c5 100644 --- a/res_partner_category.go +++ b/res_partner_category.go @@ -4,7 +4,7 @@ import ( "fmt" ) -// ResPartnerCategory represents res.partner.category model +// ResPartnerCategory represents res.partner.category model. type ResPartnerCategory struct { LastUpdate *Time `xmlrpc:"__last_update,omptempty"` Active *Bool `xmlrpc:"active,omptempty"` @@ -23,10 +23,10 @@ type ResPartnerCategory struct { WriteUid *Many2One `xmlrpc:"write_uid,omptempty"` } -// ResPartnerCategorys represents array of res.partner.category model +// ResPartnerCategorys represents array of res.partner.category model. type ResPartnerCategorys []ResPartnerCategory -// ResPartnerCategoryModel is the odoo model name +// ResPartnerCategoryModel is the odoo model name. const ResPartnerCategoryModel = "res.partner.category" // Many2One convert ResPartnerCategory to *Many2One. @@ -69,7 +69,7 @@ func (c *Client) GetResPartnerCategory(id int64) (*ResPartnerCategory, error) { if rpcs != nil && len(*rpcs) > 0 { return &((*rpcs)[0]), nil } - return nil, fmt.Errorf("id %v of %s not found", id, ResPartnerCategoryModel) + return nil, fmt.Errorf("id %v of res.partner.category was not found", id) } // GetResPartnerCategorys gets res.partner.category existing records. @@ -81,7 +81,7 @@ func (c *Client) GetResPartnerCategorys(ids []int64) (*ResPartnerCategorys, erro return rpcs, nil } -// FindResPartnerCategory finds res.partner.category record by querying it with criteria +// FindResPartnerCategory finds res.partner.category record by querying it with criteria. func (c *Client) FindResPartnerCategory(criteria *Criteria) (*ResPartnerCategory, error) { rpcs := &ResPartnerCategorys{} if err := c.SearchRead(ResPartnerCategoryModel, criteria, NewOptions().Limit(1), rpcs); err != nil { @@ -102,3 +102,25 @@ func (c *Client) FindResPartnerCategorys(criteria *Criteria, options *Options) ( } return rpcs, nil } + +// FindResPartnerCategoryIds finds records ids by querying it +// and filtering it with criteria and options. +func (c *Client) FindResPartnerCategoryIds(criteria *Criteria, options *Options) ([]int64, error) { + ids, err := c.Search(ResPartnerCategoryModel, criteria, options) + if err != nil { + return []int64{}, err + } + return ids, nil +} + +// FindResPartnerCategoryId finds record id by querying it with criteria. +func (c *Client) FindResPartnerCategoryId(criteria *Criteria) (int64, error) { + ids, err := c.Search(ResPartnerCategoryModel, criteria, NewOptions().Limit(1)) + if err != nil { + return -1, err + } + if len(ids) > 0 { + return ids[0], nil + } + return -1, fmt.Errorf("res.partner.category was not found") +} diff --git a/res_users.go b/res_users.go index d5ade617..2977e7d5 100644 --- a/res_users.go +++ b/res_users.go @@ -4,7 +4,7 @@ import ( "fmt" ) -// ResUsers represents res.users model +// ResUsers represents res.users model. type ResUsers struct { LastUpdate *Time `xmlrpc:"__last_update,omptempty"` ActionId *Many2One `xmlrpc:"action_id,omptempty"` @@ -165,10 +165,10 @@ type ResUsers struct { Zip *String `xmlrpc:"zip,omptempty"` } -// ResUserss represents array of res.users model +// ResUserss represents array of res.users model. type ResUserss []ResUsers -// ResUsersModel is the odoo model name +// ResUsersModel is the odoo model name. const ResUsersModel = "res.users" // Many2One convert ResUsers to *Many2One. @@ -211,7 +211,7 @@ func (c *Client) GetResUsers(id int64) (*ResUsers, error) { if rus != nil && len(*rus) > 0 { return &((*rus)[0]), nil } - return nil, fmt.Errorf("id %v of %s not found", id, ResUsersModel) + return nil, fmt.Errorf("id %v of res.users was not found", id) } // GetResUserss gets res.users existing records. @@ -223,7 +223,7 @@ func (c *Client) GetResUserss(ids []int64) (*ResUserss, error) { return rus, nil } -// FindResUsers finds res.users record by querying it with criteria +// FindResUsers finds res.users record by querying it with criteria. func (c *Client) FindResUsers(criteria *Criteria) (*ResUsers, error) { rus := &ResUserss{} if err := c.SearchRead(ResUsersModel, criteria, NewOptions().Limit(1), rus); err != nil { @@ -244,3 +244,25 @@ func (c *Client) FindResUserss(criteria *Criteria, options *Options) (*ResUserss } return rus, nil } + +// FindResUsersIds finds records ids by querying it +// and filtering it with criteria and options. +func (c *Client) FindResUsersIds(criteria *Criteria, options *Options) ([]int64, error) { + ids, err := c.Search(ResUsersModel, criteria, options) + if err != nil { + return []int64{}, err + } + return ids, nil +} + +// FindResUsersId finds record id by querying it with criteria. +func (c *Client) FindResUsersId(criteria *Criteria) (int64, error) { + ids, err := c.Search(ResUsersModel, criteria, NewOptions().Limit(1)) + if err != nil { + return -1, err + } + if len(ids) > 0 { + return ids[0], nil + } + return -1, fmt.Errorf("res.users was not found") +}