Pass the restock_items params to each methods and request call

+ update spec to test whether the restock item checkbox is checked or not.
This commit is contained in:
Jean-Baptiste Bellet
2023-05-02 16:51:51 +02:00
committed by Konrad
parent 1bdb668cd3
commit f679d8733e
2 changed files with 21 additions and 6 deletions

View File

@@ -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")

View File

@@ -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