forked from skilld-labs/go-odoo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtypes.go
192 lines (160 loc) · 4.18 KB
/
types.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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
package odoo
import (
"time"
)
// String is a string wrapper
type String struct {
v string
}
// NewString creates a new *String.
func NewString(v string) *String {
return &String{v: v}
}
// Get *String value.
func (s *String) Get() string {
if s == nil {
return ""
}
return s.v
}
// Int is an int64 wrapper
type Int struct {
v int64
}
// NewInt creates a new *Int.
func NewInt(v int64) *Int {
return &Int{v: v}
}
// Get *Int value.
func (i *Int) Get() int64 {
if i == nil {
return 0
}
return i.v
}
// Bool is a bool wrapper
type Bool struct {
v bool
}
// NewBool creates a new *Bool.
func NewBool(v bool) *Bool {
return &Bool{v: v}
}
// Get *Bool value.
func (b *Bool) Get() bool {
if b == nil {
return false
}
return b.v
}
// Selection represents selection odoo type.
type Selection struct {
v interface{}
}
// NewSelection creates a new *Selection.
func NewSelection(v interface{}) *Selection {
return &Selection{v: v}
}
// Get *Selection value.
func (s *Selection) Get() interface{} {
if s == nil {
return nil
}
return s.v
}
// Time is a time.Time wrapper.
type Time struct {
v time.Time
}
// NewTime creates a new *Time.
func NewTime(v time.Time) *Time {
return &Time{v: v}
}
// Get *Time value.
func (t *Time) Get() time.Time {
if t == nil {
return time.Time{}
}
return t.v
}
// Float is a float64 wrapper
type Float struct {
v float64
}
// NewFloat creates a new *Float.
func NewFloat(v float64) *Float {
return &Float{v: v}
}
// Get *Float value.
func (f *Float) Get() float64 {
if f == nil {
return 0
}
return f.v
}
// Many2One represents odoo many2one type.
// https://www.odoo.com/documentation/13.0/reference/orm.html#relational-fields
type Many2One struct {
ID int64
Name string
}
// NewMany2One create a new *Many2One.
func NewMany2One(id int64, name string) *Many2One {
return &Many2One{ID: id, Name: name}
}
// Get *Many2One value.
func (m *Many2One) Get() int64 {
return m.ID
}
// Relation represents odoo one2many and many2many types.
// https://www.odoo.com/documentation/13.0/reference/orm.html#relational-fields
type Relation struct {
ids []int64
v []interface{}
}
// NewRelation creates a new *Relation.
func NewRelation() *Relation {
return &Relation{}
}
// Get *Relation value.
func (r *Relation) Get() []int64 {
if r == nil {
return []int64{}
}
return r.ids
}
// AddNewRecord is an helper to create a new record of one2many or many2many.
// https://www.odoo.com/documentation/13.0/reference/orm.html#odoo.models.Model.write
func (r *Relation) AddNewRecord(values interface{}) {
r.v = append(r.v, newTuple(0, 0, getValuesFromInterface(values)))
}
// UpdateRecord is an helper to update an existing record of one2many or many2many.
// https://www.odoo.com/documentation/13.0/reference/orm.html#odoo.models.Model.write
func (r *Relation) UpdateRecord(record int64, values interface{}) {
r.v = append(r.v, newTuple(1, record, getValuesFromInterface(values)))
}
// DeleteRecord is an helper to delete an existing record of one2many or many2many.
// https://www.odoo.com/documentation/13.0/reference/orm.html#odoo.models.Model.write
func (r *Relation) DeleteRecord(record int64) {
r.v = append(r.v, newTuple(2, record, 0))
}
// RemoveRecord is an helper to remove an existing record of one2many or many2many.
// https://www.odoo.com/documentation/13.0/reference/orm.html#odoo.models.Model.write
func (r *Relation) RemoveRecord(record int64) {
r.v = append(r.v, newTuple(3, record, 0))
}
// 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 int64) {
r.v = append(r.v, newTuple(4, record, 0))
}
// RemoveAllRecords is an helper to remove all records of one2many or many2many.
// https://www.odoo.com/documentation/13.0/reference/orm.html#odoo.models.Model.write
func (r *Relation) RemoveAllRecords() {
r.v = append(r.v, newTuple(5, 0, 0))
}
// ReplaceAllRecords is an helper to replace all records of one2many or many2many.
// https://www.odoo.com/documentation/13.0/reference/orm.html#odoo.models.Model.write
func (r *Relation) ReplaceAllRecords(newRecords []int64) {
r.v = append(r.v, newTuple(6, 0, newRecords))
}