spree_backend 3.2.9 → 3.3.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (196) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/javascripts/spree/backend/admin.js +16 -15
  3. data/app/assets/javascripts/spree/backend/checkouts/edit.js +25 -26
  4. data/app/assets/javascripts/spree/backend/general_settings.js.coffee +10 -12
  5. data/app/assets/javascripts/spree/backend/payments/edit.js.coffee +4 -6
  6. data/app/assets/javascripts/spree/backend/returns/return_item_selection.js +7 -1
  7. data/app/assets/javascripts/spree/backend/stock_transfer.js.coffee +4 -1
  8. data/app/assets/javascripts/spree/backend/user_picker.js +3 -1
  9. data/app/assets/javascripts/spree/backend.js +3 -3
  10. data/app/controllers/spree/admin/countries_controller.rb +1 -0
  11. data/app/controllers/spree/admin/log_entries_controller.rb +2 -2
  12. data/app/controllers/spree/admin/orders/customer_details_controller.rb +5 -6
  13. data/app/controllers/spree/admin/orders_controller.rb +4 -4
  14. data/app/controllers/spree/admin/payments_controller.rb +21 -10
  15. data/app/controllers/spree/admin/products_controller.rb +5 -0
  16. data/app/controllers/spree/admin/promotion_rules_controller.rb +11 -7
  17. data/app/controllers/spree/admin/stock_transfers_controller.rb +1 -1
  18. data/app/controllers/spree/admin/taxons_controller.rb +31 -23
  19. data/app/helpers/spree/admin/base_helper.rb +1 -1
  20. data/app/helpers/spree/admin/navigation_helper.rb +10 -4
  21. data/app/views/spree/admin/adjustments/_adjustments_table.html.erb +2 -2
  22. data/app/views/spree/admin/general_settings/edit.html.erb +8 -8
  23. data/app/views/spree/admin/images/_form.html.erb +2 -2
  24. data/app/views/spree/admin/images/edit.html.erb +2 -2
  25. data/app/views/spree/admin/images/new.html.erb +1 -1
  26. data/app/views/spree/admin/option_types/_form.html.erb +2 -2
  27. data/app/views/spree/admin/option_types/index.html.erb +4 -4
  28. data/app/views/spree/admin/orders/_line_items.html.erb +40 -38
  29. data/app/views/spree/admin/orders/_shipment.html.erb +77 -76
  30. data/app/views/spree/admin/orders/customer_details/_form.html.erb +5 -5
  31. data/app/views/spree/admin/orders/index.html.erb +16 -16
  32. data/app/views/spree/admin/payment_methods/_form.html.erb +2 -2
  33. data/app/views/spree/admin/payments/_list.html.erb +1 -1
  34. data/app/views/spree/admin/products/_add_stock_form.html.erb +3 -3
  35. data/app/views/spree/admin/products/_form.html.erb +16 -16
  36. data/app/views/spree/admin/products/index.html.erb +4 -4
  37. data/app/views/spree/admin/products/new.html.erb +8 -8
  38. data/app/views/spree/admin/promotion_categories/index.html.erb +3 -3
  39. data/app/views/spree/admin/promotions/_form.html.erb +3 -3
  40. data/app/views/spree/admin/promotions/_promotion_rule.html.erb +1 -1
  41. data/app/views/spree/admin/promotions/actions/_create_adjustment.html.erb +2 -2
  42. data/app/views/spree/admin/promotions/actions/_create_item_adjustments.html.erb +2 -2
  43. data/app/views/spree/admin/promotions/actions/_create_line_items.html.erb +2 -4
  44. data/app/views/spree/admin/promotions/edit.html.erb +3 -3
  45. data/app/views/spree/admin/promotions/index.html.erb +6 -6
  46. data/app/views/spree/admin/promotions/rules/_item_total.html.erb +2 -2
  47. data/app/views/spree/admin/promotions/rules/_option_value.html.erb +4 -4
  48. data/app/views/spree/admin/properties/_form.html.erb +2 -2
  49. data/app/views/spree/admin/properties/index.html.erb +6 -6
  50. data/app/views/spree/admin/prototypes/index.html.erb +4 -4
  51. data/app/views/spree/admin/reimbursement_types/_form.html.erb +4 -4
  52. data/app/views/spree/admin/reimbursements/edit.html.erb +1 -1
  53. data/app/views/spree/admin/return_authorizations/_form.html.erb +13 -1
  54. data/app/views/spree/admin/return_index/customer_returns.html.erb +2 -2
  55. data/app/views/spree/admin/return_index/return_authorizations.html.erb +5 -5
  56. data/app/views/spree/admin/shared/_content_header.html.erb +2 -2
  57. data/app/views/spree/admin/shared/_header.html.erb +2 -2
  58. data/app/views/spree/admin/shared/_index_table_options.html.erb +2 -2
  59. data/app/views/spree/admin/shared/_order_summary.html.erb +1 -1
  60. data/app/views/spree/admin/shared/_table_filter.html.erb +1 -1
  61. data/app/views/spree/admin/shared/_translations.html.erb +0 -1
  62. data/app/views/spree/admin/shared/_update_order_state.js.erb +1 -1
  63. data/app/views/spree/admin/shipping_methods/_form.html.erb +10 -10
  64. data/app/views/spree/admin/state_changes/index.html.erb +3 -3
  65. data/app/views/spree/admin/states/_form.html.erb +2 -2
  66. data/app/views/spree/admin/stock_locations/_form.html.erb +2 -2
  67. data/app/views/spree/admin/stock_locations/_transfer_stock_form.html.erb +4 -4
  68. data/app/views/spree/admin/stock_transfers/index.html.erb +3 -3
  69. data/app/views/spree/admin/stock_transfers/new.html.erb +2 -2
  70. data/app/views/spree/admin/store_credits/index.html.erb +1 -1
  71. data/app/views/spree/admin/tax_rates/_form.html.erb +2 -2
  72. data/app/views/spree/admin/taxonomies/_list.html.erb +2 -2
  73. data/app/views/spree/admin/taxonomies/{edit.erb → edit.html.erb} +0 -0
  74. data/app/views/spree/admin/taxonomies/index.html.erb +2 -2
  75. data/app/views/spree/admin/taxons/_form.html.erb +5 -5
  76. data/app/views/spree/admin/taxons/edit.html.erb +3 -0
  77. data/app/views/spree/admin/trackers/_form.html.erb +2 -2
  78. data/app/views/spree/admin/users/_addresses_form.html.erb +2 -2
  79. data/app/views/spree/admin/users/_form.html.erb +2 -2
  80. data/app/views/spree/admin/users/_user_page_actions.html.erb +1 -1
  81. data/app/views/spree/admin/users/index.html.erb +5 -5
  82. data/app/views/spree/admin/users/items.html.erb +1 -1
  83. data/app/views/spree/admin/users/orders.html.erb +1 -1
  84. data/app/views/spree/admin/variants/_form.html.erb +2 -2
  85. data/app/views/spree/admin/zones/_form.html.erb +2 -2
  86. data/app/views/spree/layouts/admin.html.erb +3 -3
  87. data/config/initializers/assets.rb +1 -1
  88. data/lib/spree/backend/engine.rb +0 -1
  89. data/spec/controllers/spree/admin/base_controller_spec.rb +46 -0
  90. data/spec/controllers/spree/admin/customer_returns_controller_spec.rb +185 -0
  91. data/spec/controllers/spree/admin/general_settings_controller_spec.rb +41 -0
  92. data/spec/controllers/spree/admin/missing_products_controller_spec.rb +18 -0
  93. data/spec/controllers/spree/admin/orders/customer_details_controller_spec.rb +199 -0
  94. data/spec/controllers/spree/admin/orders_controller_spec.rb +296 -0
  95. data/spec/controllers/spree/admin/payment_methods_controller_spec.rb +64 -0
  96. data/spec/controllers/spree/admin/payments_controller_spec.rb +97 -0
  97. data/spec/controllers/spree/admin/products_controller_spec.rb +137 -0
  98. data/spec/controllers/spree/admin/promotion_actions_controller_spec.rb +21 -0
  99. data/spec/controllers/spree/admin/promotion_rules_controller_spec.rb +21 -0
  100. data/spec/controllers/spree/admin/promotions_controller_spec.rb +44 -0
  101. data/spec/controllers/spree/admin/refunds_controller_spec.rb +32 -0
  102. data/spec/controllers/spree/admin/reimbursements_controller_spec.rb +74 -0
  103. data/spec/controllers/spree/admin/reports_controller_spec.rb +42 -0
  104. data/spec/controllers/spree/admin/resource_controller_spec.rb +252 -0
  105. data/spec/controllers/spree/admin/return_authorizations_controller_spec.rb +225 -0
  106. data/spec/controllers/spree/admin/return_index_controller_spec.rb +37 -0
  107. data/spec/controllers/spree/admin/return_items_controller_spec.rb +27 -0
  108. data/spec/controllers/spree/admin/shipping_methods_controller_spec.rb +14 -0
  109. data/spec/controllers/spree/admin/stock_items_controller_spec.rb +19 -0
  110. data/spec/controllers/spree/admin/stock_locations_controller_spec.rb +41 -0
  111. data/spec/controllers/spree/admin/stock_transfers_controller_spec.rb +41 -0
  112. data/spec/controllers/spree/admin/tax_categories_controller_spec.rb +34 -0
  113. data/spec/controllers/spree/admin/users_controller_spec.rb +161 -0
  114. data/spec/controllers/spree/admin/variants_controller_spec.rb +32 -0
  115. data/spec/features/admin/configuration/analytics_tracker_spec.rb +47 -0
  116. data/spec/features/admin/configuration/countries_spec.rb +24 -0
  117. data/spec/features/admin/configuration/general_settings_spec.rb +44 -0
  118. data/spec/features/admin/configuration/payment_methods_spec.rb +63 -0
  119. data/spec/features/admin/configuration/roles_spec.rb +47 -0
  120. data/spec/features/admin/configuration/shipping_methods_spec.rb +62 -0
  121. data/spec/features/admin/configuration/states_spec.rb +68 -0
  122. data/spec/features/admin/configuration/stock_locations_spec.rb +48 -0
  123. data/spec/features/admin/configuration/store_credit_categories_spec.rb +50 -0
  124. data/spec/features/admin/configuration/tax_categories_spec.rb +56 -0
  125. data/spec/features/admin/configuration/tax_rates_spec.rb +18 -0
  126. data/spec/features/admin/configuration/zones_spec.rb +39 -0
  127. data/spec/features/admin/homepage_spec.rb +89 -0
  128. data/spec/features/admin/locale_spec.rb +31 -0
  129. data/spec/features/admin/orders/adjustments_promotions_spec.rb +53 -0
  130. data/spec/features/admin/orders/adjustments_spec.rb +124 -0
  131. data/spec/features/admin/orders/cancelling_and_resuming_spec.rb +47 -0
  132. data/spec/features/admin/orders/customer_details_spec.rb +154 -0
  133. data/spec/features/admin/orders/line_items_spec.rb +51 -0
  134. data/spec/features/admin/orders/listing_spec.rb +224 -0
  135. data/spec/features/admin/orders/log_entries_spec.rb +55 -0
  136. data/spec/features/admin/orders/new_order_spec.rb +186 -0
  137. data/spec/features/admin/orders/order_details_spec.rb +660 -0
  138. data/spec/features/admin/orders/payments_spec.rb +244 -0
  139. data/spec/features/admin/orders/risk_analysis_spec.rb +48 -0
  140. data/spec/features/admin/orders/shipments_spec.rb +64 -0
  141. data/spec/features/admin/orders/state_changes_spec.rb +21 -0
  142. data/spec/features/admin/products/edit/images_spec.rb +86 -0
  143. data/spec/features/admin/products/edit/products_spec.rb +56 -0
  144. data/spec/features/admin/products/edit/taxons_spec.rb +41 -0
  145. data/spec/features/admin/products/edit/variants_spec.rb +56 -0
  146. data/spec/features/admin/products/option_types_spec.rb +114 -0
  147. data/spec/features/admin/products/products_spec.rb +445 -0
  148. data/spec/features/admin/products/properties_spec.rb +147 -0
  149. data/spec/features/admin/products/prototypes_spec.rb +112 -0
  150. data/spec/features/admin/products/stock_management_spec.rb +124 -0
  151. data/spec/features/admin/products/taxonomies_spec.rb +52 -0
  152. data/spec/features/admin/products/variant_spec.rb +50 -0
  153. data/spec/features/admin/promotions/adjustments_spec.rb +258 -0
  154. data/spec/features/admin/promotions/option_value_rule_spec.rb +70 -0
  155. data/spec/features/admin/promotions/tiered_calculator_spec.rb +70 -0
  156. data/spec/features/admin/refund_reasons/refund_reasons_spec.rb +57 -0
  157. data/spec/features/admin/reimbursement_type/edit_reimbursement_type_spec.rb +36 -0
  158. data/spec/features/admin/reimbursement_type/new_reimbursement_type_spec.rb +62 -0
  159. data/spec/features/admin/reports_spec.rb +61 -0
  160. data/spec/features/admin/return_authorization_reasons/return_authorization_reasons_spec.rb +63 -0
  161. data/spec/features/admin/returns/customer_returns_spec.rb +80 -0
  162. data/spec/features/admin/returns/return_authorizations_spec.rb +152 -0
  163. data/spec/features/admin/stock_transfer_spec.rb +91 -0
  164. data/spec/features/admin/store_credits_spec.rb +93 -0
  165. data/spec/features/admin/taxons_spec.rb +53 -0
  166. data/spec/features/admin/users_spec.rb +286 -0
  167. data/spec/helpers/admin/base_helper_spec.rb +30 -0
  168. data/spec/helpers/admin/navigation_helper_spec.rb +111 -0
  169. data/spec/helpers/admin/promotion_rules_helper_spec.rb +12 -0
  170. data/spec/helpers/admin/stock_movements_helper_spec.rb +30 -0
  171. data/spec/models/spree/resource_spec.rb +48 -0
  172. data/spec/routing/admin_path_spec.rb +22 -0
  173. data/spec/spec_helper.rb +144 -0
  174. data/spec/support/appear_before_matcher.rb +8 -0
  175. data/spec/support/ror_ringer.jpeg +0 -0
  176. data/spec/test_views/spree/admin/submodule/posts/edit.html.erb +1 -0
  177. data/spec/test_views/spree/admin/submodule/posts/new.html.erb +1 -0
  178. data/spec/test_views/spree/admin/widgets/edit.html.erb +1 -0
  179. data/spec/test_views/spree/admin/widgets/new.html.erb +1 -0
  180. data/spree_backend.gemspec +4 -4
  181. data/vendor/assets/javascripts/jquery.jstree/jquery.jstree.js +130 -154
  182. metadata +106 -29
  183. data/vendor/assets/images/jquery-ui/ui-bg_flat_0_aaaaaa_40x100.png +0 -0
  184. data/vendor/assets/images/jquery-ui/ui-bg_flat_0_eeeeee_40x100.png +0 -0
  185. data/vendor/assets/images/jquery-ui/ui-bg_flat_55_ffffff_40x100.png +0 -0
  186. data/vendor/assets/images/jquery-ui/ui-bg_flat_75_ffffff_40x100.png +0 -0
  187. data/vendor/assets/images/jquery-ui/ui-bg_glass_65_ffffff_1x400.png +0 -0
  188. data/vendor/assets/images/jquery-ui/ui-bg_highlight-soft_100_f6f6f6_1x100.png +0 -0
  189. data/vendor/assets/images/jquery-ui/ui-bg_highlight-soft_25_0073ea_1x100.png +0 -0
  190. data/vendor/assets/images/jquery-ui/ui-bg_highlight-soft_50_dddddd_1x100.png +0 -0
  191. data/vendor/assets/images/jquery-ui/ui-icons_0073ea_256x240.png +0 -0
  192. data/vendor/assets/images/jquery-ui/ui-icons_454545_256x240.png +0 -0
  193. data/vendor/assets/images/jquery-ui/ui-icons_666666_256x240.png +0 -0
  194. data/vendor/assets/images/jquery-ui/ui-icons_ff0084_256x240.png +0 -0
  195. data/vendor/assets/images/jquery-ui/ui-icons_ffffff_256x240.png +0 -0
  196. data/vendor/assets/stylesheets/jquery-ui.datepicker.css.erb +0 -357
