-
Notifications
You must be signed in to change notification settings - Fork 64
/
account_payment.go
156 lines (140 loc) · 6.87 KB
/
account_payment.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
150
151
152
153
154
155
156
package odoo
// AccountPayment represents account.payment model.
type AccountPayment struct {
LastUpdate *Time `xmlrpc:"__last_update,omitempty"`
Amount *Float `xmlrpc:"amount,omitempty"`
Communication *String `xmlrpc:"communication,omitempty"`
CompanyId *Many2One `xmlrpc:"company_id,omitempty"`
CreateDate *Time `xmlrpc:"create_date,omitempty"`
CreateUid *Many2One `xmlrpc:"create_uid,omitempty"`
CurrencyId *Many2One `xmlrpc:"currency_id,omitempty"`
DestinationAccountId *Many2One `xmlrpc:"destination_account_id,omitempty"`
DestinationJournalId *Many2One `xmlrpc:"destination_journal_id,omitempty"`
DisplayName *String `xmlrpc:"display_name,omitempty"`
HasInvoices *Bool `xmlrpc:"has_invoices,omitempty"`
HidePaymentMethod *Bool `xmlrpc:"hide_payment_method,omitempty"`
Id *Int `xmlrpc:"id,omitempty"`
InvoiceIds *Relation `xmlrpc:"invoice_ids,omitempty"`
JournalId *Many2One `xmlrpc:"journal_id,omitempty"`
MessageChannelIds *Relation `xmlrpc:"message_channel_ids,omitempty"`
MessageFollowerIds *Relation `xmlrpc:"message_follower_ids,omitempty"`
MessageIds *Relation `xmlrpc:"message_ids,omitempty"`
MessageIsFollower *Bool `xmlrpc:"message_is_follower,omitempty"`
MessageLastPost *Time `xmlrpc:"message_last_post,omitempty"`
MessageNeedaction *Bool `xmlrpc:"message_needaction,omitempty"`
MessageNeedactionCounter *Int `xmlrpc:"message_needaction_counter,omitempty"`
MessagePartnerIds *Relation `xmlrpc:"message_partner_ids,omitempty"`
MessageUnread *Bool `xmlrpc:"message_unread,omitempty"`
MessageUnreadCounter *Int `xmlrpc:"message_unread_counter,omitempty"`
MoveLineIds *Relation `xmlrpc:"move_line_ids,omitempty"`
MoveName *String `xmlrpc:"move_name,omitempty"`
MoveReconciled *Bool `xmlrpc:"move_reconciled,omitempty"`
Name *String `xmlrpc:"name,omitempty"`
PartnerId *Many2One `xmlrpc:"partner_id,omitempty"`
PartnerType *Selection `xmlrpc:"partner_type,omitempty"`
PaymentDate *Time `xmlrpc:"payment_date,omitempty"`
PaymentDifference *Float `xmlrpc:"payment_difference,omitempty"`
PaymentDifferenceHandling *Selection `xmlrpc:"payment_difference_handling,omitempty"`
PaymentMethodCode *String `xmlrpc:"payment_method_code,omitempty"`
PaymentMethodId *Many2One `xmlrpc:"payment_method_id,omitempty"`
PaymentReference *String `xmlrpc:"payment_reference,omitempty"`
PaymentTokenId *Many2One `xmlrpc:"payment_token_id,omitempty"`
PaymentTransactionId *Many2One `xmlrpc:"payment_transaction_id,omitempty"`
PaymentType *Selection `xmlrpc:"payment_type,omitempty"`
State *Selection `xmlrpc:"state,omitempty"`
WebsiteMessageIds *Relation `xmlrpc:"website_message_ids,omitempty"`
WriteDate *Time `xmlrpc:"write_date,omitempty"`
WriteUid *Many2One `xmlrpc:"write_uid,omitempty"`
WriteoffAccountId *Many2One `xmlrpc:"writeoff_account_id,omitempty"`
WriteoffLabel *String `xmlrpc:"writeoff_label,omitempty"`
}
// AccountPayments represents array of account.payment model.
type AccountPayments []AccountPayment
// AccountPaymentModel is the odoo model name.
const AccountPaymentModel = "account.payment"
// Many2One convert AccountPayment to *Many2One.
func (ap *AccountPayment) Many2One() *Many2One {
return NewMany2One(ap.Id.Get(), "")
}
// CreateAccountPayment creates a new account.payment model and returns its id.
func (c *Client) CreateAccountPayment(ap *AccountPayment) (int64, error) {
ids, err := c.CreateAccountPayments([]*AccountPayment{ap})
if err != nil {
return -1, err
}
if len(ids) == 0 {
return -1, nil
}
return ids[0], nil
}
// CreateAccountPayments creates a new account.payment model and returns its id.
func (c *Client) CreateAccountPayments(aps []*AccountPayment) ([]int64, error) {
var vv []interface{}
for _, v := range aps {
vv = append(vv, v)
}
return c.Create(AccountPaymentModel, vv, nil)
}
// UpdateAccountPayment updates an existing account.payment record.
func (c *Client) UpdateAccountPayment(ap *AccountPayment) error {
return c.UpdateAccountPayments([]int64{ap.Id.Get()}, ap)
}
// UpdateAccountPayments updates existing account.payment records.
// All records (represented by ids) will be updated by ap values.
func (c *Client) UpdateAccountPayments(ids []int64, ap *AccountPayment) error {
return c.Update(AccountPaymentModel, ids, ap, nil)
}
// DeleteAccountPayment deletes an existing account.payment record.
func (c *Client) DeleteAccountPayment(id int64) error {
return c.DeleteAccountPayments([]int64{id})
}
// DeleteAccountPayments deletes existing account.payment records.
func (c *Client) DeleteAccountPayments(ids []int64) error {
return c.Delete(AccountPaymentModel, ids)
}
// GetAccountPayment gets account.payment existing record.
func (c *Client) GetAccountPayment(id int64) (*AccountPayment, error) {
aps, err := c.GetAccountPayments([]int64{id})
if err != nil {
return nil, err
}
return &((*aps)[0]), nil
}
// GetAccountPayments gets account.payment existing records.
func (c *Client) GetAccountPayments(ids []int64) (*AccountPayments, error) {
aps := &AccountPayments{}
if err := c.Read(AccountPaymentModel, ids, nil, aps); err != nil {
return nil, err
}
return aps, nil
}
// FindAccountPayment finds account.payment record by querying it with criteria.
func (c *Client) FindAccountPayment(criteria *Criteria) (*AccountPayment, error) {
aps := &AccountPayments{}
if err := c.SearchRead(AccountPaymentModel, criteria, NewOptions().Limit(1), aps); err != nil {
return nil, err
}
return &((*aps)[0]), nil
}
// FindAccountPayments finds account.payment records by querying it
// and filtering it with criteria and options.
func (c *Client) FindAccountPayments(criteria *Criteria, options *Options) (*AccountPayments, error) {
aps := &AccountPayments{}
if err := c.SearchRead(AccountPaymentModel, criteria, options, aps); err != nil {
return nil, err
}
return aps, nil
}
// FindAccountPaymentIds finds records ids by querying it
// and filtering it with criteria and options.
func (c *Client) FindAccountPaymentIds(criteria *Criteria, options *Options) ([]int64, error) {
return c.Search(AccountPaymentModel, criteria, options)
}
// FindAccountPaymentId finds record id by querying it with criteria.
func (c *Client) FindAccountPaymentId(criteria *Criteria, options *Options) (int64, error) {
ids, err := c.Search(AccountPaymentModel, criteria, options)
if err != nil {
return -1, err
}
return ids[0], nil
}