diff --git a/app/mailers/producer_mailer.rb b/app/mailers/producer_mailer.rb index e1a8953d36..66de47a36b 100644 --- a/app/mailers/producer_mailer.rb +++ b/app/mailers/producer_mailer.rb @@ -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" diff --git a/app/models/order_cycle.rb b/app/models/order_cycle.rb index adcd596a8c..442014c0d7 100644 --- a/app/models/order_cycle.rb +++ b/app/models/order_cycle.rb @@ -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 diff --git a/app/views/admin/order_cycles/edit.html.haml b/app/views/admin/order_cycles/edit.html.haml index 71d58d162e..ab9c9c1b29 100644 --- a/app/views/admin/order_cycles/edit.html.haml +++ b/app/views/admin/order_cycles/edit.html.haml @@ -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 diff --git a/app/views/producer_mailer/order_cycle_report.text.haml b/app/views/producer_mailer/order_cycle_report.text.haml index 43723aafa3..f6bbec8712 100644 --- a/app/views/producer_mailer/order_cycle_report.text.haml +++ b/app/views/producer_mailer/order_cycle_report.text.haml @@ -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. diff --git a/spec/mailers/producer_mailer_spec.rb b/spec/mailers/producer_mailer_spec.rb index ddc7fb68f9..bb6518545b 100644 --- a/spec/mailers/producer_mailer_spec.rb +++ b/spec/mailers/producer_mailer_spec.rb @@ -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