-
Notifications
You must be signed in to change notification settings - Fork 68
/
Copy pathproduct_category.go
137 lines (121 loc) · 6.06 KB
/
product_category.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
package odoo
import (
"fmt"
)
// ProductCategory represents product.category model.
type ProductCategory struct {
LastUpdate *Time `xmlrpc:"__last_update,omptempty"`
ChildId *Relation `xmlrpc:"child_id,omptempty"`
CompleteName *String `xmlrpc:"complete_name,omptempty"`
CreateDate *Time `xmlrpc:"create_date,omptempty"`
CreateUid *Many2One `xmlrpc:"create_uid,omptempty"`
DisplayName *String `xmlrpc:"display_name,omptempty"`
Id *Int `xmlrpc:"id,omptempty"`
Name *String `xmlrpc:"name,omptempty"`
ParentId *Many2One `xmlrpc:"parent_id,omptempty"`
ParentLeft *Int `xmlrpc:"parent_left,omptempty"`
ParentRight *Int `xmlrpc:"parent_right,omptempty"`
ProductCount *Int `xmlrpc:"product_count,omptempty"`
PropertyAccountCreditorPriceDifferenceCateg *Many2One `xmlrpc:"property_account_creditor_price_difference_categ,omptempty"`
PropertyAccountExpenseCategId *Many2One `xmlrpc:"property_account_expense_categ_id,omptempty"`
PropertyAccountIncomeCategId *Many2One `xmlrpc:"property_account_income_categ_id,omptempty"`
PropertyCostMethod *Selection `xmlrpc:"property_cost_method,omptempty"`
PropertyStockAccountInputCategId *Many2One `xmlrpc:"property_stock_account_input_categ_id,omptempty"`
PropertyStockAccountOutputCategId *Many2One `xmlrpc:"property_stock_account_output_categ_id,omptempty"`
PropertyStockJournal *Many2One `xmlrpc:"property_stock_journal,omptempty"`
PropertyStockValuationAccountId *Many2One `xmlrpc:"property_stock_valuation_account_id,omptempty"`
PropertyValuation *Selection `xmlrpc:"property_valuation,omptempty"`
RemovalStrategyId *Many2One `xmlrpc:"removal_strategy_id,omptempty"`
RouteIds *Relation `xmlrpc:"route_ids,omptempty"`
TotalRouteIds *Relation `xmlrpc:"total_route_ids,omptempty"`
WriteDate *Time `xmlrpc:"write_date,omptempty"`
WriteUid *Many2One `xmlrpc:"write_uid,omptempty"`
}
// ProductCategorys represents array of product.category model.
type ProductCategorys []ProductCategory
// ProductCategoryModel is the odoo model name.
const ProductCategoryModel = "product.category"
// Many2One convert ProductCategory to *Many2One.
func (pc *ProductCategory) Many2One() *Many2One {
return NewMany2One(pc.Id.Get(), "")
}
// CreateProductCategory creates a new product.category model and returns its id.
func (c *Client) CreateProductCategory(pc *ProductCategory) (int64, error) {
return c.Create(ProductCategoryModel, pc)
}
// UpdateProductCategory updates an existing product.category record.
func (c *Client) UpdateProductCategory(pc *ProductCategory) error {
return c.UpdateProductCategorys([]int64{pc.Id.Get()}, pc)
}
// UpdateProductCategorys updates existing product.category records.
// All records (represented by ids) will be updated by pc values.
func (c *Client) UpdateProductCategorys(ids []int64, pc *ProductCategory) error {
return c.Update(ProductCategoryModel, ids, pc)
}
// DeleteProductCategory deletes an existing product.category record.
func (c *Client) DeleteProductCategory(id int64) error {
return c.DeleteProductCategorys([]int64{id})
}
// DeleteProductCategorys deletes existing product.category records.
func (c *Client) DeleteProductCategorys(ids []int64) error {
return c.Delete(ProductCategoryModel, ids)
}
// GetProductCategory gets product.category existing record.
func (c *Client) GetProductCategory(id int64) (*ProductCategory, error) {
pcs, err := c.GetProductCategorys([]int64{id})
if err != nil {
return nil, err
}
if pcs != nil && len(*pcs) > 0 {
return &((*pcs)[0]), nil
}
return nil, fmt.Errorf("id %v of product.category not found", id)
}
// GetProductCategorys gets product.category existing records.
func (c *Client) GetProductCategorys(ids []int64) (*ProductCategorys, error) {
pcs := &ProductCategorys{}
if err := c.Read(ProductCategoryModel, ids, nil, pcs); err != nil {
return nil, err
}
return pcs, nil
}
// FindProductCategory finds product.category record by querying it with criteria.
func (c *Client) FindProductCategory(criteria *Criteria) (*ProductCategory, error) {
pcs := &ProductCategorys{}
if err := c.SearchRead(ProductCategoryModel, criteria, NewOptions().Limit(1), pcs); err != nil {
return nil, err
}
if pcs != nil && len(*pcs) > 0 {
return &((*pcs)[0]), nil
}
return nil, fmt.Errorf("no product.category was found with criteria %v", criteria)
}
// FindProductCategorys finds product.category records by querying it
// and filtering it with criteria and options.
func (c *Client) FindProductCategorys(criteria *Criteria, options *Options) (*ProductCategorys, error) {
pcs := &ProductCategorys{}
if err := c.SearchRead(ProductCategoryModel, criteria, options, pcs); err != nil {
return nil, err
}
return pcs, nil
}
// FindProductCategoryIds finds records ids by querying it
// and filtering it with criteria and options.
func (c *Client) FindProductCategoryIds(criteria *Criteria, options *Options) ([]int64, error) {
ids, err := c.Search(ProductCategoryModel, criteria, options)
if err != nil {
return []int64{}, err
}
return ids, nil
}
// FindProductCategoryId finds record id by querying it with criteria.
func (c *Client) FindProductCategoryId(criteria *Criteria, options *Options) (int64, error) {
ids, err := c.Search(ProductCategoryModel, criteria, options)
if err != nil {
return -1, err
}
if len(ids) > 0 {
return ids[0], nil
}
return -1, fmt.Errorf("no product.category was found with criteria %v and options %v", criteria, options)
}