forked from skilld-labs/go-odoo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
account_payment_method.go
137 lines (120 loc) · 4.95 KB
/
account_payment_method.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
package odoo
import (
"fmt"
)
// AccountPaymentMethod represents account.payment.method model.
type AccountPaymentMethod struct {
LastUpdate *Time `xmlrpc:"__last_update,omptempty"`
Code *String `xmlrpc:"code,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"`
PaymentType *Selection `xmlrpc:"payment_type,omptempty"`
WriteDate *Time `xmlrpc:"write_date,omptempty"`
WriteUid *Many2One `xmlrpc:"write_uid,omptempty"`
}
// AccountPaymentMethods represents array of account.payment.method model.
type AccountPaymentMethods []AccountPaymentMethod
// AccountPaymentMethodModel is the odoo model name.
const AccountPaymentMethodModel = "account.payment.method"
// Many2One convert AccountPaymentMethod to *Many2One.
func (apm *AccountPaymentMethod) Many2One() *Many2One {
return NewMany2One(apm.Id.Get(), "")
}
// CreateAccountPaymentMethod creates a new account.payment.method model and returns its id.
func (c *Client) CreateAccountPaymentMethod(apm *AccountPaymentMethod) (int64, error) {
ids, err := c.CreateAccountPaymentMethods([]*AccountPaymentMethod{apm})
if err != nil {
return -1, err
}
if len(ids) == 0 {
return -1, nil
}
return ids[0], nil
}
// CreateAccountPaymentMethod creates a new account.payment.method model and returns its id.
func (c *Client) CreateAccountPaymentMethods(apms []*AccountPaymentMethod) ([]int64, error) {
var vv []interface{}
for _, v := range apms {
vv = append(vv, v)
}
return c.Create(AccountPaymentMethodModel, vv)
}
// UpdateAccountPaymentMethod updates an existing account.payment.method record.
func (c *Client) UpdateAccountPaymentMethod(apm *AccountPaymentMethod) error {
return c.UpdateAccountPaymentMethods([]int64{apm.Id.Get()}, apm)
}
// UpdateAccountPaymentMethods updates existing account.payment.method records.
// All records (represented by ids) will be updated by apm values.
func (c *Client) UpdateAccountPaymentMethods(ids []int64, apm *AccountPaymentMethod) error {
return c.Update(AccountPaymentMethodModel, ids, apm)
}
// DeleteAccountPaymentMethod deletes an existing account.payment.method record.
func (c *Client) DeleteAccountPaymentMethod(id int64) error {
return c.DeleteAccountPaymentMethods([]int64{id})
}
// DeleteAccountPaymentMethods deletes existing account.payment.method records.
func (c *Client) DeleteAccountPaymentMethods(ids []int64) error {
return c.Delete(AccountPaymentMethodModel, ids)
}
// GetAccountPaymentMethod gets account.payment.method existing record.
func (c *Client) GetAccountPaymentMethod(id int64) (*AccountPaymentMethod, error) {
apms, err := c.GetAccountPaymentMethods([]int64{id})
if err != nil {
return nil, err
}
if apms != nil && len(*apms) > 0 {
return &((*apms)[0]), nil
}
return nil, fmt.Errorf("id %v of account.payment.method not found", id)
}
// GetAccountPaymentMethods gets account.payment.method existing records.
func (c *Client) GetAccountPaymentMethods(ids []int64) (*AccountPaymentMethods, error) {
apms := &AccountPaymentMethods{}
if err := c.Read(AccountPaymentMethodModel, ids, nil, apms); err != nil {
return nil, err
}
return apms, nil
}
// FindAccountPaymentMethod finds account.payment.method record by querying it with criteria.
func (c *Client) FindAccountPaymentMethod(criteria *Criteria) (*AccountPaymentMethod, error) {
apms := &AccountPaymentMethods{}
if err := c.SearchRead(AccountPaymentMethodModel, criteria, NewOptions().Limit(1), apms); err != nil {
return nil, err
}
if apms != nil && len(*apms) > 0 {
return &((*apms)[0]), nil
}
return nil, fmt.Errorf("account.payment.method was not found with criteria %v", criteria)
}
// FindAccountPaymentMethods finds account.payment.method records by querying it
// and filtering it with criteria and options.
func (c *Client) FindAccountPaymentMethods(criteria *Criteria, options *Options) (*AccountPaymentMethods, error) {
apms := &AccountPaymentMethods{}
if err := c.SearchRead(AccountPaymentMethodModel, criteria, options, apms); err != nil {
return nil, err
}
return apms, nil
}
// FindAccountPaymentMethodIds finds records ids by querying it
// and filtering it with criteria and options.
func (c *Client) FindAccountPaymentMethodIds(criteria *Criteria, options *Options) ([]int64, error) {
ids, err := c.Search(AccountPaymentMethodModel, criteria, options)
if err != nil {
return []int64{}, err
}
return ids, nil
}
// FindAccountPaymentMethodId finds record id by querying it with criteria.
func (c *Client) FindAccountPaymentMethodId(criteria *Criteria, options *Options) (int64, error) {
ids, err := c.Search(AccountPaymentMethodModel, criteria, options)
if err != nil {
return -1, err
}
if len(ids) > 0 {
return ids[0], nil
}
return -1, fmt.Errorf("account.payment.method was not found with criteria %v and options %v", criteria, options)
}