Skip to content

Commit

Permalink
Fix missed error return in getAllModelsName(). Ignore models without …
Browse files Browse the repository at this point in the history
…ID prop. Fix using 'map' VarName. Allow options on client.Create() (#52)

Co-authored-by: Oleksiy Stepaniuk <ostepaniuk@skilld.fr>
  • Loading branch information
Stolexiy and Oleksiy Stepaniuk authored Feb 26, 2024
1 parent 5d0a229 commit 65da36b
Show file tree
Hide file tree
Showing 361 changed files with 2,233 additions and 8,257 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,8 @@ These functions give you more flexibility but less usability. We recommand you t
Here are available low level functions :

```go
func (c *Client) Create(model string, values []interface{}) ([]int64, error) {} !! Creating multiple instances is only for odoo 12+ versions !!
func (c *Client) Update(model string, ids []int64, values interface{}) error {}
func (c *Client) Create(model string, values []interface{}, options *Options) ([]int64, error) {} !! Creating multiple instances is only for odoo 12+ versions !!
func (c *Client) Update(model string, ids []int64, values interface{}, options *Options) error {}
func (c *Client) Delete(model string, ids []int64) error {}
func (c *Client) SearchRead(model string, criteria *Criteria, options *Options, elem interface{}) error {}
func (c *Client) Read(model string, ids []int64, options *Options, elem interface{}) error {}
Expand Down
29 changes: 6 additions & 23 deletions account_abstract_payment.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
package odoo

import (
"fmt"
)

// AccountAbstractPayment represents account.abstract.payment model.
type AccountAbstractPayment struct {
LastUpdate *Time `xmlrpc:"__last_update,omptempty"`
Expand Down Expand Up @@ -52,7 +48,7 @@ func (c *Client) CreateAccountAbstractPayments(aaps []*AccountAbstractPayment) (
for _, v := range aaps {
vv = append(vv, v)
}
return c.Create(AccountAbstractPaymentModel, vv)
return c.Create(AccountAbstractPaymentModel, vv, nil)
}

// UpdateAccountAbstractPayment updates an existing account.abstract.payment record.
Expand All @@ -63,7 +59,7 @@ func (c *Client) UpdateAccountAbstractPayment(aap *AccountAbstractPayment) error
// UpdateAccountAbstractPayments updates existing account.abstract.payment records.
// All records (represented by ids) will be updated by aap values.
func (c *Client) UpdateAccountAbstractPayments(ids []int64, aap *AccountAbstractPayment) error {
return c.Update(AccountAbstractPaymentModel, ids, aap)
return c.Update(AccountAbstractPaymentModel, ids, aap, nil)
}

// DeleteAccountAbstractPayment deletes an existing account.abstract.payment record.
Expand All @@ -82,10 +78,7 @@ func (c *Client) GetAccountAbstractPayment(id int64) (*AccountAbstractPayment, e
if err != nil {
return nil, err
}
if aaps != nil && len(*aaps) > 0 {
return &((*aaps)[0]), nil
}
return nil, fmt.Errorf("id %v of account.abstract.payment not found", id)
return &((*aaps)[0]), nil
}

// GetAccountAbstractPayments gets account.abstract.payment existing records.
Expand All @@ -103,10 +96,7 @@ func (c *Client) FindAccountAbstractPayment(criteria *Criteria) (*AccountAbstrac
if err := c.SearchRead(AccountAbstractPaymentModel, criteria, NewOptions().Limit(1), aaps); err != nil {
return nil, err
}
if aaps != nil && len(*aaps) > 0 {
return &((*aaps)[0]), nil
}
return nil, fmt.Errorf("account.abstract.payment was not found with criteria %v", criteria)
return &((*aaps)[0]), nil
}

// FindAccountAbstractPayments finds account.abstract.payment records by querying it
Expand All @@ -122,11 +112,7 @@ func (c *Client) FindAccountAbstractPayments(criteria *Criteria, options *Option
// FindAccountAbstractPaymentIds finds records ids by querying it
// and filtering it with criteria and options.
func (c *Client) FindAccountAbstractPaymentIds(criteria *Criteria, options *Options) ([]int64, error) {
ids, err := c.Search(AccountAbstractPaymentModel, criteria, options)
if err != nil {
return []int64{}, err
}
return ids, nil
return c.Search(AccountAbstractPaymentModel, criteria, options)
}

// FindAccountAbstractPaymentId finds record id by querying it with criteria.
Expand All @@ -135,8 +121,5 @@ func (c *Client) FindAccountAbstractPaymentId(criteria *Criteria, options *Optio
if err != nil {
return -1, err
}
if len(ids) > 0 {
return ids[0], nil
}
return -1, fmt.Errorf("account.abstract.payment was not found with criteria %v and options %v", criteria, options)
return ids[0], nil
}
29 changes: 6 additions & 23 deletions account_account.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
package odoo

import (
"fmt"
)

// AccountAccount represents account.account model.
type AccountAccount struct {
LastUpdate *Time `xmlrpc:"__last_update,omptempty"`
Expand Down Expand Up @@ -59,7 +55,7 @@ func (c *Client) CreateAccountAccounts(aas []*AccountAccount) ([]int64, error) {
for _, v := range aas {
vv = append(vv, v)
}
return c.Create(AccountAccountModel, vv)
return c.Create(AccountAccountModel, vv, nil)
}

// UpdateAccountAccount updates an existing account.account record.
Expand All @@ -70,7 +66,7 @@ func (c *Client) UpdateAccountAccount(aa *AccountAccount) error {
// UpdateAccountAccounts updates existing account.account records.
// All records (represented by ids) will be updated by aa values.
func (c *Client) UpdateAccountAccounts(ids []int64, aa *AccountAccount) error {
return c.Update(AccountAccountModel, ids, aa)
return c.Update(AccountAccountModel, ids, aa, nil)
}

// DeleteAccountAccount deletes an existing account.account record.
Expand All @@ -89,10 +85,7 @@ func (c *Client) GetAccountAccount(id int64) (*AccountAccount, error) {
if err != nil {
return nil, err
}
if aas != nil && len(*aas) > 0 {
return &((*aas)[0]), nil
}
return nil, fmt.Errorf("id %v of account.account not found", id)
return &((*aas)[0]), nil
}

// GetAccountAccounts gets account.account existing records.
Expand All @@ -110,10 +103,7 @@ func (c *Client) FindAccountAccount(criteria *Criteria) (*AccountAccount, error)
if err := c.SearchRead(AccountAccountModel, criteria, NewOptions().Limit(1), aas); err != nil {
return nil, err
}
if aas != nil && len(*aas) > 0 {
return &((*aas)[0]), nil
}
return nil, fmt.Errorf("account.account was not found with criteria %v", criteria)
return &((*aas)[0]), nil
}

// FindAccountAccounts finds account.account records by querying it
Expand All @@ -129,11 +119,7 @@ func (c *Client) FindAccountAccounts(criteria *Criteria, options *Options) (*Acc
// 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
return c.Search(AccountAccountModel, criteria, options)
}

// FindAccountAccountId finds record id by querying it with criteria.
Expand All @@ -142,8 +128,5 @@ func (c *Client) FindAccountAccountId(criteria *Criteria, options *Options) (int
if err != nil {
return -1, err
}
if len(ids) > 0 {
return ids[0], nil
}
return -1, fmt.Errorf("account.account was not found with criteria %v and options %v", criteria, options)
return ids[0], nil
}
29 changes: 6 additions & 23 deletions account_account_tag.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
package odoo

import (
"fmt"
)

// AccountAccountTag represents account.account.tag model.
type AccountAccountTag struct {
LastUpdate *Time `xmlrpc:"__last_update,omptempty"`
Expand Down Expand Up @@ -48,7 +44,7 @@ func (c *Client) CreateAccountAccountTags(aats []*AccountAccountTag) ([]int64, e
for _, v := range aats {
vv = append(vv, v)
}
return c.Create(AccountAccountTagModel, vv)
return c.Create(AccountAccountTagModel, vv, nil)
}

// UpdateAccountAccountTag updates an existing account.account.tag record.
Expand All @@ -59,7 +55,7 @@ func (c *Client) UpdateAccountAccountTag(aat *AccountAccountTag) error {
// UpdateAccountAccountTags updates existing account.account.tag records.
// All records (represented by ids) will be updated by aat values.
func (c *Client) UpdateAccountAccountTags(ids []int64, aat *AccountAccountTag) error {
return c.Update(AccountAccountTagModel, ids, aat)
return c.Update(AccountAccountTagModel, ids, aat, nil)
}

// DeleteAccountAccountTag deletes an existing account.account.tag record.
Expand All @@ -78,10 +74,7 @@ func (c *Client) GetAccountAccountTag(id int64) (*AccountAccountTag, error) {
if err != nil {
return nil, err
}
if aats != nil && len(*aats) > 0 {
return &((*aats)[0]), nil
}
return nil, fmt.Errorf("id %v of account.account.tag not found", id)
return &((*aats)[0]), nil
}

// GetAccountAccountTags gets account.account.tag existing records.
Expand All @@ -99,10 +92,7 @@ func (c *Client) FindAccountAccountTag(criteria *Criteria) (*AccountAccountTag,
if err := c.SearchRead(AccountAccountTagModel, criteria, NewOptions().Limit(1), aats); err != nil {
return nil, err
}
if aats != nil && len(*aats) > 0 {
return &((*aats)[0]), nil
}
return nil, fmt.Errorf("account.account.tag was not found with criteria %v", criteria)
return &((*aats)[0]), nil
}

// FindAccountAccountTags finds account.account.tag records by querying it
Expand All @@ -118,11 +108,7 @@ func (c *Client) FindAccountAccountTags(criteria *Criteria, options *Options) (*
// FindAccountAccountTagIds finds records ids by querying it
// and filtering it with criteria and options.
func (c *Client) FindAccountAccountTagIds(criteria *Criteria, options *Options) ([]int64, error) {
ids, err := c.Search(AccountAccountTagModel, criteria, options)
if err != nil {
return []int64{}, err
}
return ids, nil
return c.Search(AccountAccountTagModel, criteria, options)
}

// FindAccountAccountTagId finds record id by querying it with criteria.
Expand All @@ -131,8 +117,5 @@ func (c *Client) FindAccountAccountTagId(criteria *Criteria, options *Options) (
if err != nil {
return -1, err
}
if len(ids) > 0 {
return ids[0], nil
}
return -1, fmt.Errorf("account.account.tag was not found with criteria %v and options %v", criteria, options)
return ids[0], nil
}
29 changes: 6 additions & 23 deletions account_account_template.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
package odoo

import (
"fmt"
)

// AccountAccountTemplate represents account.account.template model.
type AccountAccountTemplate struct {
LastUpdate *Time `xmlrpc:"__last_update,omptempty"`
Expand Down Expand Up @@ -55,7 +51,7 @@ func (c *Client) CreateAccountAccountTemplates(aats []*AccountAccountTemplate) (
for _, v := range aats {
vv = append(vv, v)
}
return c.Create(AccountAccountTemplateModel, vv)
return c.Create(AccountAccountTemplateModel, vv, nil)
}

// UpdateAccountAccountTemplate updates an existing account.account.template record.
Expand All @@ -66,7 +62,7 @@ func (c *Client) UpdateAccountAccountTemplate(aat *AccountAccountTemplate) error
// UpdateAccountAccountTemplates updates existing account.account.template records.
// All records (represented by ids) will be updated by aat values.
func (c *Client) UpdateAccountAccountTemplates(ids []int64, aat *AccountAccountTemplate) error {
return c.Update(AccountAccountTemplateModel, ids, aat)
return c.Update(AccountAccountTemplateModel, ids, aat, nil)
}

// DeleteAccountAccountTemplate deletes an existing account.account.template record.
Expand All @@ -85,10 +81,7 @@ func (c *Client) GetAccountAccountTemplate(id int64) (*AccountAccountTemplate, e
if err != nil {
return nil, err
}
if aats != nil && len(*aats) > 0 {
return &((*aats)[0]), nil
}
return nil, fmt.Errorf("id %v of account.account.template not found", id)
return &((*aats)[0]), nil
}

// GetAccountAccountTemplates gets account.account.template existing records.
Expand All @@ -106,10 +99,7 @@ func (c *Client) FindAccountAccountTemplate(criteria *Criteria) (*AccountAccount
if err := c.SearchRead(AccountAccountTemplateModel, criteria, NewOptions().Limit(1), aats); err != nil {
return nil, err
}
if aats != nil && len(*aats) > 0 {
return &((*aats)[0]), nil
}
return nil, fmt.Errorf("account.account.template was not found with criteria %v", criteria)
return &((*aats)[0]), nil
}

// FindAccountAccountTemplates finds account.account.template records by querying it
Expand All @@ -125,11 +115,7 @@ func (c *Client) FindAccountAccountTemplates(criteria *Criteria, options *Option
// FindAccountAccountTemplateIds finds records ids by querying it
// and filtering it with criteria and options.
func (c *Client) FindAccountAccountTemplateIds(criteria *Criteria, options *Options) ([]int64, error) {
ids, err := c.Search(AccountAccountTemplateModel, criteria, options)
if err != nil {
return []int64{}, err
}
return ids, nil
return c.Search(AccountAccountTemplateModel, criteria, options)
}

// FindAccountAccountTemplateId finds record id by querying it with criteria.
Expand All @@ -138,8 +124,5 @@ func (c *Client) FindAccountAccountTemplateId(criteria *Criteria, options *Optio
if err != nil {
return -1, err
}
if len(ids) > 0 {
return ids[0], nil
}
return -1, fmt.Errorf("account.account.template was not found with criteria %v and options %v", criteria, options)
return ids[0], nil
}
29 changes: 6 additions & 23 deletions account_account_type.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
package odoo

import (
"fmt"
)

// AccountAccountType represents account.account.type model.
type AccountAccountType struct {
LastUpdate *Time `xmlrpc:"__last_update,omptempty"`
Expand Down Expand Up @@ -48,7 +44,7 @@ func (c *Client) CreateAccountAccountTypes(aats []*AccountAccountType) ([]int64,
for _, v := range aats {
vv = append(vv, v)
}
return c.Create(AccountAccountTypeModel, vv)
return c.Create(AccountAccountTypeModel, vv, nil)
}

// UpdateAccountAccountType updates an existing account.account.type record.
Expand All @@ -59,7 +55,7 @@ func (c *Client) UpdateAccountAccountType(aat *AccountAccountType) error {
// UpdateAccountAccountTypes updates existing account.account.type records.
// All records (represented by ids) will be updated by aat values.
func (c *Client) UpdateAccountAccountTypes(ids []int64, aat *AccountAccountType) error {
return c.Update(AccountAccountTypeModel, ids, aat)
return c.Update(AccountAccountTypeModel, ids, aat, nil)
}

// DeleteAccountAccountType deletes an existing account.account.type record.
Expand All @@ -78,10 +74,7 @@ func (c *Client) GetAccountAccountType(id int64) (*AccountAccountType, error) {
if err != nil {
return nil, err
}
if aats != nil && len(*aats) > 0 {
return &((*aats)[0]), nil
}
return nil, fmt.Errorf("id %v of account.account.type not found", id)
return &((*aats)[0]), nil
}

// GetAccountAccountTypes gets account.account.type existing records.
Expand All @@ -99,10 +92,7 @@ func (c *Client) FindAccountAccountType(criteria *Criteria) (*AccountAccountType
if err := c.SearchRead(AccountAccountTypeModel, criteria, NewOptions().Limit(1), aats); err != nil {
return nil, err
}
if aats != nil && len(*aats) > 0 {
return &((*aats)[0]), nil
}
return nil, fmt.Errorf("account.account.type was not found with criteria %v", criteria)
return &((*aats)[0]), nil
}

// FindAccountAccountTypes finds account.account.type records by querying it
Expand All @@ -118,11 +108,7 @@ func (c *Client) FindAccountAccountTypes(criteria *Criteria, options *Options) (
// FindAccountAccountTypeIds finds records ids by querying it
// and filtering it with criteria and options.
func (c *Client) FindAccountAccountTypeIds(criteria *Criteria, options *Options) ([]int64, error) {
ids, err := c.Search(AccountAccountTypeModel, criteria, options)
if err != nil {
return []int64{}, err
}
return ids, nil
return c.Search(AccountAccountTypeModel, criteria, options)
}

// FindAccountAccountTypeId finds record id by querying it with criteria.
Expand All @@ -131,8 +117,5 @@ func (c *Client) FindAccountAccountTypeId(criteria *Criteria, options *Options)
if err != nil {
return -1, err
}
if len(ids) > 0 {
return ids[0], nil
}
return -1, fmt.Errorf("account.account.type was not found with criteria %v and options %v", criteria, options)
return ids[0], nil
}
Loading

0 comments on commit 65da36b

Please sign in to comment.