mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Merge pull request #10447 from jibees/9148-no-bulk-delete-possible-on-bom-when-orders-have-multiple-items
Admin, BOM: can bulk delete line items of an order
This commit is contained in:
@@ -150,6 +150,10 @@ angular.module("admin.lineItems").controller 'LineItemsCtrl', ($scope, $timeout,
|
||||
else
|
||||
Promise.all(LineItems.delete(item) for item in items).then(-> $scope.refreshData())
|
||||
, "js.admin.deleting_item_will_cancel_order")
|
||||
else
|
||||
ofnDeleteLineItemsAlert(() ->
|
||||
Promise.all(LineItems.delete(item) for item in lineItemsToDelete).then(-> $scope.refreshData())
|
||||
, lineItemsToDelete.length)
|
||||
|
||||
$scope.allBoxesChecked = ->
|
||||
checkedCount = $scope.filteredLineItems.reduce (count,lineItem) ->
|
||||
|
||||
@@ -250,6 +250,18 @@ ofnCancelOrderAlert = function(callback, i18nKey) {
|
||||
$('#custom-confirm').show();
|
||||
}
|
||||
|
||||
ofnDeleteLineItemsAlert = function(callback, count) {
|
||||
$('#custom-confirm .message').html(`${t("js.admin.orders.delete_line_items_html", {count: count})}`);
|
||||
$('#custom-confirm button.confirm').click(() => {
|
||||
$('#custom-confirm').hide();
|
||||
callback();
|
||||
});
|
||||
$('#custom-confirm button.cancel').click(() => {
|
||||
$('#custom-confirm').hide();
|
||||
});
|
||||
$('#custom-confirm').show();
|
||||
}
|
||||
|
||||
ofnConfirm = function(callback) {
|
||||
$('#custom-confirm .message').html(
|
||||
` ${t("are_you_sure")}
|
||||
|
||||
@@ -3253,6 +3253,9 @@ See the %{link} to find out more about %{sitename}'s features and to start using
|
||||
cancel_the_order_send_cancelation_email: "Send a cancellation email to the customer"
|
||||
restock_item: "Restock Items: return this item to stock"
|
||||
restock_items: "Restock Items: return all items to stock"
|
||||
delete_line_items_html:
|
||||
one: "This will delete one line item from the order.<br />Are you sure you want to proceed?"
|
||||
other: "This will delete %{count} line items from the order.<br />Are you sure you want to proceed?"
|
||||
resend_user_email_confirmation:
|
||||
resend: "Resend"
|
||||
sending: "Resend..."
|
||||
|
||||
@@ -737,6 +737,7 @@ describe '
|
||||
completed_at: Time.zone.now )
|
||||
}
|
||||
let!(:li1) { create(:line_item_with_shipment, order: o1 ) }
|
||||
let!(:li11) { create(:line_item_with_shipment, order: o1 ) }
|
||||
let!(:li2) { create(:line_item_with_shipment, order: o2 ) }
|
||||
|
||||
before :each do
|
||||
@@ -770,27 +771,58 @@ describe '
|
||||
end
|
||||
|
||||
context "performing actions" do
|
||||
it "deletes selected items" do
|
||||
expect(page).to have_selector "tr#li_#{li1.id}"
|
||||
expect(page).to have_selector "tr#li_#{li2.id}"
|
||||
within("tr#li_#{li2.id} td.bulk") do
|
||||
check "bulk"
|
||||
context "deletes selected items" do
|
||||
it "displays a confirmation dialog when deleting one or more items leads to order cancelation" do
|
||||
expect(page).to have_selector "tr#li_#{li1.id}"
|
||||
expect(page).to have_selector "tr#li_#{li11.id}"
|
||||
within("tr#li_#{li1.id} td.bulk") do
|
||||
check "bulk"
|
||||
end
|
||||
within("tr#li_#{li11.id} td.bulk") do
|
||||
check "bulk"
|
||||
end
|
||||
|
||||
find("div#bulk-actions-dropdown").click
|
||||
find("div#bulk-actions-dropdown div.menu_item", text: "Delete Selected" ).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 do
|
||||
within(".modal") do
|
||||
check("send_cancellation_email")
|
||||
click_on("OK")
|
||||
end
|
||||
# order 1 should be canceled
|
||||
expect(page).to have_no_selector "tr#li_#{li1.id}"
|
||||
expect(page).to have_no_selector "tr#li_#{li11.id}"
|
||||
expect(o1.reload.state).to eq("canceled")
|
||||
# order 2 should not be canceled
|
||||
expect(page).to have_selector "tr#li_#{li2.id}"
|
||||
expect(o2.reload.state).to eq("complete")
|
||||
end.to have_enqueued_mail(Spree::OrderMailer, :cancel_email)
|
||||
end
|
||||
|
||||
find("div#bulk-actions-dropdown").click
|
||||
find("div#bulk-actions-dropdown div.menu_item", text: "Delete Selected" ).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 do
|
||||
within(".modal") do
|
||||
check("send_cancellation_email")
|
||||
click_on("OK")
|
||||
end
|
||||
it "deletes one line item should show modal confirmation about this line item deletion and not about order cancelation" do
|
||||
expect(page).to have_selector "tr#li_#{li1.id}"
|
||||
expect(page).to have_no_selector "tr#li_#{li2.id}"
|
||||
expect(o2.reload.state).to eq("canceled")
|
||||
end.to have_enqueued_mail(Spree::OrderMailer, :cancel_email)
|
||||
within("tr#li_#{li1.id} td.bulk") do
|
||||
check "bulk"
|
||||
end
|
||||
|
||||
find("div#bulk-actions-dropdown").click
|
||||
find("div#bulk-actions-dropdown div.menu_item", text: "Delete Selected" ).click
|
||||
|
||||
within ".modal" do
|
||||
expect(page).to have_content "This will delete one line item from the order. Are you sure you want to proceed?"
|
||||
click_on "OK"
|
||||
end
|
||||
|
||||
expect(page).to have_content "Loading orders"
|
||||
|
||||
expect(page).to have_no_selector ".modal"
|
||||
expect(page).to have_no_selector "tr#li_#{li1.id}"
|
||||
expect(page).to have_selector "tr#li_#{li11.id}"
|
||||
expect(o1.reload.state).to eq("complete")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user