Class: Beanie::SalesOrderItem

Inherits:
Api
  • Object
show all
Defined in:
lib/beanie/sales_order_item.rb

Constant Summary collapse

STATE_NEW =
0
STATE_READY =
1
STATE_DONE =
2
STATE_BLOCKED =
3
STATE_NAMES =
[
  ["New Order Item", STATE_NEW],
  ["Billable", STATE_READY],
  ["Complete", STATE_DONE],
  ["Blocked", STATE_BLOCKED]
].freeze
SERVICE_PERIOD_ONEOFF =
0
SERVICE_PERIOD_HOURLY =
1
SERVICE_PERIOD_DAILY =
2
SERVICE_PERIOD_WEEKLY =
3
SERVICE_PERIOD_MONTHLY =
4
SERVICE_PERIOD_QUARTERLY =
5
SERVICE_PERIOD_ANNUALLY =
6
SERVICE_PERIOD_NAMES =
[
  ["One-Off", SERVICE_PERIOD_ONEOFF],
  ["Hourly Rate", SERVICE_PERIOD_HOURLY],
  ["Daily Rate", SERVICE_PERIOD_DAILY],
  ["Weekly Rate", SERVICE_PERIOD_WEEKLY],
  ["Monthly Rate", SERVICE_PERIOD_MONTHLY],
  ["Quarterly Rate", SERVICE_PERIOD_QUARTERLY],
  ["Annual Rate", SERVICE_PERIOD_ANNUALLY]
].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Api

all, build_url, #construct_path, delete, #extract, #field_name, find, get, #object_name, #populate, post, put, #save!, set_headers

Constructor Details

#initializeSalesOrderItem

Initialize instance variables



67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/beanie/sales_order_item.rb', line 67

def initialize
  @id = nil
  @completion = nil
  @description = nil
  @discount = nil
  @quantity = nil
  @rundate = nil
  @state = nil
  @sales_order_id = nil
  @product_id = nil
  @service_period = nil
  @unit_cost = nil
  @sales_tax = nil
end

Instance Attribute Details

#completionObject

Returns the value of attribute completion.



32
33
34
# File 'lib/beanie/sales_order_item.rb', line 32

def completion
  @completion
end

#descriptionObject

Returns the value of attribute description.



32
33
34
# File 'lib/beanie/sales_order_item.rb', line 32

def description
  @description
end

#discountObject

Returns the value of attribute discount.



32
33
34
# File 'lib/beanie/sales_order_item.rb', line 32

def discount
  @discount
end

#idObject

Returns the value of attribute id.



32
33
34
# File 'lib/beanie/sales_order_item.rb', line 32

def id
  @id
end

#product_idObject

Returns the value of attribute product_id.



33
34
35
# File 'lib/beanie/sales_order_item.rb', line 33

def product_id
  @product_id
end

#quantityObject

Returns the value of attribute quantity.



32
33
34
# File 'lib/beanie/sales_order_item.rb', line 32

def quantity
  @quantity
end

#rundateObject

Returns the value of attribute rundate.



32
33
34
# File 'lib/beanie/sales_order_item.rb', line 32

def rundate
  @rundate
end

#sales_order_idObject

Returns the value of attribute sales_order_id.



33
34
35
# File 'lib/beanie/sales_order_item.rb', line 33

def sales_order_id
  @sales_order_id
end

#sales_taxObject

Returns the value of attribute sales_tax.



33
34
35
# File 'lib/beanie/sales_order_item.rb', line 33

def sales_tax
  @sales_tax
end

#service_periodObject

Returns the value of attribute service_period.



33
34
35
# File 'lib/beanie/sales_order_item.rb', line 33

def service_period
  @service_period
end

#stateObject

Returns the value of attribute state.



32
33
34
# File 'lib/beanie/sales_order_item.rb', line 32

def state
  @state
end

#unit_costObject

Returns the value of attribute unit_cost.



33
34
35
# File 'lib/beanie/sales_order_item.rb', line 33

def unit_cost
  @unit_cost
end

Instance Method Details

#active?Boolean

Is this item active?

Returns:

  • (Boolean)


96
97
98
# File 'lib/beanie/sales_order_item.rb', line 96

def active?
  state == STATE_READY
end

#blocked?Boolean

Is this item blocked?

Returns:

  • (Boolean)


102
103
104
# File 'lib/beanie/sales_order_item.rb', line 102

def blocked?
  state == STATE_BLOCKED
end

#one_off?Boolean

Is this a one-off rather than a time-based item?

Returns:

  • (Boolean)


108
109
110
# File 'lib/beanie/sales_order_item.rb', line 108

def one_off?
  self.service_period == SERVICE_PERIOD_ONEOFF
end

#period_nameObject

Service period name



90
91
92
# File 'lib/beanie/sales_order_item.rb', line 90

def period_name
  SERVICE_PERIOD_NAMES[service_period][0]
end

#private_dataObject

Get the private data



114
115
116
117
# File 'lib/beanie/sales_order_item.rb', line 114

def private_data
  response = SalesOrderItem.get(:url => "/sales_order_items/#{@id}/private_data")
  response["data"]
end

#private_data=(data) ⇒ Object

Update/set the private data



121
122
123
124
# File 'lib/beanie/sales_order_item.rb', line 121

def private_data=(data)
  pdata = {:data => data}
  response = SalesOrderItem.post(pdata, :url => "/sales_order_items/#{@id}/private_data")
end

#state_nameObject

Pretty name for the state



84
85
86
# File 'lib/beanie/sales_order_item.rb', line 84

def state_name
  STATE_NAMES[state][0]
end