Skip to content

Commit 65da36b

Browse files
StolexiyOleksiy Stepaniuk
andauthored
Fix missed error return in getAllModelsName(). Ignore models without ID prop. Fix using 'map' VarName. Allow options on client.Create() (#52)
Co-authored-by: Oleksiy Stepaniuk <[email protected]>
1 parent 5d0a229 commit 65da36b

File tree

361 files changed

+2233
-8257
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

361 files changed

+2233
-8257
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,8 @@ These functions give you more flexibility but less usability. We recommand you t
175175
Here are available low level functions :
176176

177177
```go
178-
func (c *Client) Create(model string, values []interface{}) ([]int64, error) {} !! Creating multiple instances is only for odoo 12+ versions !!
179-
func (c *Client) Update(model string, ids []int64, values interface{}) error {}
178+
func (c *Client) Create(model string, values []interface{}, options *Options) ([]int64, error) {} !! Creating multiple instances is only for odoo 12+ versions !!
179+
func (c *Client) Update(model string, ids []int64, values interface{}, options *Options) error {}
180180
func (c *Client) Delete(model string, ids []int64) error {}
181181
func (c *Client) SearchRead(model string, criteria *Criteria, options *Options, elem interface{}) error {}
182182
func (c *Client) Read(model string, ids []int64, options *Options, elem interface{}) error {}

account_abstract_payment.go

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
package odoo
22

3-
import (
4-
"fmt"
5-
)
6-
73
// AccountAbstractPayment represents account.abstract.payment model.
84
type AccountAbstractPayment struct {
95
LastUpdate *Time `xmlrpc:"__last_update,omptempty"`
@@ -52,7 +48,7 @@ func (c *Client) CreateAccountAbstractPayments(aaps []*AccountAbstractPayment) (
5248
for _, v := range aaps {
5349
vv = append(vv, v)
5450
}
55-
return c.Create(AccountAbstractPaymentModel, vv)
51+
return c.Create(AccountAbstractPaymentModel, vv, nil)
5652
}
5753

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

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

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

112102
// FindAccountAbstractPayments finds account.abstract.payment records by querying it
@@ -122,11 +112,7 @@ func (c *Client) FindAccountAbstractPayments(criteria *Criteria, options *Option
122112
// FindAccountAbstractPaymentIds finds records ids by querying it
123113
// and filtering it with criteria and options.
124114
func (c *Client) FindAccountAbstractPaymentIds(criteria *Criteria, options *Options) ([]int64, error) {
125-
ids, err := c.Search(AccountAbstractPaymentModel, criteria, options)
126-
if err != nil {
127-
return []int64{}, err
128-
}
129-
return ids, nil
115+
return c.Search(AccountAbstractPaymentModel, criteria, options)
130116
}
131117

132118
// FindAccountAbstractPaymentId finds record id by querying it with criteria.
@@ -135,8 +121,5 @@ func (c *Client) FindAccountAbstractPaymentId(criteria *Criteria, options *Optio
135121
if err != nil {
136122
return -1, err
137123
}
138-
if len(ids) > 0 {
139-
return ids[0], nil
140-
}
141-
return -1, fmt.Errorf("account.abstract.payment was not found with criteria %v and options %v", criteria, options)
124+
return ids[0], nil
142125
}

account_account.go

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
package odoo
22

3-
import (
4-
"fmt"
5-
)
6-
73
// AccountAccount represents account.account model.
84
type AccountAccount struct {
95
LastUpdate *Time `xmlrpc:"__last_update,omptempty"`
@@ -59,7 +55,7 @@ func (c *Client) CreateAccountAccounts(aas []*AccountAccount) ([]int64, error) {
5955
for _, v := range aas {
6056
vv = append(vv, v)
6157
}
62-
return c.Create(AccountAccountModel, vv)
58+
return c.Create(AccountAccountModel, vv, nil)
6359
}
6460

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

7672
// DeleteAccountAccount deletes an existing account.account record.
@@ -89,10 +85,7 @@ func (c *Client) GetAccountAccount(id int64) (*AccountAccount, error) {
8985
if err != nil {
9086
return nil, err
9187
}
92-
if aas != nil && len(*aas) > 0 {
93-
return &((*aas)[0]), nil
94-
}
95-
return nil, fmt.Errorf("id %v of account.account not found", id)
88+
return &((*aas)[0]), nil
9689
}
9790

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

119109
// FindAccountAccounts finds account.account records by querying it
@@ -129,11 +119,7 @@ func (c *Client) FindAccountAccounts(criteria *Criteria, options *Options) (*Acc
129119
// FindAccountAccountIds finds records ids by querying it
130120
// and filtering it with criteria and options.
131121
func (c *Client) FindAccountAccountIds(criteria *Criteria, options *Options) ([]int64, error) {
132-
ids, err := c.Search(AccountAccountModel, criteria, options)
133-
if err != nil {
134-
return []int64{}, err
135-
}
136-
return ids, nil
122+
return c.Search(AccountAccountModel, criteria, options)
137123
}
138124

139125
// FindAccountAccountId finds record id by querying it with criteria.
@@ -142,8 +128,5 @@ func (c *Client) FindAccountAccountId(criteria *Criteria, options *Options) (int
142128
if err != nil {
143129
return -1, err
144130
}
145-
if len(ids) > 0 {
146-
return ids[0], nil
147-
}
148-
return -1, fmt.Errorf("account.account was not found with criteria %v and options %v", criteria, options)
131+
return ids[0], nil
149132
}

account_account_tag.go

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
package odoo
22

3-
import (
4-
"fmt"
5-
)
6-
73
// AccountAccountTag represents account.account.tag model.
84
type AccountAccountTag struct {
95
LastUpdate *Time `xmlrpc:"__last_update,omptempty"`
@@ -48,7 +44,7 @@ func (c *Client) CreateAccountAccountTags(aats []*AccountAccountTag) ([]int64, e
4844
for _, v := range aats {
4945
vv = append(vv, v)
5046
}
51-
return c.Create(AccountAccountTagModel, vv)
47+
return c.Create(AccountAccountTagModel, vv, nil)
5248
}
5349

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

6561
// DeleteAccountAccountTag deletes an existing account.account.tag record.
@@ -78,10 +74,7 @@ func (c *Client) GetAccountAccountTag(id int64) (*AccountAccountTag, error) {
7874
if err != nil {
7975
return nil, err
8076
}
81-
if aats != nil && len(*aats) > 0 {
82-
return &((*aats)[0]), nil
83-
}
84-
return nil, fmt.Errorf("id %v of account.account.tag not found", id)
77+
return &((*aats)[0]), nil
8578
}
8679

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

10898
// FindAccountAccountTags finds account.account.tag records by querying it
@@ -118,11 +108,7 @@ func (c *Client) FindAccountAccountTags(criteria *Criteria, options *Options) (*
118108
// FindAccountAccountTagIds finds records ids by querying it
119109
// and filtering it with criteria and options.
120110
func (c *Client) FindAccountAccountTagIds(criteria *Criteria, options *Options) ([]int64, error) {
121-
ids, err := c.Search(AccountAccountTagModel, criteria, options)
122-
if err != nil {
123-
return []int64{}, err
124-
}
125-
return ids, nil
111+
return c.Search(AccountAccountTagModel, criteria, options)
126112
}
127113

128114
// FindAccountAccountTagId finds record id by querying it with criteria.
@@ -131,8 +117,5 @@ func (c *Client) FindAccountAccountTagId(criteria *Criteria, options *Options) (
131117
if err != nil {
132118
return -1, err
133119
}
134-
if len(ids) > 0 {
135-
return ids[0], nil
136-
}
137-
return -1, fmt.Errorf("account.account.tag was not found with criteria %v and options %v", criteria, options)
120+
return ids[0], nil
138121
}

account_account_template.go

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
package odoo
22

3-
import (
4-
"fmt"
5-
)
6-
73
// AccountAccountTemplate represents account.account.template model.
84
type AccountAccountTemplate struct {
95
LastUpdate *Time `xmlrpc:"__last_update,omptempty"`
@@ -55,7 +51,7 @@ func (c *Client) CreateAccountAccountTemplates(aats []*AccountAccountTemplate) (
5551
for _, v := range aats {
5652
vv = append(vv, v)
5753
}
58-
return c.Create(AccountAccountTemplateModel, vv)
54+
return c.Create(AccountAccountTemplateModel, vv, nil)
5955
}
6056

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

7268
// DeleteAccountAccountTemplate deletes an existing account.account.template record.
@@ -85,10 +81,7 @@ func (c *Client) GetAccountAccountTemplate(id int64) (*AccountAccountTemplate, e
8581
if err != nil {
8682
return nil, err
8783
}
88-
if aats != nil && len(*aats) > 0 {
89-
return &((*aats)[0]), nil
90-
}
91-
return nil, fmt.Errorf("id %v of account.account.template not found", id)
84+
return &((*aats)[0]), nil
9285
}
9386

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

115105
// FindAccountAccountTemplates finds account.account.template records by querying it
@@ -125,11 +115,7 @@ func (c *Client) FindAccountAccountTemplates(criteria *Criteria, options *Option
125115
// FindAccountAccountTemplateIds finds records ids by querying it
126116
// and filtering it with criteria and options.
127117
func (c *Client) FindAccountAccountTemplateIds(criteria *Criteria, options *Options) ([]int64, error) {
128-
ids, err := c.Search(AccountAccountTemplateModel, criteria, options)
129-
if err != nil {
130-
return []int64{}, err
131-
}
132-
return ids, nil
118+
return c.Search(AccountAccountTemplateModel, criteria, options)
133119
}
134120

135121
// FindAccountAccountTemplateId finds record id by querying it with criteria.
@@ -138,8 +124,5 @@ func (c *Client) FindAccountAccountTemplateId(criteria *Criteria, options *Optio
138124
if err != nil {
139125
return -1, err
140126
}
141-
if len(ids) > 0 {
142-
return ids[0], nil
143-
}
144-
return -1, fmt.Errorf("account.account.template was not found with criteria %v and options %v", criteria, options)
127+
return ids[0], nil
145128
}

account_account_type.go

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
package odoo
22

3-
import (
4-
"fmt"
5-
)
6-
73
// AccountAccountType represents account.account.type model.
84
type AccountAccountType struct {
95
LastUpdate *Time `xmlrpc:"__last_update,omptempty"`
@@ -48,7 +44,7 @@ func (c *Client) CreateAccountAccountTypes(aats []*AccountAccountType) ([]int64,
4844
for _, v := range aats {
4945
vv = append(vv, v)
5046
}
51-
return c.Create(AccountAccountTypeModel, vv)
47+
return c.Create(AccountAccountTypeModel, vv, nil)
5248
}
5349

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

6561
// DeleteAccountAccountType deletes an existing account.account.type record.
@@ -78,10 +74,7 @@ func (c *Client) GetAccountAccountType(id int64) (*AccountAccountType, error) {
7874
if err != nil {
7975
return nil, err
8076
}
81-
if aats != nil && len(*aats) > 0 {
82-
return &((*aats)[0]), nil
83-
}
84-
return nil, fmt.Errorf("id %v of account.account.type not found", id)
77+
return &((*aats)[0]), nil
8578
}
8679

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

10898
// FindAccountAccountTypes finds account.account.type records by querying it
@@ -118,11 +108,7 @@ func (c *Client) FindAccountAccountTypes(criteria *Criteria, options *Options) (
118108
// FindAccountAccountTypeIds finds records ids by querying it
119109
// and filtering it with criteria and options.
120110
func (c *Client) FindAccountAccountTypeIds(criteria *Criteria, options *Options) ([]int64, error) {
121-
ids, err := c.Search(AccountAccountTypeModel, criteria, options)
122-
if err != nil {
123-
return []int64{}, err
124-
}
125-
return ids, nil
111+
return c.Search(AccountAccountTypeModel, criteria, options)
126112
}
127113

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

0 commit comments

Comments
 (0)