Merge pull request #6674 from cillian/include-ready-for-in-producer-notification

Include the 'Ready for' time for the order cycle in the Notify Producers email
This commit is contained in:
Matt-Yorkley
2021-02-18 22:01:08 +01:00
committed by GitHub
5 changed files with 24 additions and 2 deletions

View File

@@ -36,6 +36,7 @@ class ProducerMailer < Spree::BaseMailer
line_items = line_items_from(@order_cycle, @producer)
@grouped_line_items = line_items.group_by(&:product_and_full_name)
@distributors_pickup_times = distributors_pickup_times_for(line_items)
@receival_instructions = @order_cycle.receival_instructions_for(@producer)
@total = total_from_line_items(line_items)
@tax_total = tax_total_from_line_items(line_items)
@@ -50,6 +51,15 @@ class ProducerMailer < Spree::BaseMailer
line_items_from(order_cycle, producer).any?
end
def distributors_pickup_times_for(line_items)
@order_cycle.distributors.
joins(:distributed_orders).
where("spree_orders.id IN (?)", line_items.map(&:order_id).uniq).
map do |distributor|
[distributor.name, @order_cycle.pickup_time_for(distributor)]
end
end
def line_items_from(order_cycle, producer)
@line_items ||= Spree::LineItem.
includes(:option_values, variant: [:product, { option_values: :option_type }]).

View File

@@ -3,6 +3,11 @@
#{" " + @producer.name},
%p
= t :producer_mail_text_before
%ul
- @distributors_pickup_times.each do |distributor_name, pickup_time|
%li
#{distributor_name} (#{pickup_time})
- if @receival_instructions
%p
%b

View File

@@ -2,10 +2,12 @@
\
= t :producer_mail_text_before
\
- @distributors_pickup_times.each do |distributor_name, pickup_time|
\- #{distributor_name} (#{pickup_time})
\
- if @receival_instructions
= t :producer_mail_delivery_instructions
= @receival_instructions
\
Orders summary
================

View File

@@ -1654,7 +1654,7 @@ See the %{link} to find out more about %{sitename}'s features and to start using
mistakenly_sent: "Not sure why you have received this email? Please contact %{owner_email} for more information."
producer_mail_greeting: "Dear"
producer_mail_text_before: "We now have all the consumer orders for the next food drop."
producer_mail_text_before: "Please find below an update about the order cycle ready for:"
producer_mail_order_text: "Here is a summary of the orders for your products:"
producer_mail_delivery_instructions: "Stock pickup/delivery instructions:"
producer_mail_text_after: ""

View File

@@ -23,6 +23,7 @@ describe ProducerMailer, type: :mailer do
let(:p5) { create(:product, name: "Daffodil", price: 56.78, supplier: s1) }
let(:order_cycle) { create(:simple_order_cycle) }
let!(:incoming_exchange) { order_cycle.exchanges.create! sender: s1, receiver: d1, incoming: true, receival_instructions: 'Outside shed.' }
let!(:outgoing_exchange) { order_cycle.exchanges.create! sender: d1, receiver: d1, incoming: false, pickup_time: 'Tue, 23rd Dec' }
let!(:order) do
order = create(:order, distributor: d1, order_cycle: order_cycle, state: 'complete')
@@ -55,6 +56,10 @@ describe ProducerMailer, type: :mailer do
expect(mail.reply_to).to eq [order_cycle.coordinator.contact.email]
end
it "includes the pickup time for each distributor" do
expect(mail.body.encoded).to include "#{d1.name} (Tue, 23rd Dec)"
end
it "includes receival instructions" do
expect(mail.body.encoded).to include 'Outside shed.'
end