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..93594bd12f 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? + = 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 c101b9d938..ce1d8e67e7 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -3326,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" 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