Class: Dolibarr::Api::Products

Inherits:
Object
  • Object
show all
Defined in:
lib/dolibarr-api/api/products.rb

Defined Under Namespace

Classes: Attributes, Barcode, Categories, Contact, Contacts, PurchasePrices, Ref, RefExt, Variants

Instance Method Summary collapse

Constructor Details

#initialize(connection) ⇒ Products

Returns a new instance of Products.



5
6
7
# File 'lib/dolibarr-api/api/products.rb', line 5

def initialize(connection)
  @connection = connection
end

Instance Method Details

#add_subproducts(id:, products_add_subproducts_model:) ⇒ Object

Raises:

  • (ArgumentError)


9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/dolibarr-api/api/products.rb', line 9

def add_subproducts(id:, products_add_subproducts_model:)
  raise ArgumentError, 'id is required' if id.nil?
  raise ArgumentError, 'products_add_subproducts_model is required' if products_add_subproducts_model.nil?

  @connection.call(
    :POST,
    '/products/{id}/subproducts/add'
      .gsub('{id}', ERB::Util.url_encode(id.to_s)),
    type: nil,
    auth: ['api_key'],
    body: products_add_subproducts_model
  )
end

#create(create_products_model: nil) ⇒ Object



23
24
25
26
27
28
29
30
31
# File 'lib/dolibarr-api/api/products.rb', line 23

def create(create_products_model: nil)
  @connection.call(
    :POST,
    '/products',
    type: nil,
    auth: ['api_key'],
    body: create_products_model
  )
end

#del_subproducts(id:, subproduct_id:) ⇒ Object

Raises:

  • (ArgumentError)


33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/dolibarr-api/api/products.rb', line 33

def del_subproducts(id:, subproduct_id:)
  raise ArgumentError, 'id is required' if id.nil?
  raise ArgumentError, 'subproduct_id is required' if subproduct_id.nil?

  @connection.call(
    :DELETE,
    '/products/{id}/subproducts/remove/{subproduct_id}'
      .gsub('{id}', ERB::Util.url_encode(id.to_s))
      .gsub('{subproduct_id}', ERB::Util.url_encode(subproduct_id.to_s)),
    type: nil,
    auth: ['api_key']
  )
end

#delete(id:) ⇒ Object

Raises:

  • (ArgumentError)


47
48
49
50
51
52
53
54
55
56
57
# File 'lib/dolibarr-api/api/products.rb', line 47

def delete(id:)
  raise ArgumentError, 'id is required' if id.nil?

  @connection.call(
    :DELETE,
    '/products/{id}'
      .gsub('{id}', ERB::Util.url_encode(id.to_s)),
    type: nil,
    auth: ['api_key']
  )
end

#get(id:, includestockdata: nil, includesubproducts: nil, includeparentid: nil, includetrans: nil) ⇒ Object

Raises:

  • (ArgumentError)


59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/dolibarr-api/api/products.rb', line 59

def get(id:, includestockdata: nil, includesubproducts: nil, includeparentid: nil, includetrans: nil)
  raise ArgumentError, 'id is required' if id.nil?

  @connection.call(
    :GET,
    '/products/{id}'
      .gsub('{id}', ERB::Util.url_encode(id.to_s)),
    type: nil,
    auth: ['api_key'],
    query: { 'includestockdata' => includestockdata, 'includesubproducts' => includesubproducts, 'includeparentid' => includeparentid, 'includetrans' => includetrans }
  )
end

#list(sortfield: nil, sortorder: nil, limit: nil, page: nil, mode: nil, category: nil, sqlfilters: nil, ids_only: nil, variant_filter: nil, pagination_data: nil, includestockdata: nil, properties: nil) ⇒ Object



72
73
74
75
76
77
78
79
80
# File 'lib/dolibarr-api/api/products.rb', line 72

