Skip to content

Commit

Permalink
If an order has out of stock line items display them and let admins r…
Browse files Browse the repository at this point in the history
…emove them
  • Loading branch information
cillian committed Oct 29, 2021
1 parent b0545c7 commit 098601b
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 0 deletions.
11 changes: 11 additions & 0 deletions app/assets/stylesheets/admin/sections/orders.scss
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
@import 'admin/globals/variables';
@import "../../darkswarm/branding";

// Customize orders filter
[data-hook="admin_orders_index_search"] {
Expand Down Expand Up @@ -35,6 +36,16 @@
}
}

.insufficient-stock-items {
legend {
color: $color-error;
}

table tr:last-child th {
border-bottom: 1px solid $clr-turquoise-light;
}
}

// Customize orduct add fieldset
#add-line-item {
fieldset {
Expand Down
3 changes: 3 additions & 0 deletions app/views/spree/admin/orders/_form.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
- if @line_item.try(:errors).present?
= render :partial => 'spree/shared/error_messages', :locals => { :target => @line_item }
- if @order.insufficient_stock_lines.any?
= render 'spree/admin/orders/insufficient_stock_lines', insufficient_stock_lines: @order.insufficient_stock_lines
= render :partial => "spree/admin/orders/shipment", :collection => @order.shipments, :locals => { :order => order }
= render :partial => "spree/admin/orders/_form/adjustments", :locals => { :adjustments => @order.line_item_adjustments, :title => t(".line_item_adjustments")}
Expand Down
39 changes: 39 additions & 0 deletions app/views/spree/admin/orders/_insufficient_stock_lines.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
%div.insufficient-stock-items
%fieldset.no-border-bottom
%legend
= t("spree.orders.line_item.out_of_stock")

%table
%colgroup
%col{ :style => "width: 10%;" }
%col{ :style => "width: 30%;" }
%col{ :style => "width: 15%;" }
%col{ :style => "width: 15%;" }
%col{ :style => "width: 15%;" }
%col{ :style => "width: 15%;" }

%thead
%th{ :colspan => "2" }
= Spree.t(:item_description)
%th
= Spree.t(:price)
%th
= Spree.t(:quantity)
%th
= Spree.t(:total)
%th.orders-actions.actions

- insufficient_stock_lines.each do |line_item|
%tr.insufficient-stock-item
%td
= render 'spree/shared/variant_thumbnail', variant: line_item.variant
%td
= line_item.variant.product_and_full_name
%td.align-center
= line_item.single_money.to_html
%td.align-center
= line_item.quantity
%td.align-center
= line_item.money.to_html
%td.actions
= link_to_delete line_item, { url: main_app.admin_bulk_line_item_path(line_item), no_text: true }
16 changes: 16 additions & 0 deletions spec/features/admin/order_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,22 @@ def new_order_with_distribution(distributor, order_cycle)
end
end
end

context "when the order has some line items with insufficient stock" do
it "displays the out of stock line items and they can be deleted from the order" do
order.line_items.first.variant.update!(on_demand: false, on_hand: 0)

visit spree.edit_admin_order_path(order)

within ".insufficient-stock-items" do
expect(page).to have_content order.products.first.name
accept_alert 'Are you sure?' do
find("a.delete-resource").click
end
expect(page).to_not have_content order.products.first.name
end
end
end
end

it "creating an order with distributor and order cycle" do
Expand Down

0 comments on commit 098601b

Please sign in to comment.