Skip to content

Commit

Permalink
added templates + recover panics when closing connections
Browse files Browse the repository at this point in the history
  • Loading branch information
ahuret committed Jun 25, 2020
1 parent bd966f4 commit a3b1dd7
Show file tree
Hide file tree
Showing 19 changed files with 62 additions and 56 deletions.
6 changes: 3 additions & 3 deletions account_account.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 account.account was not found", id)
return nil, fmt.Errorf("id %v of account.account not found", id)
}

// GetAccountAccounts gets account.account existing records.
Expand Down Expand Up @@ -121,8 +121,8 @@ func (c *Client) FindAccountAccountIds(criteria *Criteria, options *Options) ([]
}

// 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))
func (c *Client) FindAccountAccountId(criteria *Criteria, options *Options) (int64, error) {
ids, err := c.Search(AccountAccountModel, criteria, options)
if err != nil {
return -1, err
}
Expand Down
6 changes: 3 additions & 3 deletions account_analytic_account.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 account.analytic.account was not found", id)
return nil, fmt.Errorf("id %v of account.analytic.account not found", id)
}

// GetAccountAnalyticAccounts gets account.analytic.account existing records.
Expand Down Expand Up @@ -133,8 +133,8 @@ func (c *Client) FindAccountAnalyticAccountIds(criteria *Criteria, options *Opti
}

// 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))
func (c *Client) FindAccountAnalyticAccountId(criteria *Criteria, options *Options) (int64, error) {
ids, err := c.Search(AccountAnalyticAccountModel, criteria, options)
if err != nil {
return -1, err
}
Expand Down
6 changes: 3 additions & 3 deletions account_analytic_line.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 account.analytic.line was not found", id)
return nil, fmt.Errorf("id %v of account.analytic.line not found", id)
}

// GetAccountAnalyticLines gets account.analytic.line existing records.
Expand Down Expand Up @@ -134,8 +134,8 @@ func (c *Client) FindAccountAnalyticLineIds(criteria *Criteria, options *Options
}

// 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))
func (c *Client) FindAccountAnalyticLineId(criteria *Criteria, options *Options) (int64, error) {
ids, err := c.Search(AccountAnalyticLineModel, criteria, options)
if err != nil {
return -1, err
}
Expand Down
6 changes: 3 additions & 3 deletions account_analytic_tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 account.analytic.tag was not found", id)
return nil, fmt.Errorf("id %v of account.analytic.tag not found", id)
}

// GetAccountAnalyticTags gets account.analytic.tag existing records.
Expand Down Expand Up @@ -109,8 +109,8 @@ func (c *Client) FindAccountAnalyticTagIds(criteria *Criteria, options *Options)
}

// 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))
func (c *Client) FindAccountAnalyticTagId(criteria *Criteria, options *Options) (int64, error) {
ids, err := c.Search(AccountAnalyticTagModel, criteria, options)
if err != nil {
return -1, err
}
Expand Down
6 changes: 3 additions & 3 deletions account_invoice.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 account.invoice was not found", id)
return nil, fmt.Errorf("id %v of account.invoice not found", id)
}

// GetAccountInvoices gets account.invoice existing records.
Expand Down Expand Up @@ -187,8 +187,8 @@ func (c *Client) FindAccountInvoiceIds(criteria *Criteria, options *Options) ([]
}

// 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))
func (c *Client) FindAccountInvoiceId(criteria *Criteria, options *Options) (int64, error) {
ids, err := c.Search(AccountInvoiceModel, criteria, options)
if err != nil {
return -1, err
}
Expand Down
6 changes: 3 additions & 3 deletions account_invoice_line.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 account.invoice.line was not found", id)
return nil, fmt.Errorf("id %v of account.invoice.line not found", id)
}

// GetAccountInvoiceLines gets account.invoice.line existing records.
Expand Down Expand Up @@ -133,8 +133,8 @@ func (c *Client) FindAccountInvoiceLineIds(criteria *Criteria, options *Options)
}

// 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))
func (c *Client) FindAccountInvoiceLineId(criteria *Criteria, options *Options) (int64, error) {
ids, err := c.Search(AccountInvoiceLineModel, criteria, options)
if err != nil {
return -1, err
}
Expand Down
6 changes: 3 additions & 3 deletions account_journal.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 account.journal was not found", id)
return nil, fmt.Errorf("id %v of account.journal not found", id)
}

