From 098601b3e9f2ad57491a03e7bead2d43c752e685 Mon Sep 17 00:00:00 2001 From: Cillian O'Ruanaidh Date: Fri, 29 Oct 2021 17:43:27 +0100 Subject: [PATCH] If an order has out of stock line items display them and let admins remove them --- .../stylesheets/admin/sections/orders.scss | 11 ++++++ app/views/spree/admin/orders/_form.html.haml | 3 ++ .../_insufficient_stock_lines.html.haml | 39 +++++++++++++++++++ spec/features/admin/order_spec.rb | 16 ++++++++ 4 files changed, 69 insertions(+) create mode 100644 app/views/spree/admin/orders/_insufficient_stock_lines.html.haml diff --git a/app/assets/stylesheets/admin/sections/orders.scss b/app/assets/stylesheets/admin/sections/orders.scss index 47b84337b992..e9bfe6f32488 100644 --- a/app/assets/stylesheets/admin/sections/orders.scss +++ b/app/assets/stylesheets/admin/sections/orders.scss @@ -1,4 +1,5 @@ @import 'admin/globals/variables'; +@import "../../darkswarm/branding"; // Customize orders filter [data-hook="admin_orders_index_search"] { @@ -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 { diff --git a/app/views/spree/admin/orders/_form.html.haml b/app/views/spree/admin/orders/_form.html.haml index 72dbf3d81bb0..cdd2550c89b6 100644 --- a/app/views/spree/admin/orders/_form.html.haml +++ b/app/views/spree/admin/orders/_form.html.haml @@ -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")} diff --git a/app/views/spree/admin/orders/_insufficient_stock_lines.html.haml b/app/views/spree/admin/orders/_insufficient_stock_lines.html.haml new file mode 100644 index 000000000000..70a4ac14ce26 --- /dev/null +++ b/app/views/spree/admin/orders/_insufficient_stock_lines.html.haml @@ -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 } diff --git a/spec/features/admin/order_spec.rb b/spec/features/admin/order_spec.rb index 8cad382463b9..09b388f894b8 100644 --- a/spec/features/admin/order_spec.rb +++ b/spec/features/admin/order_spec.rb @@ -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