def list(sortfield: nil, sortorder: nil, limit: nil, page: nil, mode: nil, category: nil, sqlfilters: nil, ids_only: nil, variant_filter: nil, pagination_data: nil, includestockdata: nil, properties: nil)
  @connection.call(
    :GET,
    '/products',
    type: nil,
    auth: ['api_key'],
    query: { 'sortfield' => sortfield, 'sortorder' => sortorder, 'limit' => limit, 'page' => page, 'mode' => mode, 'category' => category, 'sqlfilters' => sqlfilters, 'ids_only' => ids_only, 'variant_filter' => variant_filter, 'pagination_data' => pagination_data, 'includestockdata' => includestockdata, 'properties' => properties }
  )
end

#retrieve_customer_prices_per_customer(id:, thirdparty_id: nil) ⇒ Object

Raises:

  • (ArgumentError)


82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/dolibarr-api/api/products.rb', line 82

def retrieve_customer_prices_per_customer(id:, thirdparty_id: nil)
  raise ArgumentError, 'id is required' if id.nil?

  @connection.call(
    :GET,
    '/products/{id}/selling_multiprices/per_customer'
      .gsub('{id}', ERB::Util.url_encode(id.to_s)),
    type: nil,
    auth: ['api_key'],
    query: { 'thirdparty_id' => thirdparty_id }
  )
end

#retrieve_customer_prices_per_quantity(id:) ⇒ Object

Raises:

  • (ArgumentError)


95
96
97
98
99
100
101
102
103
104
105
# File 'lib/dolibarr-api/api/products.rb', line 95

def retrieve_customer_prices_per_quantity(id:)
  raise ArgumentError, 'id is required' if id.nil?

  @connection.call(
    :GET,
    '/products/{id}/selling_multiprices/per_quantity'
      .gsub('{id}', ERB::Util.url_encode(id.to_s)),
    type: nil,
    auth: ['api_key']
  )
end

#retrieve_customer_prices_per_segment(id:) ⇒ Object

Raises:

  • (ArgumentError)


107
108
109
110
111
112
113
114
115
116
117
# File 'lib/dolibarr-api/api/products.rb', line 107

def retrieve_customer_prices_per_segment(id:)
  raise ArgumentError, 'id is required' if id.nil?

  @connection.call(
    :GET,
    '/products/{id}/selling_multiprices/per_segment'
      .gsub('{id}', ERB::Util.url_encode(id.to_s)),
    type: nil,
    auth: ['api_key']
  )
end

#retrieve_stock(id:, selected_warehouse_id: nil) ⇒ Object

Raises:

  • (ArgumentError)


119
120
121
122
123
124
125
126
127
128
129
130
# File 'lib/dolibarr-api/api/products.rb', line 119

def retrieve_stock(id:, selected_warehouse_id: nil)
  raise ArgumentError, 'id is required' if id.nil?

  @connection.call(
    :GET,
    '/products/{id}/stock'
      .gsub('{id}', ERB::Util.url_encode(id.to_s)),
    type: nil,
    auth: ['api_key'],
    query: { 'selected_warehouse_id' => selected_warehouse_id }
  )
end

#retrieve_subproducts(id:) ⇒ Object

Raises:

  • (ArgumentError)


132
133
134
135
136
137
138
139
140
141
142
# File 'lib/dolibarr-api/api/products.rb', line 132

def retrieve_subproducts(id:)
  raise ArgumentError, 'id is required' if id.nil?

  @connection.call(
    :GET,
    '/products/{id}/subproducts'
      .gsub('{id}', ERB::Util.url_encode(id.to_s)),
    type: nil,
    auth: ['api_key']
  )
end

#update(id:, update_products_model: nil) ⇒ Object

Raises:

  • (ArgumentError)


144
145
146
147
148
149
150
151
152
153
154
155
# File 'lib/dolibarr-api/api/products.rb', line 144

def update(id:, update_products_model: nil)
  raise ArgumentError, 'id is required' if id.nil?

  @connection.call(
    :PUT,
    '/products/{id}'
      .gsub('{id}', ERB::Util.url_encode(id.to_s)),
    type: Dolibarr::Api::Models::Obj,
    auth: ['api_key'],
    body: update_products_model
  )
end