Skip to content

Commit

Permalink
added account_analytic_tag.go + resolved invalid int type on AddRecor…
Browse files Browse the repository at this point in the history
…d method of Relation
  • Loading branch information
ahuret committed May 5, 2020
1 parent 30f0f81 commit 0404e29
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 2 deletions.
99 changes: 99 additions & 0 deletions account_analytic_tag.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
package odoo

import (
"fmt"
)

// AccountAnalyticTag represents account.analytic.tag model
type AccountAnalyticTag struct {
LastUpdate *Time `xmlrpc:"__last_update,omptempty"`
Active *Bool `xmlrpc:"active,omptempty"`
Color *Int `xmlrpc:"color,omptempty"`
CreateDate *Time `xmlrpc:"create_date,omptempty"`
CreateUid *Many2One `xmlrpc:"create_uid,omptempty"`
DisplayName *String `xmlrpc:"display_name,omptempty"`
Id *Int `xmlrpc:"id,omptempty"`
Name *String `xmlrpc:"name,omptempty"`
WriteDate *Time `xmlrpc:"write_date,omptempty"`
WriteUid *Many2One `xmlrpc:"write_uid,omptempty"`
}

// AccountAnalyticTags represents array of account.analytic.tag model
type AccountAnalyticTags []AccountAnalyticTag

// AccountAnalyticTagModel is the odoo model name
const AccountAnalyticTagModel = "account.analytic.tag"

// Many2One convert AccountAnalyticTag to *Many2One.
func (aat *AccountAnalyticTag) Many2One() *Many2One {
return NewMany2One(aat.Id.Get(), "")
}

// CreateAccountAnalyticTag creates a new account.analytic.tag model and returns its id.
func (c *Client) CreateAccountAnalyticTag(aat *AccountAnalyticTag) (int64, error) {
return c.Create(AccountAnalyticTagModel, aat)
}

// UpdateAccountAnalyticTag updates an existing account.analytic.tag record.
func (c *Client) UpdateAccountAnalyticTag(aat *AccountAnalyticTag) error {
return c.UpdateAccountAnalyticTags([]int64{aat.Id.Get()}, aat)
}

// UpdateAccountAnalyticTags updates existing account.analytic.tag records.
// All records (represented by ids) will be updated by aat values.
func (c *Client) UpdateAccountAnalyticTags(ids []int64, aat *AccountAnalyticTag) error {
return c.Update(AccountAnalyticTagModel, ids, aat)
}

// DeleteAccountAnalyticTag deletes an existing account.analytic.tag record.
func (c *Client) DeleteAccountAnalyticTag(id int64) error {
return c.DeleteAccountAnalyticTags([]int64{id})
}

// DeleteAccountAnalyticTags deletes existing account.analytic.tag records.
func (c *Client) DeleteAccountAnalyticTags(ids []int64) error {
return c.Delete(AccountAnalyticTagModel, ids)
}

// GetAccountAnalyticTag gets account.analytic.tag existing record.
func (c *Client) GetAccountAnalyticTag(id int64) (*AccountAnalyticTag, error) {
aats, err := c.GetAccountAnalyticTags([]int64{id})
if err != nil {
return nil, err
}
if aats != nil && len(*aats) > 0 {
return &((*aats)[0]), nil
}
return nil, fmt.Errorf("id %v of %s not found", id, AccountAnalyticTagModel)
}

// GetAccountAnalyticTags gets account.analytic.tag existing records.
func (c *Client) GetAccountAnalyticTags(ids []int64) (*AccountAnalyticTags, error) {
aats := &AccountAnalyticTags{}
if err := c.Read(AccountAnalyticTagModel, ids, nil, aats); err != nil {
return nil, err
}
return aats, nil
}

// 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 {
return nil, err
}
if aats != nil && len(*aats) > 0 {
return &((*aats)[0]), nil
}
return nil, fmt.Errorf("account.analytic.tag was not found")
}

// FindAccountAnalyticTags finds account.analytic.tag records by querying it
// and filtering it with criteria and options.
func (c *Client) FindAccountAnalyticTags(criteria *Criteria, options *Options) (*AccountAnalyticTags, error) {
aats := &AccountAnalyticTags{}
if err := c.SearchRead(AccountAnalyticTagModel, criteria, options, aats); err != nil {
return nil, err
}
return aats, nil
}
1 change: 0 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3Ee
github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4=
github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA=
github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no=
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
Expand Down
2 changes: 1 addition & 1 deletion types.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ func (r *Relation) RemoveRecord(record int64) {

// AddRecord is an helper to add an existing record of one2many or many2many.
// https://www.odoo.com/documentation/13.0/reference/orm.html#odoo.models.Model.write
func (r *Relation) AddRecord(record int) {
func (r *Relation) AddRecord(record int64) {
r.v = append(r.v, newTuple(4, record, 0))
}

Expand Down

0 comments on commit 0404e29

Please sign in to comment.