diff --git a/app/mailers/producer_mailer.rb b/app/mailers/producer_mailer.rb index 1d2f801fd2..9f46b26a85 100644 --- a/app/mailers/producer_mailer.rb +++ b/app/mailers/producer_mailer.rb @@ -36,7 +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) - @ready_for = @order_cycle.pickup_time_for(@coordinator) + @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) @@ -51,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 }]). diff --git a/app/views/producer_mailer/order_cycle_report.html.haml b/app/views/producer_mailer/order_cycle_report.html.haml index e83e74cb4e..9a21317d54 100644 --- a/app/views/producer_mailer/order_cycle_report.html.haml +++ b/app/views/producer_mailer/order_cycle_report.html.haml @@ -2,7 +2,12 @@ = t :producer_mail_greeting #{" " + @producer.name}, %p - = t :producer_mail_text_before, ready_for: @ready_for + = 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 diff --git a/app/views/producer_mailer/order_cycle_report.text.haml b/app/views/producer_mailer/order_cycle_report.text.haml index e92ac8aa3d..84ccf0dfd8 100644 --- a/app/views/producer_mailer/order_cycle_report.text.haml +++ b/app/views/producer_mailer/order_cycle_report.text.haml @@ -1,11 +1,13 @@ #{t :producer_mail_greeting} #{@producer.name}, \ -= t :producer_mail_text_before, ready_for: @ready_for += 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 ================ diff --git a/config/locales/en.yml b/config/locales/en.yml index cc7b13d670..39ed7508e4 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -1656,7 +1656,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: "Please find below an update about the order cycle ready for %{ready_for}." + 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: "" diff --git a/spec/mailers/producer_mailer_spec.rb b/spec/mailers/producer_mailer_spec.rb index 956f875853..b05b59b819 100644 --- a/spec/mailers/producer_mailer_spec.rb +++ b/spec/mailers/producer_mailer_spec.rb @@ -23,7 +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: order_cycle.coordinator, receiver: order_cycle.coordinator, incoming: false, pickup_time: 'Tue, 23rd Dec' } + 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') @@ -56,8 +56,8 @@ describe ProducerMailer, type: :mailer do expect(mail.reply_to).to eq [order_cycle.coordinator.contact.email] end - it "includes the pickup time" do - expect(mail.body.encoded).to include 'Tue, 23rd Dec' + 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