From fd3732435941a365bd6187eeb8aa02d85067b0d2 Mon Sep 17 00:00:00 2001 From: Paul Mackay Date: Sat, 9 May 2015 11:02:25 +0100 Subject: [PATCH 1/3] #536: Add permissions checking for Notify producers action. --- app/models/spree/ability_decorator.rb | 2 +- app/views/admin/order_cycles/edit.html.haml | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/app/models/spree/ability_decorator.rb b/app/models/spree/ability_decorator.rb index e66c03aa72..28aa0b5701 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..71d58d162e 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' %h1 Edit Order Cycle From 2f05fc3824739989d08bfa61d9eacaf587309169 Mon Sep 17 00:00:00 2001 From: Paul Mackay Date: Sun, 24 May 2015 10:38:49 +0100 Subject: [PATCH 2/3] #275: Insert receival time and instructions into email. --- app/mailers/producer_mailer.rb | 2 ++ app/models/order_cycle.rb | 14 +++++++++++++- app/views/admin/order_cycles/edit.html.haml | 2 +- .../producer_mailer/order_cycle_report.text.haml | 6 +++++- spec/mailers/producer_mailer_spec.rb | 13 ++++++++++++- 5 files changed, 33 insertions(+), 4 deletions(-) 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 From baaa192967c429d73fd5b39eb6d2642c6a9e6266 Mon Sep 17 00:00:00 2001 From: Paul Mackay Date: Sun, 24 May 2015 10:44:39 +0100 Subject: [PATCH 3/3] #275: Code cleanup. --- spec/mailers/producer_mailer_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/mailers/producer_mailer_spec.rb b/spec/mailers/producer_mailer_spec.rb index bb6518545b..672976a43d 100644 --- a/spec/mailers/producer_mailer_spec.rb +++ b/spec/mailers/producer_mailer_spec.rb @@ -1,5 +1,6 @@ require 'spec_helper' require 'yaml' + describe ProducerMailer do let(:s1) { create(:supplier_enterprise, address: create(:address)) } let(:s2) { create(:supplier_enterprise, address: create(:address)) } @@ -46,7 +47,6 @@ describe ProducerMailer do end it "includes receival instructions" do - puts mail.body mail.body.should include 'Outside shed.' end