diff --git a/app/assets/javascripts/admin/line_items/controllers/line_items_controller.js.coffee b/app/assets/javascripts/admin/line_items/controllers/line_items_controller.js.coffee index e62f96467e..2efdb843f3 100644 --- a/app/assets/javascripts/admin/line_items/controllers/line_items_controller.js.coffee +++ b/app/assets/javascripts/admin/line_items/controllers/line_items_controller.js.coffee @@ -121,16 +121,16 @@ angular.module("admin.lineItems").controller 'LineItemsCtrl', ($scope, $timeout, else StatusMessage.display 'failure', t "unsaved_changes_error" - $scope.cancelOrder = (order, sendEmailCancellation) -> + $scope.cancelOrder = (order, sendEmailCancellation, restock_items) -> return $http( method: 'GET' - url: "/admin/orders/#{order.number}/fire?e=cancel&send_cancellation_email=#{sendEmailCancellation}") + url: "/admin/orders/#{order.number}/fire?e=cancel&send_cancellation_email=#{sendEmailCancellation}&restock_items=#{restock_items}") $scope.deleteLineItem = (lineItem) -> if lineItem.order.item_count == 1 - ofnCancelOrderAlert((confirm, sendEmailCancellation) -> + ofnCancelOrderAlert((confirm, sendEmailCancellation, restock_items) -> if confirm - $scope.cancelOrder(lineItem.order, sendEmailCancellation).then(-> + $scope.cancelOrder(lineItem.order, sendEmailCancellation, restock_items).then(-> $scope.refreshData() ) else @@ -152,11 +152,11 @@ angular.module("admin.lineItems").controller 'LineItemsCtrl', ($scope, $timeout, willCancelOrders = true if (order.item_count == itemsPerOrder.get(order).length) if willCancelOrders - ofnCancelOrderAlert((confirm, sendEmailCancellation) -> + ofnCancelOrderAlert((confirm, sendEmailCancellation, restock_items) -> if confirm itemsPerOrder.forEach (items, order) => if order.item_count == items.length - $scope.cancelOrder(order, sendEmailCancellation).then(-> $scope.refreshData()) + $scope.cancelOrder(order, sendEmailCancellation, restock_items).then(-> $scope.refreshData()) else Promise.all(LineItems.delete(item) for item in items).then(-> $scope.refreshData()) , "js.admin.deleting_item_will_cancel_order") diff --git a/spec/system/admin/bulk_order_management_spec.rb b/spec/system/admin/bulk_order_management_spec.rb index 3ecb090d4e..6e3cff258a 100644 --- a/spec/system/admin/bulk_order_management_spec.rb +++ b/spec/system/admin/bulk_order_management_spec.rb @@ -1006,6 +1006,7 @@ describe ' expect(page).to have_selector "a.delete-line-item", count: 2 find("tr#li_#{li2.id} a.delete-line-item").click expect(page).to have_content "This operation will result in one or more empty orders, which will be cancelled. Do you wish to proceed?" + expect(page).to have_checked_field "Restock Items: return all items to stock" end it "the user can cancel : no line item is deleted" do @@ -1017,6 +1018,7 @@ describe ' end it "the user can confirm : line item is then deleted and order is canceled" do + expect_any_instance_of(Spree::StockLocation).to receive(:restock).at_least(1).times expect do within(".modal") do uncheck("send_cancellation_email") @@ -1028,6 +1030,7 @@ describe ' end it "the user can confirm + wants to send email confirmation : line item is then deleted, order is canceled and email is sent" do + expect_any_instance_of(Spree::StockLocation).to receive(:restock).at_least(1).times expect do within(".modal") do check("send_cancellation_email") @@ -1037,6 +1040,18 @@ describe ' expect(o2.reload.state).to eq("canceled") end.to have_enqueued_mail(Spree::OrderMailer, :cancel_email) end + + it "the user can confirm + uncheck the restock option: line item is then deleted and order is canceled without retocking" do + expect_any_instance_of(Spree::StockLocation).to_not receive(:restock) + expect do + within(".modal") do + uncheck("Restock Items: return all items to stock") + click_on("OK") + end + expect(page).to have_selector "a.delete-line-item", count: 1 + expect(o2.reload.state).to eq("canceled") + end.to have_enqueued_mail(Spree::OrderMailer, :cancel_email) + end end end end