-
Notifications
You must be signed in to change notification settings - Fork 68
/
Copy pathstock_quant.go
129 lines (113 loc) · 4.35 KB
/
stock_quant.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
package odoo
import (
"fmt"
)
// StockQuant represents stock.quant model.
type StockQuant struct {
LastUpdate *Time `xmlrpc:"__last_update,omptempty"`
CompanyId *Many2One `xmlrpc:"company_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"`
InDate *Time `xmlrpc:"in_date,omptempty"`
LocationId *Many2One `xmlrpc:"location_id,omptempty"`
LotId *Many2One `xmlrpc:"lot_id,omptempty"`
OwnerId *Many2One `xmlrpc:"owner_id,omptempty"`
PackageId *Many2One `xmlrpc:"package_id,omptempty"`
ProductId *Many2One `xmlrpc:"product_id,omptempty"`
ProductTmplId *Many2One `xmlrpc:"product_tmpl_id,omptempty"`
ProductUomId *Many2One `xmlrpc:"product_uom_id,omptempty"`
Quantity *Float `xmlrpc:"quantity,omptempty"`
ReservedQuantity *Float `xmlrpc:"reserved_quantity,omptempty"`
WriteDate *Time `xmlrpc:"write_date,omptempty"`
WriteUid *Many2One `xmlrpc:"write_uid,omptempty"`
}
// StockQuants represents array of stock.quant model.
type StockQuants []StockQuant
// StockQuantModel is the odoo model name.
const StockQuantModel = "stock.quant"
// Many2One convert StockQuant to *Many2One.
func (sq *StockQuant) Many2One() *Many2One {
return NewMany2One(sq.Id.Get(), "")
}
// CreateStockQuant creates a new stock.quant model and returns its id.
func (c *Client) CreateStockQuant(sq *StockQuant) (int64, error) {
return c.Create(StockQuantModel, sq)
}
// UpdateStockQuant updates an existing stock.quant record.
func (c *Client) UpdateStockQuant(sq *StockQuant) error {
return c.UpdateStockQuants([]int64{sq.Id.Get()}, sq)
}
// UpdateStockQuants updates existing stock.quant records.
// All records (represented by ids) will be updated by sq values.
func (c *Client) UpdateStockQuants(ids []int64, sq *StockQuant) error {
return c.Update(StockQuantModel, ids, sq)
}
// DeleteStockQuant deletes an existing stock.quant record.
func (c *Client) DeleteStockQuant(id int64) error {
return c.DeleteStockQuants([]int64{id})
}
// DeleteStockQuants deletes existing stock.quant records.
func (c *Client) DeleteStockQuants(ids []int64) error {
return c.Delete(StockQuantModel, ids)
}
// GetStockQuant gets stock.quant existing record.
func (c *Client) GetStockQuant(id int64) (*StockQuant, error) {
sqs, err := c.GetStockQuants([]int64{id})
if err != nil {
return nil, err
}
if sqs != nil && len(*sqs) > 0 {
return &((*sqs)[0]), nil
}
return nil, fmt.Errorf("id %v of stock.quant not found", id)
}
// GetStockQuants gets stock.quant existing records.
func (c *Client) GetStockQuants(ids []int64) (*StockQuants, error) {
sqs := &StockQuants{}
if err := c.Read(StockQuantModel, ids, nil, sqs); err != nil {
return nil, err
}
return sqs, nil
}
// FindStockQuant finds stock.quant record by querying it with criteria.
func (c *Client) FindStockQuant(criteria *Criteria) (*StockQuant, error) {
sqs := &StockQuants{}
if err := c.SearchRead(StockQuantModel, criteria, NewOptions().Limit(1), sqs); err != nil {
return nil, err
}
if sqs != nil && len(*sqs) > 0 {
return &((*sqs)[0]), nil
}
return nil, fmt.Errorf("no stock.quant was found with criteria %v", criteria)
}
// FindStockQuants finds stock.quant records by querying it
// and filtering it with criteria and options.
func (c *Client) FindStockQuants(criteria *Criteria, options *Options) (*StockQuants, error) {
sqs := &StockQuants{}
if err := c.SearchRead(StockQuantModel, criteria, options, sqs); err != nil {
return nil, err
}
return sqs, nil
}
// FindStockQuantIds finds records ids by querying it
// and filtering it with criteria and options.
func (c *Client) FindStockQuantIds(criteria *Criteria, options *Options) ([]int64, error) {
ids, err := c.Search(StockQuantModel, criteria, options)
if err != nil {
return []int64{}, err
}
return ids, nil
}
// FindStockQuantId finds record id by querying it with criteria.
func (c *Client) FindStockQuantId(criteria *Criteria, options *Options) (int64, error) {
ids, err := c.Search(StockQuantModel, criteria, options)
if err != nil {
return -1, err
}
if len(ids) > 0 {
return ids[0], nil
}
return -1, fmt.Errorf("no stock.quant was found with criteria %v and options %v", criteria, options)
}