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 88e4953edc..1013b78c43 100644 --- a/app/models/order_cycle.rb +++ b/app/models/order_cycle.rb @@ -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 diff --git a/app/models/spree/ability_decorator.rb b/app/models/spree/ability_decorator.rb index 13fe55a852..39899d5991 100644 --- a/app/models/spree/ability_decorator.rb +++ b/app/models/spree/ability_decorator.rb @@ -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 diff --git a/app/views/admin/order_cycles/edit.html.haml b/app/views/admin/order_cycles/edit.html.haml index d09b0e0ee0..ab9c9c1b29 100644 --- a/app/views/admin/order_cycles/edit.html.haml +++ b/app/views/admin/order_cycles/edit.html.haml @@ -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 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..672976a43d 100644 --- a/spec/mailers/producer_mailer_spec.rb +++ b/spec/mailers/producer_mailer_spec.rb @@ -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