From 563a2758a640b5e6438a1e35db5f037afb50e626 Mon Sep 17 00:00:00 2001 From: Andy Brett Date: Thu, 25 Mar 2021 16:52:56 -0700 Subject: [PATCH 1/3] remove UI for modifying line items on canceled orders --- app/models/spree/shipment.rb | 4 ++++ app/views/spree/admin/orders/_add_product.html.haml | 11 +++++++---- app/views/spree/admin/orders/_shipment.html.haml | 8 ++++---- .../spree/admin/orders/_shipment_manifest.html.haml | 2 +- config/locales/en.yml | 1 + spec/features/admin/order_spec.rb | 10 ++++++++++ 6 files changed, 27 insertions(+), 9 deletions(-) diff --git a/app/models/spree/shipment.rb b/app/models/spree/shipment.rb index 173c3bebe8..afad7e4428 100644 --- a/app/models/spree/shipment.rb +++ b/app/models/spree/shipment.rb @@ -284,6 +284,10 @@ module Spree I18n.t('shipping') end + def can_modify? + !shipped? && !order.canceled? + end + private def manifest_unstock(item) diff --git a/app/views/spree/admin/orders/_add_product.html.haml b/app/views/spree/admin/orders/_add_product.html.haml index 3f12c6c1a4..a4644a91c6 100644 --- a/app/views/spree/admin/orders/_add_product.html.haml +++ b/app/views/spree/admin/orders/_add_product.html.haml @@ -4,8 +4,11 @@ %fieldset.no-border-bottom %legend{:align => "center"}= Spree.t(:add_product) - .field.twelve.columns.alpha{"data-hook" => "add_product_name"} - = label_tag :add_variant_id, Spree.t(:name_or_sku) - = hidden_field_tag :add_variant_id, "", :class => "variant_autocomplete fullwidth" - + - if @order.canceled? + = Spree.t(:cannot_add_item_to_canceled_order) + - else + .field.twelve.columns.alpha{"data-hook" => "add_product_name"} + = label_tag :add_variant_id, Spree.t(:name_or_sku) + = hidden_field_tag :add_variant_id, "", :class => "variant_autocomplete fullwidth" + #stock_details diff --git a/app/views/spree/admin/orders/_shipment.html.haml b/app/views/spree/admin/orders/_shipment.html.haml index 3248e57655..72ef176c85 100644 --- a/app/views/spree/admin/orders/_shipment.html.haml +++ b/app/views/spree/admin/orders/_shipment.html.haml @@ -33,7 +33,7 @@ %tbody{ "data-shipment-number" => "#{shipment.number}", "data-order-number" => "#{order.number}" } = render 'spree/admin/orders/shipment_manifest', order: order, shipment: shipment - - unless shipment.shipped? + - if shipment.can_modify? %tr.edit-method.hidden.total %td{ :colspan => "5" } %div.field.alpha.five.columns @@ -69,7 +69,7 @@ %span = shipment.fee_adjustment.display_amount - - if shipment.fee_adjustment.present? && !shipment.shipped? + - if shipment.fee_adjustment.present? && shipment.can_modify? %td.actions - if can? :update, shipment = link_to '', '', :class => 'edit-method icon_link icon-edit no-text with-tip', :data => { :action => 'edit' }, :title => Spree.t('edit') @@ -81,7 +81,7 @@ = text_field_tag :tracking, shipment.tracking %td.actions - - if can? :update, shipment + - if can?(:update, shipment) && !shipment.canceled? = link_to '', '', :class => 'save-tracking icon_link icon-ok no-text with-tip', :data => { 'shipment-number' => shipment.number, :action => 'save' }, :title => I18n.t('actions.save') = link_to '', '', :class => 'cancel-tracking icon_link icon-cancel no-text with-tip', :data => { :action => 'cancel' }, :title => I18n.t('actions.cancel') @@ -95,5 +95,5 @@ = Spree.t(:no_tracking_present) %td.actions - - if can? :update, shipment + - if can?(:update, shipment) && shipment.can_modify? = link_to '', '', :class => 'edit-tracking icon_link icon-edit no-text with-tip', :data => { :action => 'edit' }, :title => Spree.t('edit') diff --git a/app/views/spree/admin/orders/_shipment_manifest.html.haml b/app/views/spree/admin/orders/_shipment_manifest.html.haml index 51d1571735..19f6b7006e 100644 --- a/app/views/spree/admin/orders/_shipment_manifest.html.haml +++ b/app/views/spree/admin/orders/_shipment_manifest.html.haml @@ -19,7 +19,7 @@ = line_item_shipment_price(line_item, item.quantity) %td.cart-item-delete.actions{ "data-hook" => "cart_item_delete" } - - if !shipment.shipped? && can?(:update, shipment) + - if shipment.can_modify? && can?(:update, shipment) = link_to '', '#', :class => 'save-item icon_link icon-ok no-text with-tip', :data => {'shipment-number' => shipment.number, 'variant-id' => item.variant.id, :action => 'save'}, :title => t('actions.save'), :style => 'display: none' = link_to '', '#', :class => 'cancel-item icon_link icon-cancel no-text with-tip', :data => {:action => 'cancel'}, :title => t('actions.cancel'), :style => 'display: none' = link_to '', '#', :class => 'edit-item icon_link icon-edit no-text with-tip', :data => {:action => 'edit'}, :title => t('actions.edit') diff --git a/config/locales/en.yml b/config/locales/en.yml index bac1bfaefa..39a79f9615 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -3043,6 +3043,7 @@ See the %{link} to find out more about %{sitename}'s features and to start using back_to_payments_list: "Back To Payments List" return_authorizations: "Return Authorizations" cannot_create_returns: "Cannot create returns as this order has no shipped units." + cannot_add_item_to_canceled_order: "Cannot add item to canceled order" select_stock: "Select stock" location: "Location" count_on_hand: "Count On Hand" diff --git a/spec/features/admin/order_spec.rb b/spec/features/admin/order_spec.rb index 6e17dc2a46..36fbab0ef2 100644 --- a/spec/features/admin/order_spec.rb +++ b/spec/features/admin/order_spec.rb @@ -343,6 +343,16 @@ feature ' end end end + + context "and the order has been canceled" do + it "does not allow modifying line items" do + order.cancel! + visit spree.edit_admin_order_path(order) + within("tr.stock-item", text: order.products.first.name) do + expect(page).to_not have_selector("a.edit-item") + end + end + end end scenario "creating an order with distributor and order cycle" do From d78517b6edcdea23e38a47f63212796b3eb57c90 Mon Sep 17 00:00:00 2001 From: Andy Brett Date: Fri, 26 Mar 2021 09:34:12 -0700 Subject: [PATCH 2/3] Update app/views/spree/admin/orders/_add_product.html.haml Co-authored-by: Maikel --- app/views/spree/admin/orders/_add_product.html.haml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/spree/admin/orders/_add_product.html.haml b/app/views/spree/admin/orders/_add_product.html.haml index a4644a91c6..93594bd12f 100644 --- a/app/views/spree/admin/orders/_add_product.html.haml +++ b/app/views/spree/admin/orders/_add_product.html.haml @@ -5,7 +5,7 @@ %legend{:align => "center"}= Spree.t(:add_product) - if @order.canceled? - = Spree.t(:cannot_add_item_to_canceled_order) + = t(".cannot_add_item_to_canceled_order") - else .field.twelve.columns.alpha{"data-hook" => "add_product_name"} = label_tag :add_variant_id, Spree.t(:name_or_sku) From ba857cfce46919b29fd14f7c150deda6354948f8 Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Mon, 29 Mar 2021 17:00:11 +1100 Subject: [PATCH 3/3] Move translation for lazy lookup in previous commit --- config/locales/en.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/config/locales/en.yml b/config/locales/en.yml index 39a79f9615..c7b929c183 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -3043,7 +3043,6 @@ See the %{link} to find out more about %{sitename}'s features and to start using back_to_payments_list: "Back To Payments List" return_authorizations: "Return Authorizations" cannot_create_returns: "Cannot create returns as this order has no shipped units." - cannot_add_item_to_canceled_order: "Cannot add item to canceled order" select_stock: "Select stock" location: "Location" count_on_hand: "Count On Hand" @@ -3327,6 +3326,8 @@ See the %{link} to find out more about %{sitename}'s features and to start using received: "Received" canceled: "Canceled" orders: + add_product: + cannot_add_item_to_canceled_order: "Cannot add item to canceled order" index: listing_orders: "Listing Orders" new_order: "New Order"