forked from skilld-labs/go-odoo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
account_journal.go
168 lines (151 loc) · 6.9 KB
/
account_journal.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
157
158
159
160
161
162
163
164
165
166
167
168
package odoo
import (
"fmt"
)
// AccountJournal represents account.journal model.
type AccountJournal struct {
LastUpdate *Time `xmlrpc:"__last_update,omptempty"`
AccountControlIds *Relation `xmlrpc:"account_control_ids,omptempty"`
AccountSetupBankDataDone *Bool `xmlrpc:"account_setup_bank_data_done,omptempty"`
Active *Bool `xmlrpc:"active,omptempty"`
AtLeastOneInbound *Bool `xmlrpc:"at_least_one_inbound,omptempty"`
AtLeastOneOutbound *Bool `xmlrpc:"at_least_one_outbound,omptempty"`
BankAccNumber *String `xmlrpc:"bank_acc_number,omptempty"`
BankAccountId *Many2One `xmlrpc:"bank_account_id,omptempty"`
BankId *Many2One `xmlrpc:"bank_id,omptempty"`
BankStatementsSource *Selection `xmlrpc:"bank_statements_source,omptempty"`
BelongsToCompany *Bool `xmlrpc:"belongs_to_company,omptempty"`
Code *String `xmlrpc:"code,omptempty"`
Color *Int `xmlrpc:"color,omptempty"`
CompanyId *Many2One `xmlrpc:"company_id,omptempty"`
CreateDate *Time `xmlrpc:"create_date,omptempty"`
CreateUid *Many2One `xmlrpc:"create_uid,omptempty"`
CurrencyId *Many2One `xmlrpc:"currency_id,omptempty"`
DefaultCreditAccountId *Many2One `xmlrpc:"default_credit_account_id,omptempty"`
DefaultDebitAccountId *Many2One `xmlrpc:"default_debit_account_id,omptempty"`
DisplayName *String `xmlrpc:"display_name,omptempty"`
GroupInvoiceLines *Bool `xmlrpc:"group_invoice_lines,omptempty"`
Id *Int `xmlrpc:"id,omptempty"`
InboundPaymentMethodIds *Relation `xmlrpc:"inbound_payment_method_ids,omptempty"`
KanbanDashboard *String `xmlrpc:"kanban_dashboard,omptempty"`
KanbanDashboardGraph *String `xmlrpc:"kanban_dashboard_graph,omptempty"`
LossAccountId *Many2One `xmlrpc:"loss_account_id,omptempty"`
Name *String `xmlrpc:"name,omptempty"`
OutboundPaymentMethodIds *Relation `xmlrpc:"outbound_payment_method_ids,omptempty"`
ProfitAccountId *Many2One `xmlrpc:"profit_account_id,omptempty"`
RefundSequence *Bool `xmlrpc:"refund_sequence,omptempty"`
RefundSequenceId *Many2One `xmlrpc:"refund_sequence_id,omptempty"`
RefundSequenceNumberNext *Int `xmlrpc:"refund_sequence_number_next,omptempty"`
Sequence *Int `xmlrpc:"sequence,omptempty"`
SequenceId *Many2One `xmlrpc:"sequence_id,omptempty"`
SequenceNumberNext *Int `xmlrpc:"sequence_number_next,omptempty"`
ShowOnDashboard *Bool `xmlrpc:"show_on_dashboard,omptempty"`
Type *Selection `xmlrpc:"type,omptempty"`
TypeControlIds *Relation `xmlrpc:"type_control_ids,omptempty"`
UpdatePosted *Bool `xmlrpc:"update_posted,omptempty"`
WriteDate *Time `xmlrpc:"write_date,omptempty"`
WriteUid *Many2One `xmlrpc:"write_uid,omptempty"`
}
// AccountJournals represents array of account.journal model.
type AccountJournals []AccountJournal
// AccountJournalModel is the odoo model name.
const AccountJournalModel = "account.journal"
// Many2One convert AccountJournal to *Many2One.
func (aj *AccountJournal) Many2One() *Many2One {
return NewMany2One(aj.Id.Get(), "")
}
// CreateAccountJournal creates a new account.journal model and returns its id.
func (c *Client) CreateAccountJournal(aj *AccountJournal) (int64, error) {
ids, err := c.CreateAccountJournals([]*AccountJournal{aj})
if err != nil {
return -1, err
}
if len(ids) == 0 {
return -1, nil
}
return ids[0], nil
}
// CreateAccountJournal creates a new account.journal model and returns its id.
func (c *Client) CreateAccountJournals(ajs []*AccountJournal) ([]int64, error) {
var vv []interface{}
for _, v := range ajs {
vv = append(vv, v)
}
return c.Create(AccountJournalModel, vv)
}
// UpdateAccountJournal updates an existing account.journal record.
func (c *Client) UpdateAccountJournal(aj *AccountJournal) error {
return c.UpdateAccountJournals([]int64{aj.Id.Get()}, aj)
}
// UpdateAccountJournals updates existing account.journal records.
// All records (represented by ids) will be updated by aj values.
func (c *Client) UpdateAccountJournals(ids []int64, aj *AccountJournal) error {
return c.Update(AccountJournalModel, ids, aj)
}
// DeleteAccountJournal deletes an existing account.journal record.
func (c *Client) DeleteAccountJournal(id int64) error {
return c.DeleteAccountJournals([]int64{id})
}
// DeleteAccountJournals deletes existing account.journal records.
func (c *Client) DeleteAccountJournals(ids []int64) error {
return c.Delete(AccountJournalModel, ids)
}
// GetAccountJournal gets account.journal existing record.
func (c *Client) GetAccountJournal(id int64) (*AccountJournal, error) {
ajs, err := c.GetAccountJournals([]int64{id})
if err != nil {
return nil, err
}
if ajs != nil && len(*ajs) > 0 {
return &((*ajs)[0]), nil
}
return nil, fmt.Errorf("id %v of account.journal not found", id)
}
// GetAccountJournals gets account.journal existing records.
func (c *Client) GetAccountJournals(ids []int64) (*AccountJournals, error) {
ajs := &AccountJournals{}
if err := c.Read(AccountJournalModel, ids, nil, ajs); err != nil {
return nil, err
}
return ajs, nil
}
// FindAccountJournal finds account.journal record by querying it with criteria.
func (c *Client) FindAccountJournal(criteria *Criteria) (*AccountJournal, error) {
ajs := &AccountJournals{}
if err := c.SearchRead(AccountJournalModel, criteria, NewOptions().Limit(1), ajs); err != nil {
return nil, err
}
if ajs != nil && len(*ajs) > 0 {
return &((*ajs)[0]), nil
}
return nil, fmt.Errorf("account.journal was not found with criteria %v", criteria)
}
// FindAccountJournals finds account.journal records by querying it
// and filtering it with criteria and options.
func (c *Client) FindAccountJournals(criteria *Criteria, options *Options) (*AccountJournals, error) {
ajs := &AccountJournals{}
if err := c.SearchRead(AccountJournalModel, criteria, options, ajs); err != nil {
return nil, err
}
return ajs, nil
}
// FindAccountJournalIds finds records ids by querying it
// and filtering it with criteria and options.
func (c *Client) FindAccountJournalIds(criteria *Criteria, options *Options) ([]int64, error) {
ids, err := c.Search(AccountJournalModel, criteria, options)
if err != nil {
return []int64{}, err
}
return ids, nil
}
// FindAccountJournalId finds record id by querying it with criteria.
func (c *Client) FindAccountJournalId(criteria *Criteria, options *Options) (int64, error) {
ids, err := c.Search(AccountJournalModel, criteria, options)
if err != nil {
return -1, err
}
if len(ids) > 0 {
return ids[0], nil
}
return -1, fmt.Errorf("account.journal was not found with criteria %v and options %v", criteria, options)
}