Class: WeighflowCli::CliWeights

Inherits:
Thor
  • Object
show all
Includes:
Rendering
Defined in:
lib/weighflow_cli/cli_weights.rb

Instance Method Summary collapse

Methods included from Rendering

#options_renderer

Instance Method Details

#createObject



94
95
96
97
98
99
100
# File 'lib/weighflow_cli/cli_weights.rb', line 94

def create 
  weight_params = JSON.parse(File.read(options[:file]), symbolize_names: true)
  puts weight_params
  
  options_renderer(WeighflowCli.create_weight(params: weight_params), options) 
  #options_renderer(options, options) 
end

#from_index(index_id) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/weighflow_cli/cli_weights.rb', line 11

def from_index(index_id)
  raise 'index_id required' unless index_id
  index = WeighflowCli.find_order(index_id)
  raise 'index not found for id' unless index && index.data
  #
  # parse external id parts
  order_type, transport, io, location, order_num, lin =  index.data[:external_unique_id].to_s.split('-')
  #
  # correct for diff in type between order and weight processor
  order_type = 'Inventory' if order_type == 'BulkInventory'
  #
  weight_params = {
    io: index.data[:i_o],
    order_id: index.data[:order_id],
    order_type: order_type,
    gross_weight: options[:gross].to_i,
    tare_weight: options[:tare].to_i,
    weighed_at: Time.now.round,
    certificate_number: options[:certificate].to_s
  }

  options_renderer(WeighflowCli.create_weight(params: weight_params), options) 
end

#listObject



62
63
64
# File 'lib/weighflow_cli/cli_weights.rb', line 62

def list
  options_renderer(WeighflowCli.weights, options) 
end

#template(index_id) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/weighflow_cli/cli_weights.rb', line 37

def template(index_id)
  aise 'index_id required' unless index_id
  index = WeighflowCli.find_order(index_id)
  raise 'index not found for id' unless index && index.data
  #
  # parse external id parts
  order_type, transport, io, location, order_num, lin =  index.data[:external_unique_id].to_s.split('-')
  #
  # correct for diff in type between order and weight processor
  order_type = 'Inventory' if order_type == 'BulkInventory'
  #
  weight_params = {
    io: index.data[:i_o],
    order_id: index.data[:order_id],
    order_type: order_type,
    gross_weight: 0,
    tare_weight: 0,
    weighed_at: Time.now.round,
    certificate_number: "{cert number}"
  }
  options_renderer(weight_params, options) 
end

#voidObject



106
107
108
# File 'lib/weighflow_cli/cli_weights.rb', line 106

def void 
  options_renderer(WeighflowCli.void_weight(options[:weight_id], options[:reason]), options) 
end