Do not bulk send invoices if order is not 'complete' or 'resumed'

+ update specs as well
This commit is contained in:
Jean-Baptiste Bellet
2023-02-17 14:33:51 +01:00
parent 8926a3f08d
commit 5208094f05
2 changed files with 41 additions and 19 deletions

View File

@@ -10,11 +10,15 @@ class BulkActionsInOrdersListReflex < ApplicationReflex
end
def send_invoice(order_ids)
count = 0
orders(order_ids).find_each do |o|
Spree::OrderMailer.invoice_email(o.id).deliver_later if o.distributor.can_invoice?
next unless o.distributor.can_invoice? && (o.resumed? || o.complete?)
Spree::OrderMailer.invoice_email(o.id).deliver_later
count += 1
end
success("admin.send_invoice_feedback", order_ids.count)
success("admin.send_invoice_feedback", count)
end
private

View File

@@ -384,27 +384,45 @@ describe '
login_as_admin_and_visit spree.admin_orders_path
end
it "can bulk send invoice for 2 orders" do
Spree::Config[:enable_invoices?] = true
Spree::Config[:enterprise_number_required_on_invoices?] = false
page.find("#listing_orders tbody tr:nth-child(1) input[name='order_ids[]']").click
page.find("#listing_orders tbody tr:nth-child(2) input[name='order_ids[]']").click
page.find("span.icon-reorder", text: "ACTIONS").click
within ".ofn-drop-down-with-prepend .menu" do
page.find("span", text: "Send Invoices").click
context "bulk print invoices" do
before do
Spree::Config[:enable_invoices?] = true
Spree::Config[:enterprise_number_required_on_invoices?] = false
end
expect(page).to have_content "Are you sure you want to proceed?"
context "with multiple orders with differents states" do
before do
order2.update(state: "complete")
order3.update(state: "resumed")
order4.update(state: "canceled")
order5.update(state: "payment")
end
within ".reveal-modal" do
expect {
find_button("Confirm").click
}.to enqueue_job(ActionMailer::MailDeliveryJob).exactly(:twice)
it "can bulk print invoices but only for the 'complete' or 'resumed' ones" do
within "#listing_orders" do
page.find("input[name='order_ids[]'][value='#{order2.id}']").click
page.find("input[name='order_ids[]'][value='#{order3.id}']").click
page.find("input[name='order_ids[]'][value='#{order4.id}']").click
page.find("input[name='order_ids[]'][value='#{order5.id}']").click
end
page.find("span.icon-reorder", text: "ACTIONS").click
within ".ofn-drop-down-with-prepend .menu" do
page.find("span", text: "Send Invoices").click
end
expect(page).to have_content "This will email customer invoices for all selected complete orders."
expect(page).to have_content "Are you sure you want to proceed?"
within ".reveal-modal" do
expect {
find_button("Confirm").click
}.to enqueue_job(ActionMailer::MailDeliveryJob).exactly(:twice)
end
expect(page).to have_content "Invoice emails sent for 2 orders."
end
end
expect(page).to have_content "Invoice emails sent for 2 orders."
end
it "can bulk send email to 2 orders" do