Merge pull request #11754 from mkllnk/reload-bug

Don't update order when not enough stock when editing as admin
This commit is contained in:
Filipe
2023-11-10 16:57:43 +00:00
committed by GitHub
3 changed files with 15 additions and 12 deletions

View File

@@ -50,11 +50,11 @@ $(document).ready(function() {
if (quantity > maxQuantity) {
quantity = maxQuantity;
save.parents('tr').find('input.line_item_quantity').val(maxQuantity);
ofnAlert(t("js.admin.orders.quantity_adjusted"));
ofnAlert(t("js.admin.orders.quantity_unavailable"));
} else {
adjustItems(shipment_number, variant_id, quantity, true);
}
toggleItemEdit();
adjustItems(shipment_number, variant_id, quantity, true);
return false;
}
$('a.save-item').click(handle_save_click);

View File

@@ -3440,7 +3440,7 @@ See the %{link} to find out more about %{sitename}'s features and to start using
processing: "processing"
void: "void"
invalid: "invalid"
quantity_adjusted: "Insufficient stock available. Line item updated to maximum available quantity."
quantity_unavailable: "Insufficient stock available. Line item unsaved!"
quantity_unchanged: "Quantity unchanged from previous amount."
cancel_the_order_html: "This will cancel the current order.<br />Are you sure you want to proceed?"
cancel_the_order_send_cancelation_email: "Send a cancellation email to the customer"

View File

@@ -339,24 +339,27 @@ describe '
login_as_admin
visit spree.edit_admin_order_path(order)
quantity = order.line_items.first.quantity
max_quantity = 0
item = order.line_items.first
quantity = item.quantity
max_quantity = quantity + item.variant.on_hand
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)
max_quantity = find("input[name='quantity']")["max"].to_i
fill_in(:quantity, with: max_quantity + 1)
find("a.save-item").click
end
click_button("OK")
expect(page).to_not have_content "Loading..."
within("tr.stock-item", text: order.products.first.name) do
expect(page).to have_text(max_quantity.to_s)
within(".modal") do
expect(page).to have_content "Insufficient stock available"
click_on "OK"
end
expect(order.reload.line_items.first.quantity).to eq(max_quantity)
within("tr.stock-item", text: order.products.first.name) do
expect(page).to have_field :quantity, with: max_quantity.to_s
end
expect { item.reload }.to_not change { item.quantity }
end
it "there are infinite items available (variant is on demand)" do