allow any quantity if variant is set to on demand

This commit is contained in:
Andy Brett
2021-03-31 21:29:37 -07:00
parent 3f4b97d006
commit 9f0f88de4e
2 changed files with 24 additions and 1 deletions

View File

@@ -14,7 +14,9 @@
= "#{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, :max => item.variant.on_hand + item.quantity
- html_options = { :min => 0, :class => "line_item_quantity", :size => 5 }
- html_options.merge!({ :max => item.variant.on_hand + item.quantity }) unless item.variant.on_demand
= number_field_tag :quantity, item.quantity, html_options
%td.item-total.align-center
= line_item_shipment_price(line_item, item.quantity)

View File

@@ -146,6 +146,27 @@ feature '
expect(order.reload.line_items.first.quantity).to eq(max_quantity)
end
scenario "there are infinite items available (variant is on demand)" do
# Move the order back to the cart state
order.state = 'cart'
order.completed_at = nil
order.line_items.first.variant.update_attribute(:on_demand, true)
login_as_admin_and_visit spree.edit_admin_order_path(order)
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: 1000)
find("a.save-item").click
end
within("tr.stock-item", text: order.products.first.name) do
expect(page).to have_text("1000 x")
end
expect(order.reload.line_items.first.quantity).to eq(1000)
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)