// GetAccountJournals gets account.journal existing records.
Expand Down Expand Up @@ -140,8 +140,8 @@ func (c *Client) FindAccountJournalIds(criteria *Criteria, options *Options) ([]
}

// 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))
func (c *Client) FindAccountJournalId(criteria *Criteria, options *Options) (int64, error) {
ids, err := c.Search(AccountJournalModel, criteria, options)
if err != nil {
return -1, err
}
Expand Down
6 changes: 3 additions & 3 deletions crm_lead.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 crm.lead was not found", id)
return nil, fmt.Errorf("id %v of crm.lead not found", id)
}

// GetCrmLeads gets crm.lead existing records.
Expand Down Expand Up @@ -178,8 +178,8 @@ func (c *Client) FindCrmLeadIds(criteria *Criteria, options *Options) ([]int64,
}

// 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))
func (c *Client) FindCrmLeadId(criteria *Criteria, options *Options) (int64, error) {
ids, err := c.Search(CrmLeadModel, criteria, options)
if err != nil {
return -1, err
}
Expand Down
6 changes: 3 additions & 3 deletions crm_lead_tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 crm.lead.tag was not found", id)
return nil, fmt.Errorf("id %v of crm.lead.tag not found", id)
}

// GetCrmLeadTags gets crm.lead.tag existing records.
Expand Down Expand Up @@ -108,8 +108,8 @@ func (c *Client) FindCrmLeadTagIds(criteria *Criteria, options *Options) ([]int6
}