@@ -0,0 +1,660 @@
1
+ # coding: utf-8
2
+ require 'spec_helper'
3
+
4
+ describe "Order Details", type: :feature, js: true do
5
+ let!(:stock_location) { create(:stock_location_with_items) }
6
+ let!(:product) { create(:product, name: 'spree t-shirt', price: 20.00) }
7
+ let(:order) { create(:order, state: 'complete', completed_at: "2011-02-01 12:36:15", number: "R100") }
8
+ let(:state) { create(:state) }
9
+ let!(:shipping_method) { create(:shipping_method, name: "Default") }
10
+
11
+ before do
12
+ order.shipments.create!(stock_location_id: stock_location.id)
13
+ order.contents.add(product.master, 2)
14
+ end
15
+
16
+ context 'as Admin' do
17
+ stub_authorization!
18
+
19
+ context "cart edit page" do
20
+ before do
21
+ product.master.stock_items.first.update_column(:count_on_hand, 100)
22
+ visit spree.cart_admin_order_path(order)
23
+ end
24
+
25
+ it "should allow me to edit order details" do
26
+ expect(page).to have_content("spree t-shirt")
27
+ expect(page).to have_content("$40.00")
28
+
29
+ within_row(1) do
30
+ click_icon :edit
31
+ fill_in "quantity", with: "1"
32
+ end
33
+ click_icon :save
34
+
35
+ within("#order_total") do
36
+ expect(page).to have_content("$20.00")
37
+ end
38
+ end
39
+
40
+ it "can add an item to a shipment" do
41
+ select2_search "spree t-shirt", from: Spree.t(:name_or_sku)
42
+ within("table.stock-levels") do
43
+ fill_in "variant_quantity", with: 2
44
+ click_icon :add
45
+ end
46
+
47
+ within("#order_total") do
48
+ expect(page).to have_content("$80.00")
49
+ end
50
+ end
51
+
52
+ it "can remove an item from a shipment" do
53
+ expect(page).to have_content("spree t-shirt")
54
+
55
+ within_row(1) do
56
+ accept_alert do
57
+ click_icon :delete
58
+ end
59
+ end
60
+
61
+ # Click "ok" on confirmation dialog
62
+ expect(page).not_to have_content("spree t-shirt")
63
+ end
64
+
65
+ # Regression test for #3862
66
+ it "can cancel removing an item from a shipment" do
67
+ expect(page).to have_content("spree t-shirt")
68
+
69
+ within_row(1) do
70
+ # Click "cancel" on confirmation dialog
71
+ dismiss_alert do
72
+ click_icon :delete
73
+ end
74
+ end
75
+
76
+ expect(page).to have_content("spree t-shirt")
77
+ end
78
+
79
+ it "can add tracking information" do
80
+ visit spree.edit_admin_order_path(order)
81
+
82
+ within(".show-tracking") do
83
+ click_icon :edit
84
+ end
85
+ fill_in "tracking", with: "FOOBAR"
86
+ click_icon :save
87
+
88
+ expect(page).not_to have_css("input[name=tracking]")
89
+ expect(page).to have_content("Tracking: FOOBAR")
90
+ end
91
+
92
+ it "can change the shipping method" do
93
+ order = create(:completed_order_with_totals)
94
+ visit spree.edit_admin_order_path(order)
95
+ within("table.table tr.show-method") do
96
+ click_icon :edit
97
+ end
98
+ select2 "Default", from: "Shipping Method"
99
+ click_icon :save
100
+
101
+ expect(page).not_to have_css('#selected_shipping_rate_id')
102
+ expect(page).to have_content("Default")
103
+ end
104
+
105
+ it "can assign a back-end only shipping method" do
106
+ create(:shipping_method, name: "Backdoor", display_on: "back_end")
107
+ order = create(
108
+ :completed_order_with_totals,
109
+ shipping_method_filter: Spree::ShippingMethod::DISPLAY_ON_BACK_END
110
+ )
111
+ visit spree.edit_admin_order_path(order)
112
+ within("table tr.show-method") do
113
+ click_icon :edit
114
+ end
115
+ select2 "Backdoor", from: "Shipping Method"
116
+ click_icon :save
117
+
118
+ expect(page).not_to have_css('#selected_shipping_rate_id')
119
+ expect(page).to have_content("Backdoor")
120
+ end
121
+
122
+ it "will show the variant sku", js: false do
123
+ order = create(:completed_order_with_totals)
124
+ visit spree.edit_admin_order_path(order)
125
+ sku = order.line_items.first.variant.sku
126
+ expect(page).to have_content("SKU: #{sku}")
127
+ end
128
+
129
+ context "with special_instructions present" do
130
+ before(:each) do
131
+ order.update_column(:special_instructions, "Very special instructions here")
132
+ end
133
+
134
+ it "will show the special_instructions", js: false do
135
+ visit spree.edit_admin_order_path(order)
136
+ expect(page).to have_content("Very special instructions here")
137
+ end
138
+ end
139
+
140
+ context 'when not tracking inventory' do
141
+ let(:tote) { create(:product, name: "Tote", price: 15.00) }
142
+
143
+ context "variant doesn't track inventory" do
144
+ before do
145
+ tote.master.update_column :track_inventory, false
146
+ # make sure there's no stock level for any item
147
+ tote.master.stock_items.update_all count_on_hand: 0, backorderable: false
148
+ end
149
+
150
+ it "adds variant to order just fine" do
151
+ select2_search tote.name, from: Spree.t(:name_or_sku)
152
+ within("table.stock-levels") do
153
+ fill_in "variant_quantity", with: 1
154
+ click_icon :add
155
+ end
156
+
157
+ wait_for_ajax
158
+
159
+ within(".line-items") do
160
+ expect(page).to have_content(tote.name)
161
+ end
162
+ end
163
+ end
164
+
165
+ context "site doesn't track inventory" do
166
+ before do
167
+ Spree::Config[:track_inventory_levels] = false
168
+ tote.master.update_column(:track_inventory, true)
169
+ # make sure there's no stock level for any item
170
+ tote.master.stock_items.update_all count_on_hand: 0, backorderable: true
171
+ end
172
+
173
+ it "adds variant to order just fine" do
174
+ select2_search tote.name, from: Spree.t(:name_or_sku)
175
+ within("table.stock-levels") do
176
+ fill_in "variant_quantity", with: 1
177
+ click_icon :add
178
+ end
179
+
180
+ wait_for_ajax
181
+
182
+ within(".line-items") do
183
+ expect(page).to have_content(tote.name)
184
+ end
185
+ end
186
+
187
+ after { Spree::Config[:track_inventory_levels] = true }
188
+ end
189
+ end
190
+
191
+ context "variant out of stock and not backorderable" do
192
+ before do
193
+ product.master.stock_items.first.update_column(:backorderable, false)
194
+ product.master.stock_items.first.update_column(:count_on_hand, 0)
195
+ end
196
+
197
+ it "displays out of stock instead of add button" do
198
+ select2_search product.name, from: Spree.t(:name_or_sku)
199
+
200
+ within("table.stock-levels") do
201
+ expect(page).to have_content(Spree.t(:out_of_stock))
202
+ end
203
+ end
204
+ end
205
+ end
206
+
207
+ context 'Shipment edit page' do
208
+ let!(:stock_location2) { create(:stock_location_with_items, name: 'Clarksville') }
209
+
210
+ before do
211
+ product.master.stock_items.first.update_column(:backorderable, true)
212
+ product.master.stock_items.first.update_column(:count_on_hand, 100)
213
+ product.master.stock_items.last.update_column(:count_on_hand, 100)
214
+ end
215
+
216
+ context 'splitting to location' do
217
+ before { visit spree.edit_admin_order_path(order) }
218
+ # can not properly implement until poltergeist supports checking alert text
219
+ # see https://github.com/teampoltergeist/poltergeist/pull/516
220
+ it 'should warn you if you have not selected a location or shipment'
221
+
222
+ context 'there is enough stock at the other location' do
223
+ it 'should allow me to make a split' do
224
+ expect(order.shipments.count).to eq(1)
225
+ expect(order.shipments.first.inventory_units_for(product.master).count).to eq(2)
226
+
227
+ within_row(1) { click_icon 'split' }
228
+ targetted_select2 stock_location2.name, from: '#s2id_item_stock_location'
229
+ click_icon :save
230
+
231
+ wait_for_ajax
232
+ order.reload
233
+
234
+ expect(order.shipments.count).to eq(2)
235
+ expect(order.shipments.last.backordered?).to eq(false)
236
+ expect(order.shipments.first.inventory_units_for(product.master).count).to eq(1)
237
+ expect(order.shipments.last.inventory_units_for(product.master).count).to eq(1)
238
+ end
239
+
240
+ it 'should allow me to make a transfer via splitting off all stock' do
241
+ expect(order.shipments.first.stock_location.id).to eq(stock_location.id)
242
+
243
+ within_row(1) { click_icon 'split' }
244
+ targetted_select2 stock_location2.name, from: '#s2id_item_stock_location'
245
+ fill_in 'item_quantity', with: 2
246
+ click_icon :save
247
+
248
+ wait_for_ajax
249
+ order.reload
250
+
251
+ expect(order.shipments.count).to eq(1)
252
+ expect(order.shipments.last.backordered?).to eq(false)
253
+ expect(order.shipments.first.inventory_units_for(product.master).count).to eq(2)
254
+ expect(order.shipments.first.stock_location.id).to eq(stock_location2.id)
255
+ end
256
+
257
+ it 'should allow me to split more than I have if available there' do
258
+ expect(order.shipments.first.stock_location.id).to eq(stock_location.id)
259
+
260
+ within_row(1) { click_icon 'split' }
261
+ targetted_select2 stock_location2.name, from: '#s2id_item_stock_location'
262
+ fill_in 'item_quantity', with: 5
263
+ click_icon :save
264
+
265
+ wait_for_ajax
266
+ order.reload
267
+
268
+ expect(order.shipments.count).to eq(1)
269
+ expect(order.shipments.last.backordered?).to eq(false)
270
+ expect(order.shipments.first.inventory_units_for(product.master).count).to eq(5)
271
+ expect(order.shipments.first.stock_location.id).to eq(stock_location2.id)
272
+ end
273
+
274
+ it 'should not split anything if the input quantity is garbage' do
275
+ expect(order.shipments.first.stock_location.id).to eq(stock_location.id)
276
+
277
+ within_row(1) { click_icon 'split' }
278
+ targetted_select2 stock_location2.name, from: '#s2id_item_stock_location'
279
+ fill_in 'item_quantity', with: 'ff'
280
+ click_icon :save
281
+
282
+ wait_for_ajax
283
+
284
+ expect(order.shipments.count).to eq(1)
285
+ expect(order.shipments.first.inventory_units_for(product.master).count).to eq(2)
286
+ expect(order.shipments.first.stock_location.id).to eq(stock_location.id)
287
+ end
288
+
289
+ it 'should not allow less than or equal to zero qty' do
290
+ expect(order.shipments.first.stock_location.id).to eq(stock_location.id)
291
+
292
+ within_row(1) { click_icon 'split' }
293
+ targetted_select2 stock_location2.name, from: '#s2id_item_stock_location'
294
+ fill_in 'item_quantity', with: 0
295
+ click_icon :save
296
+
297
+ wait_for_ajax
298
+
299
+ expect(order.shipments.count).to eq(1)
300
+ expect(order.shipments.first.inventory_units_for(product.master).count).to eq(2)
301
+ expect(order.shipments.first.stock_location.id).to eq(stock_location.id)
302
+
303
+
304
+ fill_in 'item_quantity', with: -1
305
+ click_icon :save
306
+
307
+ wait_for_ajax
308
+
309
+ expect(order.shipments.count).to eq(1)
310
+ expect(order.shipments.first.inventory_units_for(product.master).count).to eq(2)
311
+ expect(order.shipments.first.stock_location.id).to eq(stock_location.id)
312
+ end
313
+
314
+ context 'A shipment has shipped' do
315
+
316
+ it 'should not show or let me back to the cart page, nor show the shipment edit buttons', js: false do
317
+ order = create(:order, state: 'payment')
318
+ order.shipments.create!(stock_location_id: stock_location.id, state: 'shipped')
319
+
320
+ visit spree.cart_admin_order_path(order)
321
+
322
+ expect(page.current_path).to eq(spree.edit_admin_order_path(order))
323
+ expect(page).not_to have_text 'Cart'
324
+ end
325
+
326
+ end
327
+ end
328
+
329
+ context 'there is not enough stock at the other location' do
330
+ context 'and it cannot backorder' do
331
+ it 'should not allow me to split stock' do
332
+ product.master.stock_items.last.update_column(:backorderable, false)
333
+ product.master.stock_items.last.update_column(:count_on_hand, 0)
334
+
335
+ within_row(1) { click_icon 'split' }
336
+ targetted_select2 stock_location2.name, from: '#s2id_item_stock_location'
337
+ fill_in 'item_quantity', with: 2
338
+ click_icon :save
339
+
340
+ wait_for_ajax
341
+
342
+ expect(order.shipments.count).to eq(1)
343
+ expect(order.shipments.first.inventory_units_for(product.master).count).to eq(2)
344
+ expect(order.shipments.first.stock_location.id).to eq(stock_location.id)
345
+ end
346
+
347
+ end
348
+
349
+ context 'but it can backorder' do
350
+ it 'should allow me to split and backorder the stock' do
351
+ product.master.stock_items.last.update_column(:count_on_hand, 0)
352
+ product.master.stock_items.last.update_column(:backorderable, true)
353
+
354
+ within_row(1) { click_icon 'split' }
355
+ targetted_select2 stock_location2.name, from: '#s2id_item_stock_location'
356
+ fill_in 'item_quantity', with: 2
357
+ click_icon :save
358
+
359
+ wait_for_ajax
360
+ order.reload
361
+
362
+ expect(order.shipments.count).to eq(1)
363
+ expect(order.shipments.first.inventory_units_for(product.master).count).to eq(2)
364
+ expect(order.shipments.first.stock_location.id).to eq(stock_location2.id)
365
+ end
366
+ end
367
+ end
368
+
369
+ context 'multiple items in cart' do
370
+ it 'should have no problem splitting if multiple items are in the from shipment' do
371
+ order.contents.add(create(:variant), 2)
372
+ expect(order.shipments.count).to eq(1)
373
+ expect(order.shipments.first.manifest.count).to eq(2)
374
+
375
+ within_row(1) { click_icon 'split' }
376
+ targetted_select2 stock_location2.name, from: '#s2id_item_stock_location'
377
+ click_icon :save
378
+
379
+ wait_for_ajax
380
+ order.reload
381
+
382
+ expect(order.shipments.count).to eq(2)
383
+ expect(order.shipments.last.backordered?).to eq(false)
384
+ expect(order.shipments.first.inventory_units_for(product.master).count).to eq(1)
385
+ expect(order.shipments.last.inventory_units_for(product.master).count).to eq(1)
386
+ end
387
+ end
388
+
389
+ context 'when not tracking inventory' do
390
+ let(:tote) { create(:product, name: "Tote", price: 15.00) }
391
+
392
+ context "variant doesn't track inventory" do
393
+ before do
394
+ tote.master.update_column :track_inventory, false
395
+ # make sure there's no stock level for any item
396
+ tote.master.stock_items.update_all count_on_hand: 0, backorderable: false
397
+ end
398
+
399
+ it "adds variant to order just fine" do
400
+ select2_search tote.name, from: Spree.t(:name_or_sku)
401
+ within("table.stock-levels") do
402
+ fill_in "stock_item_quantity", with: 1
403
+ click_icon :add
404
+ end
405
+
406
+ wait_for_ajax
407
+
408
+ within("[data-hook=admin_order_form_fields]") do
409
+ expect(page).to have_content(tote.name)
410
+ end
411
+ end
412
+ end
413
+
414
+ context "site doesn't track inventory" do
415
+ before do
416
+ Spree::Config[:track_inventory_levels] = false
417
+ tote.master.update_column(:track_inventory, true)
418
+ # make sure there's no stock level for any item
419
+ tote.master.stock_items.update_all count_on_hand: 0, backorderable: true
420
+ end
421
+
422
+ it "adds variant to order just fine" do
423
+ select2_search tote.name, from: Spree.t(:name_or_sku)
424
+ within("table.stock-levels") do
425
+ fill_in "stock_item_quantity", with: 1
426
+ click_icon :add
427
+ end
428
+
429
+ wait_for_ajax
430
+
431
+ within("[data-hook=admin_order_form_fields]") do
432
+ expect(page).to have_content(tote.name)
433
+ end
434
+ end
435
+
436
+ after { Spree::Config[:track_inventory_levels] = true }
437
+ end
438
+ end
439
+
440
+ context "variant out of stock and not backorderable" do
441
+ before do
442
+ product.master.stock_items.first.update_column(:backorderable, false)
443
+ product.master.stock_items.first.update_column(:count_on_hand, 0)
444
+ end
445
+
446
+ it "displays out of stock instead of add button" do
447
+ select2_search product.name, from: Spree.t(:name_or_sku)
448
+
449
+ within("table.stock-levels") do
450
+ expect(page).to have_content(Spree.t(:out_of_stock))
451
+ end
452
+ end
453
+ end
454
+ end
455
+
456
+ context 'splitting to shipment' do
457
+ before do
458
+ @shipment2 = order.shipments.create(stock_location_id: stock_location2.id)
459
+ visit spree.edit_admin_order_path(order)
460
+ end
461
+
462
+ it 'should delete the old shipment if enough are split off' do
463
+ expect(order.shipments.count).to eq(2)
464
+
465
+ within_row(1) { click_icon 'split' }
466
+ targetted_select2 @shipment2.number, from: '#s2id_item_stock_location'
467
+ fill_in 'item_quantity', with: 2
468
+ click_icon :save
469
+
470
+ wait_for_ajax
471
+ order.reload
472
+
473
+ expect(order.shipments.count).to eq(1)
474
+ expect(order.shipments.last.inventory_units_for(product.master).count).to eq(2)
475
+ end
476
+
477
+ context 'receiving shipment can not backorder' do
478
+ before { product.master.stock_items.last.update_column(:backorderable, false) }
479
+
480
+ it 'should not allow a split if the receiving shipment qty plus the incoming is greater than the count_on_hand' do
481
+ expect(order.shipments.count).to eq(2)
482
+
483
+ within_row(1) { click_icon 'split' }
484
+ targetted_select2 @shipment2.number, from: '#s2id_item_stock_location'
485
+ fill_in 'item_quantity', with: 1
486
+ click_icon :save
487
+
488
+ wait_for_ajax
489
+
490
+ within_row(1) { click_icon 'split' }
491
+ targetted_select2 @shipment2.number, from: '#s2id_item_stock_location'
492
+ fill_in 'item_quantity', with: 200
493
+ click_icon :save
494
+
495
+ wait_for_ajax
496
+
497
+ expect(order.shipments.count).to eq(2)
498
+ expect(order.shipments.first.inventory_units_for(product.master).count).to eq(1)
499
+ expect(order.shipments.last.inventory_units_for(product.master).count).to eq(1)
500
+ end
501
+
502
+ it 'should not allow a shipment to split stock to itself' do
503
+ within_row(1) { click_icon 'split' }
504
+ targetted_select2 order.shipments.first.number, from: '#s2id_item_stock_location'
505
+ fill_in 'item_quantity', with: 1
506
+ click_icon :save
507
+
508
+ wait_for_ajax
509
+
510
+ expect(order.shipments.count).to eq(2)
511
+ expect(order.shipments.first.inventory_units_for(product.master).count).to eq(2)
512
+ end
513
+
514
+ it 'should split fine if more than one line_item is in the receiving shipment' do
515
+ variant2 = create(:variant)
516
+ order.contents.add(variant2, 2, shipment: @shipment2)
517
+
518
+ within_row(1) { click_icon 'split' }
519
+ targetted_select2 @shipment2.number, from: '#s2id_item_stock_location'
520
+ fill_in 'item_quantity', with: 1
521
+ click_icon :save
522
+
523
+ wait_for_ajax
524
+
525
+ expect(order.shipments.count).to eq(2)
526
+ expect(order.shipments.first.inventory_units_for(product.master).count).to eq 1
527
+ expect(order.shipments.last.inventory_units_for(product.master).count).to eq 1
528
+ expect(order.shipments.first.inventory_units_for(variant2).count).to eq 0
529
+ expect(order.shipments.last.inventory_units_for(variant2).count).to eq 2
530
+ end
531
+ end
532
+
533
+ context 'receiving shipment can backorder' do
534
+ it 'should add more to the backorder' do
535
+ product.master.stock_items.last.update_column(:backorderable, true)
536
+ product.master.stock_items.last.update_column(:count_on_hand, 0)
537
+ expect(@shipment2.reload.backordered?).to eq(false)
538
+
539
+
540
+ within_row(1) { click_icon 'split' }
541
+ targetted_select2 @shipment2.number, from: '#s2id_item_stock_location'
542
+ fill_in 'item_quantity', with: 1
543
+ click_icon :save
544
+
545
+ wait_for_ajax
546
+
547
+ expect(@shipment2.reload.backordered?).to eq(true)
548
+
549
+ within_row(1) { click_icon 'split' }
550
+ targetted_select2 @shipment2.number, from: '#s2id_item_stock_location'
551
+ fill_in 'item_quantity', with: 1
552
+ click_icon :save
553
+
554
+ wait_for_ajax
555
+
556
+ expect(order.shipments.count).to eq(1)
557
+ expect(order.shipments.last.inventory_units_for(product.master).count).to eq(2)
558
+ expect(@shipment2.reload.backordered?).to eq(true)
559
+ end
560
+ end
561
+ end
562
+ end
563
+ end
564
+
565
+ context 'with only read permissions' do
566
+ before do
567
+ allow_any_instance_of(Spree::Admin::BaseController).to receive(:spree_current_user).and_return(nil)
568
+ end
569
+
570
+ custom_authorization! do |user|
571
+ can [:admin, :index, :read, :edit], Spree::Order
572
+ end
573
+
574
+ it "should not display forbidden links" do
575
+ visit spree.edit_admin_order_path(order)
576
+
577
+ expect(page).not_to have_button('cancel')
578
+ expect(page).not_to have_button('Resend')
579
+
580
+ # Order Tabs
581
+ expect(page).not_to have_link('Details')
582
+ expect(page).not_to have_link('Customer')
583
+ expect(page).not_to have_link('Adjustments')
584
+ expect(page).not_to have_link('Payments')
585
+ expect(page).not_to have_link('Returns')
586
+
587
+ # Order item actions
588
+ expect(page).not_to have_css('.delete-item')
589
+ expect(page).not_to have_css('.split-item')
590
+ expect(page).not_to have_css('.edit-item')
591
+ expect(page).not_to have_css('.edit-tracking')
592
+
593
+ expect(page).not_to have_css('#add-line-item')
594
+ end
595
+ end
596
+
597
+ context 'as Fakedispatch' do
598
+ custom_authorization! do |user|
599
+ # allow dispatch to :admin, :index, and :edit on Spree::Order
600
+ can [:admin, :edit, :index, :read], Spree::Order
601
+ # allow dispatch to :index, :show, :create and :update shipments on the admin
602
+ can [:admin, :manage, :read, :ship], Spree::Shipment
603
+ end
604
+
605
+ before do
606
+ allow(Spree.user_class).to receive(:find_by).
607
+ with(hash_including(:spree_api_key)).
608
+ and_return(Spree.user_class.new)
609
+ end
610
+
611
+ it 'should not display order tabs or edit buttons without ability', js: false do
612
+ visit spree.edit_admin_order_path(order)
613
+
614
+ # Order Form
615
+ expect(page).not_to have_css('.edit-item')
616
+ # Order Tabs
617
+ expect(page).not_to have_link('Details')
618
+ expect(page).not_to have_link('Customer')
619
+ expect(page).not_to have_link('Adjustments')
620
+ expect(page).not_to have_link('Payments')
621
+ expect(page).not_to have_link('Returns')
622
+ end
623
+
624
+ it "can add tracking information" do
625
+ visit spree.edit_admin_order_path(order)
626
+ within("table.table tr:nth-child(5)") do
627
+ click_icon :edit
628
+ end
629
+ fill_in "tracking", with: "FOOBAR"
630
+ click_icon :save
631
+
632
+ expect(page).not_to have_css("input[name=tracking]")
633
+ expect(page).to have_content("Tracking: FOOBAR")
634
+ end
635
+
636
+ it "can change the shipping method" do
637
+ order = create(:completed_order_with_totals)
638
+ visit spree.edit_admin_order_path(order)
639
+ within("table.table tr.show-method") do
640
+ click_icon :edit
641
+ end
642
+ select2 "Default", from: "Shipping Method"
643
+ click_icon :save
644
+
645
+ expect(page).not_to have_css('#selected_shipping_rate_id')
646
+ expect(page).to have_content("Default")
647
+ end
648
+
649
+ it 'can ship' do
650
+ order = create(:order_ready_to_ship)
651
+ order.refresh_shipment_rates
652
+ visit spree.edit_admin_order_path(order)
653
+ click_on 'Ship'
654
+ wait_for_ajax
655
+ within '.shipment-state' do
656
+ expect(page).to have_content('shipped')
657
+ end
658
+ end
659
+ end
660
+ end