mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-27 01:43:22 +00:00
Merge pull request #10789 from jibees/10770-bom-cancelling-an-order-always-restocks-the-line-item
BOM: when deleting the last item of order that leads to order cancellation, take into account the restock items checkbox
This commit is contained in:
@@ -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")
|
||||
|
||||
@@ -100,6 +100,7 @@ adjustItems = function(shipment_number, variant_id, quantity, restock_item){
|
||||
doAdjustItems(shipment_number, variant_id, quantity, inventory_units, restock_item, () => {
|
||||
var redirectTo = new URL(Spree.routes.cancel_order.toString());
|
||||
redirectTo.searchParams.append("send_cancellation_email", sendEmailCancellation);
|
||||
redirectTo.searchParams.append("restock_item", restock_item);
|
||||
window.location.href = redirectTo.toString();
|
||||
});
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user