// 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))
func (c *Client) FindCrmLeadTagId(criteria *Criteria, options *Options) (int64, error) {
ids, err := c.Search(CrmLeadTagModel, criteria, options)
if err != nil {
return -1, err
}
Expand Down
10 changes: 5 additions & 5 deletions generator/cmd/tmpl/model.tmpl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package odoo
package odoo

import (
"fmt"
Expand Down Expand Up @@ -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 {{ .Name }} was not found", id)
return nil, fmt.Errorf("id %v of {{.Name}} not found", id)
}

// Get{{.StructName}}s gets {{ .Name }} existing records.
Expand All @@ -79,7 +79,7 @@ func (c *Client) Find{{.StructName}}(criteria *Criteria) (*{{.StructName}}, erro
return nil, fmt.Errorf("{{ .Name }} was not found")
}

// Find{{.StructName}}s finds {{ .Name }} records by querying it
// Find{{.StructName}}s finds {{ .Name }} records by querying it
// and filtering it with criteria and options.
func (c *Client) Find{{.StructName}}s(criteria *Criteria, options *Options) (*{{.StructName}}s, error) {
{{.VarsName}} := &{{.StructName}}s{}
Expand All @@ -100,8 +100,8 @@ func (c *Client) Find{{.StructName}}Ids(criteria *Criteria, options *Options) ([
}

// 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))
func (c *Client) Find{{.StructName}}Id(criteria *Criteria, options *Options) (int64, error) {
ids, err := c.Search({{.StructName}}Model, criteria, options)
if err != nil {
return -1, err
}
Expand Down
6 changes: 6 additions & 0 deletions odoo.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package odoo

import (
"errors"
"log"

"github.com/kolo/xmlrpc"
)
Expand Down Expand Up @@ -56,6 +57,11 @@ func NewClient(cfg *ClientConfig) (*Client, error) {

// Close closes all opened client connections.
func (c *Client) Close() {
defer func() {
if r := recover(); r != nil {
log.Print("connections were already closed")
}
}()
if c.common != nil {
c.common.Close()
}
Expand Down
6 changes: 3 additions & 3 deletions product_product.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 product.product was not found", id)
return nil, fmt.Errorf("id %v of product.product not found", id)
}

// GetProductProducts gets product.product existing records.
Expand Down Expand Up @@ -217,8 +217,8 @@ func (c *Client) FindProductProductIds(criteria *Criteria, options *Options) ([]
}

// 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))
func (c *Client) FindProductProductId(criteria *Criteria, options *Options) (int64, error) {
ids, err := c.Search(ProductProductModel, criteria, options)
if err != nil {
return -1, err
}
Expand Down
6 changes: 3 additions & 3 deletions product_supplierinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 product.supplierinfo was not found", id)
return nil, fmt.Errorf("id %v of product.supplierinfo not found", id)
}

// GetProductSupplierinfos gets product.supplierinfo existing records.
Expand Down Expand Up @@ -121,8 +121,8 @@ func (c *Client) FindProductSupplierinfoIds(criteria *Criteria, options *Options
}

// 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))
func (c *Client) FindProductSupplierinfoId(criteria *Criteria, options *Options) (int64, error) {
ids, err := c.Search(ProductSupplierinfoModel, criteria, options)
if err != nil {
return -1, err
}
Expand Down
6 changes: 3 additions & 3 deletions project_project.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 project.project was not found", id)
return nil, fmt.Errorf("id %v of project.project not found", id)
}

// GetProjectProjects gets project.project existing records.
Expand Down Expand Up @@ -164,8 +164,8 @@ func (c *Client) FindProjectProjectIds(criteria *Criteria, options *Options) ([]
}

// 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))
func (c *Client) FindProjectProjectId(criteria *Criteria, options *Options) (int64, error) {
ids, err := c.Search(ProjectProjectModel, criteria, options)
if err != nil {
return -1, err
}
Expand Down
6 changes: 3 additions & 3 deletions project_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 project.task was not found", id)
return nil, fmt.Errorf("id %v of project.task not found", id)
}

// GetProjectTasks gets project.task existing records.
Expand Down Expand Up @@ -171,8 +171,8 @@ func (c *Client) FindProjectTaskIds(criteria *Criteria, options *Options) ([]int
}

// 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))
func (c *Client) FindProjectTaskId(criteria *Criteria, options *Options) (int64, error) {
ids, err := c.Search(ProjectTaskModel, criteria, options)
if err != nil {
return -1, err
}
Expand Down
6 changes: 3 additions & 3 deletions res_company.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 res.company was not found", id)
return nil, fmt.Errorf("id %v of res.company not found", id)
}

// GetResCompanys gets res.company existing records.
Expand Down Expand Up @@ -186,8 +186,8 @@ func (c *Client) FindResCompanyIds(criteria *Criteria, options *Options) ([]int6
}

// 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))
func (c *Client) FindResCompanyId(criteria *Criteria, options *Options) (int64, error) {
ids, err := c.Search(ResCompanyModel, criteria, options)
if err != nil {
return -1, err
}
Expand Down
6 changes: 3 additions & 3 deletions res_partner.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 res.partner was not found", id)
return nil, fmt.Errorf("id %v of res.partner not found", id)
}

// GetResPartners gets res.partner existing records.
Expand Down Expand Up @@ -230,8 +230,8 @@ func (c *Client) FindResPartnerIds(criteria *Criteria, options *Options) ([]int6
}

// 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))
func (c *Client) FindResPartnerId(criteria *Criteria, options *Options) (int64, error) {
ids, err := c.Search(ResPartnerModel, criteria, options)
if err != nil {
return -1, err
}
Expand Down
6 changes: 3 additions & 3 deletions res_partner_category.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 res.partner.category was not found", id)
return nil, fmt.Errorf("id %v of res.partner.category not found", id)
}

// GetResPartnerCategorys gets res.partner.category existing records.
Expand Down Expand Up @@ -114,8 +114,8 @@ func (c *Client) FindResPartnerCategoryIds(criteria *Criteria, options *Options)
}

// 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))
func (c *Client) FindResPartnerCategoryId(criteria *Criteria, options *Options) (int64, error) {
ids, err := c.Search(ResPartnerCategoryModel, criteria, options)
if err != nil {
return -1, err
}
Expand Down
6 changes: 3 additions & 3 deletions res_users.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 res.users was not found", id)
return nil, fmt.Errorf("id %v of res.users not found", id)
}

// GetResUserss gets res.users existing records.
Expand Down Expand Up @@ -256,8 +256,8 @@ func (c *Client) FindResUsersIds(criteria *Criteria, options *Options) ([]int64,
}

// 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))
func (c *Client) FindResUsersId(criteria *Criteria, options *Options) (int64, error) {
ids, err := c.Search(ResUsersModel, criteria, options)
if err != nil {
return -1, err
}
Expand Down

0 comments on commit a3b1dd7

Please sign in to comment.