Merge branch 'producer-emails' of https://github.com/folklabs/openfoodnetwork into folklabs-producer-emails

This commit is contained in:
Rohan Mitchell
2015-05-29 17:36:56 +10:00
6 changed files with 35 additions and 5 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

@@ -182,6 +182,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

@@ -127,7 +127,7 @@ class AbilityDecorator
can [:admin, :index, :read, :edit, :update], OrderCycle do |order_cycle|
OrderCycle.accessible_by(user).include? order_cycle
end
can [:bulk_update, :clone, :destroy], OrderCycle do |order_cycle|
can [:bulk_update, :clone, :destroy, :notify_producers], OrderCycle do |order_cycle|
user.enterprises.include? order_cycle.coordinator
end
can [:for_order_cycle], Enterprise

View File

@@ -1,6 +1,7 @@
= content_for :page_actions do
%li
= button_to "Notify producers", main_app.notify_producers_admin_order_cycle_path, :id => 'admin_notify_producers'
- 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', :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,4 +1,5 @@
require 'spec_helper'
require 'yaml'
describe ProducerMailer do
let(:s1) { create(:supplier_enterprise, address: create(:address)) }
@@ -9,6 +10,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 +42,14 @@ 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
mail.body.should include 'Outside shed.'
end
it "cc's the enterprise" do
mail.cc.should == [s1.email]
end