Class: AppCommand::DummyOrder
- Inherits:
-
Convoy::ActionCommand::Base
- Object
- Convoy::ActionCommand::Base
- AppCommand::DummyOrder
- Defined in:
- lib/routes/dummy_order.rb
Constant Summary collapse
- SALES_ORDER =
'so'- SALES_CREDIT =
'sc'- PURCHASE_ORDER =
'po'- PURCHASE_CREDIT =
'pc'
Instance Method Summary collapse
- #create_order(type = SALES_ORDER) ⇒ Object
- #error_invalid_quantity ⇒ Object
- #error_multi_order ⇒ Object
- #execute ⇒ Object
- #opts_routing ⇒ Object
- #opts_validate ⇒ Object
- #validate_type(type) ⇒ Object
Instance Method Details
#create_order(type = SALES_ORDER) ⇒ Object
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 |
# File 'lib/routes/dummy_order.rb', line 68 def create_order(type = SALES_ORDER) validate_type(type) post_data = { 'orderTypeCode' => 'SO', 'reference' => 'order#001', 'priceListId' => 2, 'invoices' => [ { 'taxDate' => '2014-10-19T12:57:25+00:00' } ], 'placedOn' => '2014-10-19T11:12:24.000+01:00', 'orderStatus' => { 'orderStatusId' => 1 }, 'delivery' => { 'deliveryDate' => '2014-10-19T11:12:24.000+01:00', 'shippingMethodId' => App::MySQL::get_random_shipping_id }, 'currency' => { 'orderCurrencyCode' => 'GBP' }, 'parties' => { 'customer' => { 'contactId' => App::MySQL::get_random_customer_id } }, 'assignment' => { 'current' => { 'channelId' => 1, 'leadSourceId' => 1, 'staffOwnerContactId' => 4 } } }.to_json puts puts "\x1B[33m#{post_data}\x1B[0m" puts exit begin response = RestClient.post( "http://#{App::Config.param(App::Config::VM_IP)}:#{App::Enum::PORT_ORDER_SERVICE}/order-service/app/order", post_data, :content_type => :json, :accept => :json, :'account-version' => 'admindev', :'effective-user-id' => 6 ) rescue puts response ensure puts response end end |
#error_invalid_quantity ⇒ Object
143 144 145 146 |
# File 'lib/routes/dummy_order.rb', line 143 def error_invalid_quantity puts "You can only create between 1-50 orders at a time. You tried to create #{@opts[:times]}." exit end |
#error_multi_order ⇒ Object
138 139 140 141 |
# File 'lib/routes/dummy_order.rb', line 138 def error_multi_order puts "You can only create \x1B[35mONE\x1B[0m type of order at the time. Please specify \x1B[35mONLY ONE\x1B[0m of the following: \x1B[90m-s, -S, -p, -P\x1B[0m" exit end |
#execute ⇒ Object
13 14 15 16 17 18 19 20 |
# File 'lib/routes/dummy_order.rb', line 13 def execute @opts = # @database = App::MySQL::get_database_connection opts_validate opts_routing end |
#opts_routing ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/routes/dummy_order.rb', line 52 def opts_routing if @opts[:salesOrder] create_order(SALES_ORDER) elsif @opts[:salesCredit] create_order(SALES_CREDIT) elsif @opts[:purchaseOrder] create_order(PURCHASE_ORDER) elsif @opts[:purchaseCredit] create_order(PURCHASE_CREDIT) else create_order(SALES_ORDER) end end |
#opts_validate ⇒ Object
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 |
# File 'lib/routes/dummy_order.rb', line 22 def opts_validate if @opts[:salesOrder] if @opts[:salesCredit] || @opts[:purchaseOrder] || @opts[:purchaseCredit] error_multi_order end elsif @opts[:salesCredit] if @opts[:salesOrder] || @opts[:purchaseOrder] || @opts[:purchaseCredit] error_multi_order end elsif @opts[:purchaseOrder] if @opts[:salesCredit] || @opts[:salesOrder] || @opts[:purchaseCredit] error_multi_order end elsif @opts[:purchaseCredit] if @opts[:salesCredit] || @opts[:salesOrder] || @opts[:purchaseOrder] error_multi_order end else @opts[:salesOrder] = true end if @opts[:times].nil? @opts[:times] = 1 elsif @opts[:times] <= 0 || @opts[:times] > 50 error_invalid_quantity end end |
#validate_type(type) ⇒ Object
127 128 129 130 131 132 133 134 135 136 |
# File 'lib/routes/dummy_order.rb', line 127 def validate_type(type) unless [ SALES_ORDER, SALES_CREDIT, PURCHASE_ORDER, PURCHASE_CREDIT ].include?(type) raise RuntimeError, 'Invalid order type.' end end |