mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Display the pickup time for each distributor, not the coordinator, in the Notify Producers email
This commit is contained in:
@@ -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 }]).
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
================
|
||||
|
||||
@@ -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: ""
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user