#275: Insert receival time and instructions into email.

This commit is contained in:
Paul Mackay
2015-05-24 10:38:49 +01:00
parent 955f41633a
commit 2f05fc3824
5 changed files with 33 additions and 4 deletions

View File

@@ -6,6 +6,8 @@ class ProducerMailer < Spree::BaseMailer
@coordinator = order_cycle.coordinator
@order_cycle = order_cycle
@line_items = aggregated_line_items_from(@order_cycle, @producer)
@receival_time = @order_cycle.receival_time_for @producer
@receival_instructions = @order_cycle.receival_instructions_for @producer
subject = "[#{Spree::Config.site_name}] Order cycle report"

View File

@@ -26,7 +26,7 @@ class OrderCycle < ActiveRecord::Base
closed.
where("order_cycles.orders_close_at >= ?", 31.days.ago).
order("order_cycles.orders_close_at DESC") }
scope :soonest_opening, lambda { upcoming.order('order_cycles.orders_open_at ASC') }
scope :distributing_product, lambda { |product|
@@ -163,6 +163,18 @@ class OrderCycle < ActiveRecord::Base
exchanges.outgoing.to_enterprises([distributor]).first
end
def exchange_for_supplier(supplier)
exchanges.incoming.from_enterprises([supplier]).first
end
def receival_time_for(supplier)
exchange_for_supplier(supplier).andand.receival_time
end
def receival_instructions_for(supplier)
exchange_for_supplier(supplier).andand.receival_instructions
end
def pickup_time_for(distributor)
exchange_for_distributor(distributor).andand.pickup_time || distributor.next_collection_at
end

View File

@@ -1,7 +1,7 @@
- if can? :notify_producers, @order_cycle
= content_for :page_actions do
%li
= button_to "Notify producers", main_app.notify_producers_admin_order_cycle_path, :id => 'admin_notify_producers'
= button_to "Notify producers", main_app.notify_producers_admin_order_cycle_path, :id => 'admin_notify_producers', :confirm => 'Are you sure?'
%h1 Edit Order Cycle

View File

@@ -1,6 +1,10 @@
Dear #{@producer.name},
\
We now have all the consumer orders for the food drop on #{@distribution_date}.
We now have all the consumer orders for next food drop. Please drop off your delivery at #{@receival_time}.
- if @receival_instructions
Extra instructions: #{@receival_instructions}
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}.
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.

View File

@@ -1,5 +1,5 @@
require 'spec_helper'
require 'yaml'
describe ProducerMailer do
let(:s1) { create(:supplier_enterprise, address: create(:address)) }
let(:s2) { create(:supplier_enterprise, address: create(:address)) }
@@ -9,6 +9,8 @@ describe ProducerMailer do
let(:p2) { create(:product, price: 23.45, supplier: s2) }
let(:p3) { create(:product, price: 34.56, supplier: s1) }
let(:order_cycle) { create(:simple_order_cycle) }
let!(:incoming_exchange) { order_cycle.exchanges.create! sender: s1, receiver: d1, incoming: true, receival_time: '10am Saturday', receival_instructions: 'Outside shed.' }
let!(:order) do
order = create(:order, distributor: d1, order_cycle: order_cycle, state: 'complete')
order.line_items << create(:line_item, variant: p1.master)
@@ -39,6 +41,15 @@ describe ProducerMailer do
mail.reply_to.should == [s1.email]
end
it "includes receival time" do
mail.body.should include '10am Saturday'
end
it "includes receival instructions" do
puts mail.body
mail.body.should include 'Outside shed.'
end
it "cc's the enterprise" do
mail.cc.should == [s1.email]
end