Class: Brightpearl::Order

Inherits:
Resource show all
Extended by:
APIOperations::Get, APIOperations::Options, APIOperations::Patch, APIOperations::Post
Defined in:
lib/brightpearl/resources/order.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from APIOperations::Get

get

Methods included from APIOperations::Post

post

Methods included from APIOperations::Patch

patch

Methods included from APIOperations::Options

options

Methods inherited from Resource

send_request, to_query

Constructor Details

#initialize(ara, as_response: false) ⇒ Order

DSL ARA => API Record Array(from search and other endpoints)



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
# File 'lib/brightpearl/resources/order.rb', line 37

def initialize(ara, as_response: false)
  unless as_response
    @id = ara[0];
    @order_type_id = ara[1]; @contact_id = ara[2]; @order_status_id = ara[3]; @order_stock_status_id = ara[4];
    @created_on = ara[5]; @created_by_id = ara[6]; 
    @customer_ref = ara[7]; @order_payment_status_id = ara[8]; @updated_on = ara[9]; 
    @parent_order_id = ara[10]; @order_shipping_status_id = ara[11]; @external_ref = ara[12];
    @installed_integration_instance_id = ara[13]; @warehouse_id = ara[14]; @staff_owner_contact_id = ara[15]; 
    @tax_date = ara[16];
    @department_id = ara[17];
    @delivery_date = ara[18];
  else  # Order response from get_order
    @id = ara["id"]
    @order_type_id = nil 
    @contact_id = ara["parties"]["customer"]["contactId"]
    @order_status_id = ara["orderStatus"]["orderStatusId"]
    @order_stock_status_id = nil
    @created_on = ara["createdOn"]
    @created_by_id = ara["createdById"]
    @customer_ref = nil
    @order_payment_status_id = nil
    @updated_on = ara["updatedOn"]
    @parent_order_id = ara["parentOrderId"]
    @order_shipping_status_id = nil
    @external_ref = ara["reference"]
    @installed_integration_instance_id = nil
    @warehouse_id = ara["warehousrId"]
    @staff_owner_contact_id = ara["assignment"]["current"]["staffOwnerContactId"]
    @tax_date = ara["invoices"][0] && ara["invoices"][0]["taxDate"]
    @department_id = nil
    @delivery_date = nil
  end
end

Instance Attribute Details

#contact_idObject

Returns the value of attribute contact_id.



8
9
10
# File 'lib/brightpearl/resources/order.rb', line 8

def contact_id
  @contact_id
end

#created_by_idObject

Returns the value of attribute created_by_id.



8
9
10
# File 'lib/brightpearl/resources/order.rb', line 8

def created_by_id
  @created_by_id
end

#created_onObject

Returns the value of attribute created_on.



8
9
10
# File 'lib/brightpearl/resources/order.rb', line 8

def created_on
  @created_on
end

#customer_refObject

Returns the value of attribute customer_ref.



8
9
10
# File 'lib/brightpearl/resources/order.rb', line 8

def customer_ref
  @customer_ref
end

#delivery_dateObject

Returns the value of attribute delivery_date.



8
9
10
# File 'lib/brightpearl/resources/order.rb', line 8

def delivery_date
  @delivery_date
end

#department_idObject

Returns the value of attribute department_id.



8
9
10
# File 'lib/brightpearl/resources/order.rb', line 8

def department_id
  @department_id
end

#external_refObject

Returns the value of attribute external_ref.



8
9
10
# File 'lib/brightpearl/resources/order.rb', line 8

def external_ref
  @external_ref
end

#idObject

Returns the value of attribute id.



8
9
10
# File 'lib/brightpearl/resources/order.rb', line 8

def id
  @id
end

#installed_integration_instance_idObject

Returns the value of attribute installed_integration_instance_id.



8
9
10
# File 'lib/brightpearl/resources/order.rb', line 8

def installed_integration_instance_id
  @installed_integration_instance_id
end

#order_payment_status_idObject

Returns the value of attribute order_payment_status_id.



8
9
10
# File 'lib/brightpearl/resources/order.rb', line 8

def order_payment_status_id
  @order_payment_status_id
end

#order_shipping_status_idObject

Returns the value of attribute order_shipping_status_id.



8
9
10
# File 'lib/brightpearl/resources/order.rb', line 8

def order_shipping_status_id
  @order_shipping_status_id
end

#order_status_idObject

Returns the value of attribute order_status_id.



8
9
10
# File 'lib/brightpearl/resources/order.rb', line 8

def order_status_id
  @order_status_id
end

#order_stock_status_idObject

Returns the value of attribute order_stock_status_id.



8
9
10
# File 'lib/brightpearl/resources/order.rb', line 8

def order_stock_status_id
  @order_stock_status_id
end

#order_type_idObject

Returns the value of attribute order_type_id.



8
9
10
# File 'lib/brightpearl/resources/order.rb', line 8

def order_type_id
  @order_type_id
end

#parent_order_idObject

Returns the value of attribute parent_order_id.



8
9
10
# File 'lib/brightpearl/resources/order.rb', line 8

def parent_order_id
  @parent_order_id
end

#staff_owner_contact_idObject

Returns the value of attribute staff_owner_contact_id.



8
9
10
# File 'lib/brightpearl/resources/order.rb', line 8

def staff_owner_contact_id
  @staff_owner_contact_id
end

#tax_dateObject

Returns the value of attribute tax_date.



8
9
10
# File 'lib/brightpearl/resources/order.rb', line 8

def tax_date
  @tax_date
end

#updated_onObject

Returns the value of attribute updated_on.



8
9
10
# File 'lib/brightpearl/resources/order.rb', line 8

def updated_on
  @updated_on
end

#warehouse_idObject

Returns the value of attribute warehouse_id.



8
9
10
# File 'lib/brightpearl/resources/order.rb', line 8

def warehouse_id
  @warehouse_id
end

Class Method Details

.resource_pathObject



16
17
18
# File 'lib/brightpearl/resources/order.rb', line 16

def resource_path
  "order-service/order"
end

.search(query_params = {}) ⇒ Object



27
28
29
30
31
32
# File 'lib/brightpearl/resources/order.rb', line 27

def search(query_params = {})
  response = send_request(path: "order-service/order-search?#{to_query(query_params)}", method: :get)
  return response.merge({ # modify final payload to set search results as objects
    records: response[:payload]["response"]["results"].map { |item| Order.new(item) },
   })
end