mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-01 02:03:22 +00:00
Notify user of failed backorder completion
This commit is contained in:
@@ -23,6 +23,15 @@ class CompleteBackorderJob < ApplicationJob
|
||||
adjust_quantities(user, order, urls, variants)
|
||||
|
||||
FdcBackorderer.new(user, urls).complete_order(order)
|
||||
rescue StandardError => e
|
||||
Bugsnag.notify(e) do |payload|
|
||||
payload.add_metadata(:user, user)
|
||||
payload.add_metadata(:distributor, distributor)
|
||||
payload.add_metadata(:order_cycle, order_cycle)
|
||||
payload.add_metadata(:order_id, order_id)
|
||||
end
|
||||
|
||||
BackorderMailer.backorder_incomplete(user, distributor, order_cycle, order_id).deliver_later
|
||||
end
|
||||
|
||||
# Check if we have enough stock to reduce the backorder.
|
||||
|
||||
@@ -11,4 +11,14 @@ class BackorderMailer < ApplicationMailer
|
||||
mail(to: order.distributor.owner.email)
|
||||
end
|
||||
end
|
||||
|
||||
def backorder_incomplete(user, distributor, order_cycle, order_id)
|
||||
@distributor = distributor
|
||||
@order_cycle = order_cycle
|
||||
@order_id = order_id
|
||||
|
||||
I18n.with_locale valid_locale(user) do
|
||||
mail(to: user.email)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
9
app/views/backorder_mailer/backorder_incomplete.haml
Normal file
9
app/views/backorder_mailer/backorder_incomplete.haml
Normal file
@@ -0,0 +1,9 @@
|
||||
%h1= t ".headline"
|
||||
|
||||
%p= t ".description"
|
||||
|
||||
%p= t ".hints"
|
||||
|
||||
%p= t ".affected", enterprise: @distributor.name, order_cycle: @order_cycle.name
|
||||
|
||||
%pre= @order_id
|
||||
@@ -376,6 +376,20 @@ en:
|
||||
order: "Affected order: %{number}"
|
||||
stock: "Stock"
|
||||
product: "Product"
|
||||
backorder_incomplete:
|
||||
subject: "An automatic backorder failed to complete"
|
||||
headline: "Your backorder is still a draft"
|
||||
description: |
|
||||
We tried to complete a backorder for out-of-stock items but
|
||||
something went wrong. The backorder quantities may be too high if
|
||||
you had cancellations. And your backorder won't be fulfilled while
|
||||
it's in draft state.
|
||||
hints: |
|
||||
You may need to go to the OIDC settings and reconnect your account.
|
||||
Also check that your supplier's catalog hasn't changed and is still
|
||||
supplying all products you need. And please get in touch with us if
|
||||
you have any questions.
|
||||
affected: "%{enterprise}: %{order_cycle}"
|
||||
enterprise_mailer:
|
||||
confirmation_instructions:
|
||||
subject: "Please confirm the email address for %{enterprise}"
|
||||
|
||||
@@ -88,5 +88,20 @@ RSpec.describe CompleteBackorderJob do
|
||||
variant.on_hand
|
||||
}.from(49).to(13) # minus 3 backordered slabs (3 * 12 = 36)
|
||||
end
|
||||
|
||||
it "reports errors" do
|
||||
expect(Bugsnag).to receive(:notify).and_call_original
|
||||
|
||||
expect {
|
||||
subject.perform(user, distributor, order_cycle, "https://nil")
|
||||
}.not_to raise_error
|
||||
|
||||
# Combined example for performance
|
||||
expect(Bugsnag).to receive(:notify).and_call_original
|
||||
|
||||
expect {
|
||||
subject.perform(user, distributor, order_cycle, "https://nil")
|
||||
}.to enqueue_mail(BackorderMailer, :backorder_incomplete)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -17,4 +17,19 @@ RSpec.describe BackorderMailer do
|
||||
expect(mail.subject).to eq "An automatic backorder failed"
|
||||
end
|
||||
end
|
||||
|
||||
describe "#backorder_incomplete" do
|
||||
let(:user) { build(:user, email: "jane@example.net") }
|
||||
let(:distributor) { build(:enterprise) }
|
||||
let(:order_cycle) { build(:order_cycle) }
|
||||
let(:order_id) { "https://null" }
|
||||
|
||||
it "notifies the owner" do
|
||||
BackorderMailer.backorder_incomplete(user, distributor, order_cycle, order_id).deliver_now
|
||||
|
||||
mail = ActionMailer::Base.deliveries.first
|
||||
expect(mail.to).to eq ["jane@example.net"]
|
||||
expect(mail.subject).to eq "An automatic backorder failed to complete"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -9,4 +9,16 @@ class BackorderMailerPreview < ActionMailer::Preview
|
||||
order.line_items.map(&:variant),
|
||||
)
|
||||
end
|
||||
|
||||
def backorder_incomplete
|
||||
order = Spree::Order.complete.last || Spree::Order.last
|
||||
order_cycle = order.order_cycle
|
||||
distributor = order.distributor
|
||||
user = distributor.owner
|
||||
order_id = "https://env-0105831.jcloud-ver-jpe.ik-server.com/api/dfc/Enterprises/test-hodmedod/Orders/1177603473714"
|
||||
|
||||
BackorderMailer.backorder_incomplete(
|
||||
user, distributor, order_cycle, order_id
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user