Skip to content

Commit

Permalink
Merge pull request #6098 from brymut/item-counter-fix
Browse files Browse the repository at this point in the history
Fix #5989 Item counter accepts higher amount than available stock
  • Loading branch information
Matt-Yorkley authored Jan 13, 2021
2 parents c29d57b + ffeea63 commit 5f2dc38
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/views/spree/admin/orders/_shipment_manifest.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
= "#{count} x #{t(state.humanize.downcase, scope: [:spree, :shipment_states], default: [:missing, "none"])}"
- unless shipment.shipped?
%td.item-qty-edit.hidden
= number_field_tag :quantity, item.quantity, :min => 0, :class => "line_item_quantity", :size => 5
= number_field_tag :quantity, item.quantity, :min => 0, :class => "line_item_quantity", :size => 5, :max => item.variant.on_hand
%td.item-total.align-center
= line_item_shipment_price(line_item, item.quantity)

Expand Down
25 changes: 25 additions & 0 deletions spec/features/admin/order_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,31 @@ def new_order_with_distribution(distributor, order_cycle)
expect(page).not_to have_select2 "add_variant_id", with_options: [product.name]
end

scenario "can't add more items than are available" do
# Move the order back to the cart state
order.state = 'cart'
order.completed_at = nil

login_as_admin_and_visit spree.edit_admin_order_path(order)

quantity = order.line_items.first.quantity
total = order.display_total

within("tr.stock-item", text: order.products.first.name) do
find("a.edit-item").click
expect(page).to have_input(:quantity)
fill_in(:quantity, with: order.line_items.first.product.on_hand + 1)
find("a.save-item").click
end

expect(page).to_not have_content "Loading..."
within("tr.stock-item", text: order.products.first.name) do
expect(page).to have_text("#{quantity} x")
end
expect(order.reload.display_total).to eq(total)
expect(order.reload.line_items.first.quantity).to eq(quantity)
end

scenario "can't change distributor or order cycle once order has been finalized" do
login_as_admin_and_visit spree.edit_admin_order_path(order)

Expand Down

0 comments on commit 5f2dc38

Please sign in to comment.