mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-27 01:43:22 +00:00
#275: Change report format. Improved mailer.
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
|
||||
require 'devise/mailers/helpers'
|
||||
class ProducerMailer < Spree::BaseMailer
|
||||
include Devise::Mailers::Helpers
|
||||
|
||||
def order_cycle_report(producer, order_cycle)
|
||||
@producer = producer
|
||||
@@ -7,12 +8,24 @@ class ProducerMailer < Spree::BaseMailer
|
||||
@order_cycle = order_cycle
|
||||
|
||||
# TODO: consider what happens if there is more than one distributor
|
||||
first_producer = @order_cycle.distributors[0]
|
||||
@distribution_date = @order_cycle.pickup_time_for first_producer
|
||||
# puts @distribution_date
|
||||
if @order_cycle.distributors.count > 0
|
||||
first_producer = @order_cycle.distributors[0]
|
||||
@distribution_date = @order_cycle.pickup_time_for first_producer
|
||||
end
|
||||
|
||||
subject = "[Open Food Network] Order cycle report for #{@distribution_date}"
|
||||
mail(to: @producer.email, from: from_address, subject: subject)
|
||||
subject = "[#{Spree::Config[:site_name]}] Order cycle report for #{@distribution_date}"
|
||||
|
||||
@orders = Spree::Order.complete.not_state(:canceled).managed_by(@producer.owner)
|
||||
@line_items = []
|
||||
@orders.each do |o|
|
||||
@line_items += o.line_items.managed_by(@producer.owner)
|
||||
end
|
||||
|
||||
mail(to: @producer.email,
|
||||
from: from_address,
|
||||
subject: subject,
|
||||
reply_to: @coordinator.email,
|
||||
cc: @coordinator.email)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -1,21 +1,22 @@
|
||||
Dear #{@producer.name},
|
||||
|
||||
\
|
||||
We now have all the consumer orders for the food drop on #{@distribution_date}.
|
||||
Please deliver to #{@coordinator.address.address1}, #{@coordinator.address.city}, #{@coordinator.address.zipcode} during the regular delivery time. If this is not convenient then please call #{@coordinator.phone}.
|
||||
|
||||
NB If you have to arrange a different delivery day and time, the school has requested that you do not come on site during drop off/pick up times (8:45-9:15 and 15:00-15:30)
|
||||
Note: If you have to arrange a different delivery day and time, it is requested that you do not come on site during drop off/pick up times.
|
||||
|
||||
\
|
||||
Orders summary
|
||||
==============
|
||||
|
||||
================
|
||||
\
|
||||
Here is a summary of the orders for your products:
|
||||
\
|
||||
- @line_items.each do |item|
|
||||
#{item.variant.sku} #{raw(item.variant.product.supplier.name)} #{raw(item.variant.product.name)} #{raw(item.variant.options_text)} (QTY: #{item.quantity}) @ #{item.single_money} = #{item.display_amount}
|
||||
|
||||
/ - @order_cycle.exchange_for_distributor.each do |exchange|
|
||||
|
||||
|
||||
\
|
||||
Detailed orders breakdown
|
||||
=========================
|
||||
|
||||
===========================
|
||||
|
||||
|
||||
Please confirm that you have got this email.
|
||||
@@ -23,5 +24,5 @@ Please confirm that you have got this email.
|
||||
Please send me an invoice for this amount so we can send you payment.
|
||||
|
||||
If you need to phone on the day please call #{@coordinator.phone}.
|
||||
|
||||
\
|
||||
Thanks and best wishes - #{@coordinator.name}
|
||||
32
spec/mailers/producer_mailer_spec.rb
Normal file
32
spec/mailers/producer_mailer_spec.rb
Normal file
@@ -0,0 +1,32 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe ProducerMailer do
|
||||
let(:p) { create(:simple_product, supplier: s) }
|
||||
let(:supplier) { create(:supplier_enterprise) }
|
||||
let(:order_cycle) { create(:simple_order_cycle) }
|
||||
|
||||
after do
|
||||
ActionMailer::Base.deliveries.clear
|
||||
end
|
||||
|
||||
before do
|
||||
ActionMailer::Base.delivery_method = :test
|
||||
ActionMailer::Base.perform_deliveries = true
|
||||
ActionMailer::Base.deliveries = []
|
||||
end
|
||||
|
||||
it "should send an email when an order cycle is closed" do
|
||||
ProducerMailer.order_cycle_report(supplier, order_cycle).deliver
|
||||
ActionMailer::Base.deliveries.count.should == 3
|
||||
end
|
||||
|
||||
it "sets a reply-to of the enterprise email" do
|
||||
ProducerMailer.order_cycle_report(supplier, order_cycle).deliver
|
||||
ActionMailer::Base.deliveries.last.reply_to.should == [supplier.email]
|
||||
end
|
||||
|
||||
it "ccs the enterprise" do
|
||||
ProducerMailer.order_cycle_report(supplier, order_cycle).deliver
|
||||
ActionMailer::Base.deliveries.last.cc.should == [supplier.email]
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user