-
Notifications
You must be signed in to change notification settings - Fork 68
/
Copy pathproduct_uom.go
125 lines (109 loc) · 4.04 KB
/
product_uom.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
package odoo
import (
"fmt"
)
// ProductUom represents product.uom model.
type ProductUom struct {
LastUpdate *Time `xmlrpc:"__last_update,omptempty"`
Active *Bool `xmlrpc:"active,omptempty"`
CategoryId *Many2One `xmlrpc:"category_id,omptempty"`
CreateDate *Time `xmlrpc:"create_date,omptempty"`
CreateUid *Many2One `xmlrpc:"create_uid,omptempty"`
DisplayName *String `xmlrpc:"display_name,omptempty"`
Factor *Float `xmlrpc:"factor,omptempty"`
FactorInv *Float `xmlrpc:"factor_inv,omptempty"`
Id *Int `xmlrpc:"id,omptempty"`
Name *String `xmlrpc:"name,omptempty"`
Rounding *Float `xmlrpc:"rounding,omptempty"`
UomType *Selection `xmlrpc:"uom_type,omptempty"`
WriteDate *Time `xmlrpc:"write_date,omptempty"`
WriteUid *Many2One `xmlrpc:"write_uid,omptempty"`
}
// ProductUoms represents array of product.uom model.
type ProductUoms []ProductUom
// ProductUomModel is the odoo model name.
const ProductUomModel = "product.uom"
// Many2One convert ProductUom to *Many2One.
func (pu *ProductUom) Many2One() *Many2One {
return NewMany2One(pu.Id.Get(), "")
}
// CreateProductUom creates a new product.uom model and returns its id.
func (c *Client) CreateProductUom(pu *ProductUom) (int64, error) {
return c.Create(ProductUomModel, pu)
}
// UpdateProductUom updates an existing product.uom record.
func (c *Client) UpdateProductUom(pu *ProductUom) error {
return c.UpdateProductUoms([]int64{pu.Id.Get()}, pu)
}
// UpdateProductUoms updates existing product.uom records.
// All records (represented by ids) will be updated by pu values.
func (c *Client) UpdateProductUoms(ids []int64, pu *ProductUom) error {
return c.Update(ProductUomModel, ids, pu)
}
// DeleteProductUom deletes an existing product.uom record.
func (c *Client) DeleteProductUom(id int64) error {
return c.DeleteProductUoms([]int64{id})
}
// DeleteProductUoms deletes existing product.uom records.
func (c *Client) DeleteProductUoms(ids []int64) error {
return c.Delete(ProductUomModel, ids)
}
// GetProductUom gets product.uom existing record.
func (c *Client) GetProductUom(id int64) (*ProductUom, error) {
pus, err := c.GetProductUoms([]int64{id})
if err != nil {
return nil, err
}
if pus != nil && len(*pus) > 0 {
return &((*pus)[0]), nil
}
return nil, fmt.Errorf("id %v of product.uom not found", id)
}
// GetProductUoms gets product.uom existing records.
func (c *Client) GetProductUoms(ids []int64) (*ProductUoms, error) {
pus := &ProductUoms{}
if err := c.Read(ProductUomModel, ids, nil, pus); err != nil {
return nil, err
}
return pus, nil
}
// FindProductUom finds product.uom record by querying it with criteria.
func (c *Client) FindProductUom(criteria *Criteria) (*ProductUom, error) {
pus := &ProductUoms{}
if err := c.SearchRead(ProductUomModel, criteria, NewOptions().Limit(1), pus); err != nil {
return nil, err
}
if pus != nil && len(*pus) > 0 {
return &((*pus)[0]), nil
}
return nil, fmt.Errorf("no product.uom was found with criteria %v", criteria)
}
// FindProductUoms finds product.uom records by querying it
// and filtering it with criteria and options.
func (c *Client) FindProductUoms(criteria *Criteria, options *Options) (*ProductUoms, error) {
pus := &ProductUoms{}
if err := c.SearchRead(ProductUomModel, criteria, options, pus); err != nil {
return nil, err
}
return pus, nil
}
// FindProductUomIds finds records ids by querying it
// and filtering it with criteria and options.
func (c *Client) FindProductUomIds(criteria *Criteria, options *Options) ([]int64, error) {
ids, err := c.Search(ProductUomModel, criteria, options)
if err != nil {
return []int64{}, err
}
return ids, nil
}
// FindProductUomId finds record id by querying it with criteria.
func (c *Client) FindProductUomId(criteria *Criteria, options *Options) (int64, error) {
ids, err := c.Search(ProductUomModel, criteria, options)
if err != nil {
return -1, err
}
if len(ids) > 0 {
return ids[0], nil
}
return -1, fmt.Errorf("no product.uom was found with criteria %v and options %v", criteria, options)
}