mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Send error notification to owner
This commit is contained in:
@@ -42,6 +42,8 @@ class BackorderJob < ApplicationJob
|
||||
payload.add_metadata(:order, order)
|
||||
payload.add_metadata(:linked_variants, linked_variants)
|
||||
end
|
||||
|
||||
BackorderMailer.backorder_failed(order, linked_variants).deliver_later
|
||||
end
|
||||
|
||||
def place_backorder(order, linked_variants)
|
||||
|
||||
14
app/mailers/backorder_mailer.rb
Normal file
14
app/mailers/backorder_mailer.rb
Normal file
@@ -0,0 +1,14 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class BackorderMailer < ApplicationMailer
|
||||
include I18nHelper
|
||||
|
||||
def backorder_failed(order, linked_variants)
|
||||
@order = order
|
||||
@linked_variants = linked_variants
|
||||
|
||||
I18n.with_locale valid_locale(order.distributor.owner) do
|
||||
mail(to: order.distributor.owner.email)
|
||||
end
|
||||
end
|
||||
end
|
||||
16
app/views/backorder_mailer/backorder_failed.haml
Normal file
16
app/views/backorder_mailer/backorder_failed.haml
Normal file
@@ -0,0 +1,16 @@
|
||||
%h1= t ".headline"
|
||||
|
||||
%p= t ".description"
|
||||
|
||||
%p= t ".hints"
|
||||
%p= t ".order", number: @order.number
|
||||
|
||||
%table
|
||||
%tr
|
||||
%th= t ".stock"
|
||||
%th= t ".product"
|
||||
|
||||
- @linked_variants.each do |variant|
|
||||
%tr
|
||||
%td= variant.on_hand
|
||||
%td= variant.product_and_full_name
|
||||
@@ -360,6 +360,22 @@ en:
|
||||
report_failed: |
|
||||
This report failed. It may be too big to process.
|
||||
We will look into it but please let us know if the problem persists.
|
||||
backorder_mailer:
|
||||
backorder_failed:
|
||||
subject: "An automatic backorder failed"
|
||||
headline: "Backordering failed"
|
||||
description: |
|
||||
We tried to place or update a backorder for out-of-stock items but
|
||||
something went wrong. You may have negative stock and need to resolve
|
||||
the issue to order more stock in.
|
||||
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.
|
||||
order: "Affected order: %{number}"
|
||||
stock: "Stock"
|
||||
product: "Product"
|
||||
enterprise_mailer:
|
||||
confirmation_instructions:
|
||||
subject: "Please confirm the email address for %{enterprise}"
|
||||
|
||||
@@ -54,6 +54,12 @@ RSpec.describe BackorderJob do
|
||||
subject.perform(nil, [])
|
||||
}.not_to raise_error
|
||||
end
|
||||
|
||||
it "notifies owner of errors" do
|
||||
expect {
|
||||
subject.perform(order, [])
|
||||
}.to enqueue_mail(BackorderMailer, :backorder_failed)
|
||||
end
|
||||
end
|
||||
|
||||
describe "#place_backorder" do
|
||||
|
||||
20
spec/mailers/backorder_mailer_spec.rb
Normal file
20
spec/mailers/backorder_mailer_spec.rb
Normal file
@@ -0,0 +1,20 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'spec_helper'
|
||||
|
||||
RSpec.describe BackorderMailer do
|
||||
let(:order) { create(:completed_order_with_totals) }
|
||||
let(:variants) { order.line_items.map(&:variant) }
|
||||
|
||||
describe "#backorder_failed" do
|
||||
it "notifies the owner" do
|
||||
order.distributor.owner.email = "jane@example.net"
|
||||
|
||||
BackorderMailer.backorder_failed(order, variants).deliver_now
|
||||
|
||||
mail = ActionMailer::Base.deliveries.first
|
||||
expect(mail.to).to eq ["jane@example.net"]
|
||||
expect(mail.subject).to eq "An automatic backorder failed"
|
||||
end
|
||||
end
|
||||
end
|
||||
12
spec/mailers/previews/backorder_mailer_preview.rb
Normal file
12
spec/mailers/previews/backorder_mailer_preview.rb
Normal file
@@ -0,0 +1,12 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class BackorderMailerPreview < ActionMailer::Preview
|
||||
def backorder_failed
|
||||
order = Spree::Order.complete.last || Spree::Order.last
|
||||
|
||||
BackorderMailer.backorder_failed(
|
||||
order,
|
||||
order.line_items.map(&:variant),
|
||||
)
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user