Skip to content

Commit

Permalink
correct bug in create multiple instances in one call
Browse files Browse the repository at this point in the history
  • Loading branch information
ahuret committed Apr 13, 2023
1 parent f26c354 commit 4e76e2d
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions odoo.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,21 +224,31 @@ func getValuesFromInterface(v interface{}) map[string]interface{} {
// Create new model instances.
// https://www.odoo.com/documentation/13.0/webservices/odoo.html#create-records
func (c *Client) Create(model string, values []interface{}) ([]int64, error) {
var args []interface{}
if len(values) == 0 {
return nil, nil
} else if len(values) == 1 {
args = []interface{}{getValuesFromInterface(values[0])}
} else {
vv := make([]interface{}, len(values))
for i := 0; i < len(values); i++ {
vv[i] = getValuesFromInterface(values[i])
}
args = []interface{}{vv}
}
var vv []interface{}
for _, v := range values {
vv = append(vv, getValuesFromInterface(v))
}
resp, err := c.ExecuteKw("create", model, vv, nil)
resp, err := c.ExecuteKw("create", model, args, nil)
if err != nil {
return nil, err
}
if len(values) == 1 {
return []int64{resp.(int64)}, nil
}
return resp.([]int64), nil
r := resp.([]interface{})
ids := make([]int64, len(r))
for i := 0; i < len(ids); i++ {
ids[i] = r[i].(int64)
}
return ids, nil
}

// Update existing model row(s).
Expand Down

0 comments on commit 4e76e2d

Please sign in to comment.