mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-17 04:34:24 +00:00
Do not bulk send invoices if order is not 'complete' or 'resumed'
+ update specs as well
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user