-
Notifications
You must be signed in to change notification settings - Fork 68
/
Copy pathstock_change_product_qty.go
124 lines (108 loc) · 4.91 KB
/
stock_change_product_qty.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
package odoo
import (
"fmt"
)
// StockChangeProductQty represents stock.change.product.qty model.
type StockChangeProductQty struct {
LastUpdate *Time `xmlrpc:"__last_update,omptempty"`
CreateDate *Time `xmlrpc:"create_date,omptempty"`
CreateUid *Many2One `xmlrpc:"create_uid,omptempty"`
DisplayName *String `xmlrpc:"display_name,omptempty"`
Id *Int `xmlrpc:"id,omptempty"`
LocationId *Many2One `xmlrpc:"location_id,omptempty"`
LotId *Many2One `xmlrpc:"lot_id,omptempty"`
NewQuantity *Float `xmlrpc:"new_quantity,omptempty"`
ProductId *Many2One `xmlrpc:"product_id,omptempty"`
ProductTmplId *Many2One `xmlrpc:"product_tmpl_id,omptempty"`
ProductVariantCount *Int `xmlrpc:"product_variant_count,omptempty"`
WriteDate *Time `xmlrpc:"write_date,omptempty"`
WriteUid *Many2One `xmlrpc:"write_uid,omptempty"`
}
// StockChangeProductQtys represents array of stock.change.product.qty model.
type StockChangeProductQtys []StockChangeProductQty
// StockChangeProductQtyModel is the odoo model name.
const StockChangeProductQtyModel = "stock.change.product.qty"
// Many2One convert StockChangeProductQty to *Many2One.
func (scpq *StockChangeProductQty) Many2One() *Many2One {
return NewMany2One(scpq.Id.Get(), "")
}
// CreateStockChangeProductQty creates a new stock.change.product.qty model and returns its id.
func (c *Client) CreateStockChangeProductQty(scpq *StockChangeProductQty) (int64, error) {
return c.Create(StockChangeProductQtyModel, scpq)
}
// UpdateStockChangeProductQty updates an existing stock.change.product.qty record.
func (c *Client) UpdateStockChangeProductQty(scpq *StockChangeProductQty) error {
return c.UpdateStockChangeProductQtys([]int64{scpq.Id.Get()}, scpq)
}
// UpdateStockChangeProductQtys updates existing stock.change.product.qty records.
// All records (represented by ids) will be updated by scpq values.
func (c *Client) UpdateStockChangeProductQtys(ids []int64, scpq *StockChangeProductQty) error {
return c.Update(StockChangeProductQtyModel, ids, scpq)
}
// DeleteStockChangeProductQty deletes an existing stock.change.product.qty record.
func (c *Client) DeleteStockChangeProductQty(id int64) error {
return c.DeleteStockChangeProductQtys([]int64{id})
}
// DeleteStockChangeProductQtys deletes existing stock.change.product.qty records.
func (c *Client) DeleteStockChangeProductQtys(ids []int64) error {
return c.Delete(StockChangeProductQtyModel, ids)
}
// GetStockChangeProductQty gets stock.change.product.qty existing record.
func (c *Client) GetStockChangeProductQty(id int64) (*StockChangeProductQty, error) {
scpqs, err := c.GetStockChangeProductQtys([]int64{id})
if err != nil {
return nil, err
}
if scpqs != nil && len(*scpqs) > 0 {
return &((*scpqs)[0]), nil
}
return nil, fmt.Errorf("id %v of stock.change.product.qty not found", id)
}
// GetStockChangeProductQtys gets stock.change.product.qty existing records.
func (c *Client) GetStockChangeProductQtys(ids []int64) (*StockChangeProductQtys, error) {
scpqs := &StockChangeProductQtys{}
if err := c.Read(StockChangeProductQtyModel, ids, nil, scpqs); err != nil {
return nil, err
}
return scpqs, nil
}
// FindStockChangeProductQty finds stock.change.product.qty record by querying it with criteria.
func (c *Client) FindStockChangeProductQty(criteria *Criteria) (*StockChangeProductQty, error) {
scpqs := &StockChangeProductQtys{}
if err := c.SearchRead(StockChangeProductQtyModel, criteria, NewOptions().Limit(1), scpqs); err != nil {
return nil, err
}
if scpqs != nil && len(*scpqs) > 0 {
return &((*scpqs)[0]), nil
}
return nil, fmt.Errorf("no stock.change.product.qty was found with criteria %v", criteria)
}
// FindStockChangeProductQtys finds stock.change.product.qty records by querying it
// and filtering it with criteria and options.
func (c *Client) FindStockChangeProductQtys(criteria *Criteria, options *Options) (*StockChangeProductQtys, error) {
scpqs := &StockChangeProductQtys{}
if err := c.SearchRead(StockChangeProductQtyModel, criteria, options, scpqs); err != nil {
return nil, err
}
return scpqs, nil
}
// FindStockChangeProductQtyIds finds records ids by querying it
// and filtering it with criteria and options.
func (c *Client) FindStockChangeProductQtyIds(criteria *Criteria, options *Options) ([]int64, error) {
ids, err := c.Search(StockChangeProductQtyModel, criteria, options)
if err != nil {
return []int64{}, err
}
return ids, nil
}
// FindStockChangeProductQtyId finds record id by querying it with criteria.
func (c *Client) FindStockChangeProductQtyId(criteria *Criteria, options *Options) (int64, error) {
ids, err := c.Search(StockChangeProductQtyModel, criteria, options)
if err != nil {
return -1, err
}
if len(ids) > 0 {
return ids[0], nil
}
return -1, fmt.Errorf("no stock.change.product.qty was found with criteria %v and options %v", criteria, options)
}