mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-27 01:43:22 +00:00
#275: start on producer email.
This commit is contained in:
2
Gemfile
2
Gemfile
@@ -43,7 +43,7 @@ gem 'spinjs-rails'
|
||||
gem 'rack-ssl', :require => 'rack/ssl'
|
||||
gem 'custom_error_message', :github => 'jeremydurham/custom-err-msg'
|
||||
gem 'angularjs-file-upload-rails', '~> 1.1.0'
|
||||
|
||||
gem 'delayed_job_active_record'
|
||||
gem 'foreigner'
|
||||
gem 'immigrant'
|
||||
|
||||
|
||||
@@ -221,6 +221,11 @@ GEM
|
||||
debugger-ruby_core_source (~> 1.2.3)
|
||||
debugger-linecache (1.2.0)
|
||||
debugger-ruby_core_source (1.2.3)
|
||||
delayed_job (4.0.4)
|
||||
activesupport (>= 3.0, < 4.2)
|
||||
delayed_job_active_record (4.0.2)
|
||||
activerecord (>= 3.0, < 4.2)
|
||||
delayed_job (>= 3.0, < 4.1)
|
||||
devise (2.2.8)
|
||||
bcrypt-ruby (~> 3.0)
|
||||
orm_adapter (~> 0.1)
|
||||
@@ -521,6 +526,7 @@ DEPENDENCIES
|
||||
db2fog
|
||||
debugger-linecache
|
||||
deface!
|
||||
delayed_job_active_record
|
||||
factory_girl_rails
|
||||
foreigner
|
||||
foundation-icons-sass-rails
|
||||
|
||||
@@ -70,6 +70,27 @@ module Admin
|
||||
redirect_to main_app.admin_order_cycles_path, :notice => "Your order cycle #{@order_cycle.name} has been cloned."
|
||||
end
|
||||
|
||||
OrderCycleNotificationJob = Struct.new(:order_cycle) do
|
||||
def perform
|
||||
puts order_cycle
|
||||
@suppliers = order_cycle.suppliers
|
||||
puts @suppliers
|
||||
@suppliers.each { |supplier| ProducerMailer.order_cycle_report(supplier, order_cycle).deliver }
|
||||
end
|
||||
end
|
||||
|
||||
# Send notifications to all producers who are part of the order cycle
|
||||
def notifications
|
||||
puts 'notify_producers!'
|
||||
|
||||
@order_cycle = OrderCycle.find params[:id]
|
||||
# Delayed::Job.enqueue OrderCycleNotificationJob.new(@order_cycle)
|
||||
job = OrderCycleNotificationJob.new(@order_cycle)
|
||||
job.perform
|
||||
|
||||
render 'notifications'
|
||||
end
|
||||
|
||||
|
||||
protected
|
||||
def collection
|
||||
|
||||
13
app/mailers/producer_mailer.rb
Normal file
13
app/mailers/producer_mailer.rb
Normal file
@@ -0,0 +1,13 @@
|
||||
require 'devise/mailers/helpers'
|
||||
class ProducerMailer < ActionMailer::Base Spree::BaseMailer
|
||||
include Devise::Mailers::Helpers
|
||||
|
||||
def order_cycle_report(producer, order_cycle)
|
||||
@producer = producer
|
||||
@coordinator = order_cycle.coordinator
|
||||
@order_cycle = order_cycle
|
||||
subject = "[Open Food Network] Order cycle report for "
|
||||
mail(to: @producer.email, from: from_address, subject: subject)
|
||||
end
|
||||
|
||||
end
|
||||
@@ -1,4 +1,8 @@
|
||||
%h1 Edit Order Cycle
|
||||
|
||||
= content_for :page_actions do
|
||||
%li
|
||||
= button_to "Notify producers", main_app.admin_order_cycle_path + '/notifications', :id => 'admin_notify_producers'
|
||||
|
||||
= form_for [main_app, :admin, @order_cycle], :url => '', :html => {:class => 'ng order_cycle', 'ng-app' => 'order_cycle', 'ng-controller' => 'AdminEditOrderCycleCtrl', 'ng-submit' => 'submit()'} do |f|
|
||||
= render 'form', :f => f
|
||||
|
||||
2
app/views/admin/order_cycles/notifications.html.haml
Normal file
2
app/views/admin/order_cycles/notifications.html.haml
Normal file
@@ -0,0 +1,2 @@
|
||||
|
||||
Email sent.
|
||||
27
app/views/producer_mailer/order_cycle_report.html.haml
Normal file
27
app/views/producer_mailer/order_cycle_report.html.haml
Normal file
@@ -0,0 +1,27 @@
|
||||
Dear #{@producer.name},
|
||||
|
||||
We now have all the consumer orders for the food drop on #{}.
|
||||
Please deliver to #{coordinator.address} between 9:30am and 10:30am. If this is not convenient then please call #{@coordinator.phone}.
|
||||
|
||||
NB If you have to arrange a different delivery day and time, the school has requested that you do not come on site during drop off/pick up times (8:45-9:15 and 15:00-15:30)
|
||||
|
||||
Orders summary
|
||||
==============
|
||||
|
||||
Here is a summary of the orders for your products:
|
||||
|
||||
- @order_cycle.exchange_for_distributor.each do |exchange|
|
||||
|
||||
|
||||
Detailed orders breakdown
|
||||
=========================
|
||||
|
||||
|
||||
|
||||
Please confirm that you have got this email.
|
||||
|
||||
Please send me an invoice for this amount so we can send you payment.
|
||||
|
||||
If you need to phone on the day please call #{@coordinator.phone}.
|
||||
|
||||
Thanks and best wishes - #{@coordinator.name}
|
||||
@@ -40,6 +40,8 @@ Openfoodnetwork::Application.routes.draw do
|
||||
resources :order_cycles do
|
||||
post :bulk_update, on: :collection, as: :bulk_update
|
||||
get :clone, on: :member
|
||||
|
||||
post 'notifications', on: :member
|
||||
end
|
||||
|
||||
resources :enterprises do
|
||||
|
||||
Reference in New Issue
Block a user