#275: Change report format. Improved mailer.

This commit is contained in:
Paul Mackay
2014-11-16 07:14:29 +00:00
parent 9b7fd1c16b
commit 375bdc0586
3 changed files with 62 additions and 16 deletions

View File

@@ -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

View File

@@ -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}

View 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