forked from skilld-labs/go-odoo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
account_fiscal_position.go
149 lines (132 loc) · 5.71 KB
/
account_fiscal_position.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
package odoo
import (
"fmt"
)
// AccountFiscalPosition represents account.fiscal.position model.
type AccountFiscalPosition struct {
LastUpdate *Time `xmlrpc:"__last_update,omptempty"`
AccountIds *Relation `xmlrpc:"account_ids,omptempty"`
Active *Bool `xmlrpc:"active,omptempty"`
AutoApply *Bool `xmlrpc:"auto_apply,omptempty"`
CompanyId *Many2One `xmlrpc:"company_id,omptempty"`
CountryGroupId *Many2One `xmlrpc:"country_group_id,omptempty"`
CountryId *Many2One `xmlrpc:"country_id,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"`
Note *String `xmlrpc:"note,omptempty"`
Sequence *Int `xmlrpc:"sequence,omptempty"`
StateIds *Relation `xmlrpc:"state_ids,omptempty"`
StatesCount *Int `xmlrpc:"states_count,omptempty"`
TaxIds *Relation `xmlrpc:"tax_ids,omptempty"`
VatRequired *Bool `xmlrpc:"vat_required,omptempty"`
WriteDate *Time `xmlrpc:"write_date,omptempty"`
WriteUid *Many2One `xmlrpc:"write_uid,omptempty"`
ZipFrom *Int `xmlrpc:"zip_from,omptempty"`
ZipTo *Int `xmlrpc:"zip_to,omptempty"`
}
// AccountFiscalPositions represents array of account.fiscal.position model.
type AccountFiscalPositions []AccountFiscalPosition
// AccountFiscalPositionModel is the odoo model name.
const AccountFiscalPositionModel = "account.fiscal.position"
// Many2One convert AccountFiscalPosition to *Many2One.
func (afp *AccountFiscalPosition) Many2One() *Many2One {
return NewMany2One(afp.Id.Get(), "")
}
// CreateAccountFiscalPosition creates a new account.fiscal.position model and returns its id.
func (c *Client) CreateAccountFiscalPosition(afp *AccountFiscalPosition) (int64, error) {
ids, err := c.CreateAccountFiscalPositions([]*AccountFiscalPosition{afp})
if err != nil {
return -1, err
}
if len(ids) == 0 {
return -1, nil
}
return ids[0], nil
}
// CreateAccountFiscalPosition creates a new account.fiscal.position model and returns its id.
func (c *Client) CreateAccountFiscalPositions(afps []*AccountFiscalPosition) ([]int64, error) {
var vv []interface{}
for _, v := range afps {
vv = append(vv, v)
}
return c.Create(AccountFiscalPositionModel, vv)
}
// UpdateAccountFiscalPosition updates an existing account.fiscal.position record.
func (c *Client) UpdateAccountFiscalPosition(afp *AccountFiscalPosition) error {
return c.UpdateAccountFiscalPositions([]int64{afp.Id.Get()}, afp)
}
// UpdateAccountFiscalPositions updates existing account.fiscal.position records.
// All records (represented by ids) will be updated by afp values.
func (c *Client) UpdateAccountFiscalPositions(ids []int64, afp *AccountFiscalPosition) error {
return c.Update(AccountFiscalPositionModel, ids, afp)
}
// DeleteAccountFiscalPosition deletes an existing account.fiscal.position record.
func (c *Client) DeleteAccountFiscalPosition(id int64) error {
return c.DeleteAccountFiscalPositions([]int64{id})
}
// DeleteAccountFiscalPositions deletes existing account.fiscal.position records.
func (c *Client) DeleteAccountFiscalPositions(ids []int64) error {
return c.Delete(AccountFiscalPositionModel, ids)
}
// GetAccountFiscalPosition gets account.fiscal.position existing record.
func (c *Client) GetAccountFiscalPosition(id int64) (*AccountFiscalPosition, error) {
afps, err := c.GetAccountFiscalPositions([]int64{id})
if err != nil {
return nil, err
}
if afps != nil && len(*afps) > 0 {
return &((*afps)[0]), nil
}
return nil, fmt.Errorf("id %v of account.fiscal.position not found", id)
}
// GetAccountFiscalPositions gets account.fiscal.position existing records.
func (c *Client) GetAccountFiscalPositions(ids []int64) (*AccountFiscalPositions, error) {
afps := &AccountFiscalPositions{}
if err := c.Read(AccountFiscalPositionModel, ids, nil, afps); err != nil {
return nil, err
}
return afps, nil
}
// FindAccountFiscalPosition finds account.fiscal.position record by querying it with criteria.
func (c *Client) FindAccountFiscalPosition(criteria *Criteria) (*AccountFiscalPosition, error) {
afps := &AccountFiscalPositions{}
if err := c.SearchRead(AccountFiscalPositionModel, criteria, NewOptions().Limit(1), afps); err != nil {
return nil, err
}
if afps != nil && len(*afps) > 0 {
return &((*afps)[0]), nil
}
return nil, fmt.Errorf("account.fiscal.position was not found with criteria %v", criteria)
}
// FindAccountFiscalPositions finds account.fiscal.position records by querying it
// and filtering it with criteria and options.
func (c *Client) FindAccountFiscalPositions(criteria *Criteria, options *Options) (*AccountFiscalPositions, error) {
afps := &AccountFiscalPositions{}
if err := c.SearchRead(AccountFiscalPositionModel, criteria, options, afps); err != nil {
return nil, err
}
return afps, nil
}
// FindAccountFiscalPositionIds finds records ids by querying it
// and filtering it with criteria and options.
func (c *Client) FindAccountFiscalPositionIds(criteria *Criteria, options *Options) ([]int64, error) {
ids, err := c.Search(AccountFiscalPositionModel, criteria, options)
if err != nil {
return []int64{}, err
}
return ids, nil
}
// FindAccountFiscalPositionId finds record id by querying it with criteria.
func (c *Client) FindAccountFiscalPositionId(criteria *Criteria, options *Options) (int64, error) {
ids, err := c.Search(AccountFiscalPositionModel, criteria, options)
if err != nil {
return -1, err
}
if len(ids) > 0 {
return ids[0], nil
}
return -1, fmt.Errorf("account.fiscal.position was not found with criteria %v and options %v", criteria, options)
}