From c80255e9ab99141fbe24b422e28ffb843ea9eb00 Mon Sep 17 00:00:00 2001 From: Steve Pettitt Date: Sun, 1 May 2016 12:59:55 +0100 Subject: [PATCH] Add total to producer emails --- app/mailers/producer_mailer.rb | 5 +++++ app/views/producer_mailer/order_cycle_report.text.haml | 3 +++ spec/mailers/producer_mailer_spec.rb | 4 ++++ 3 files changed, 12 insertions(+) diff --git a/app/mailers/producer_mailer.rb b/app/mailers/producer_mailer.rb index b9fb52fb41..d65d722894 100644 --- a/app/mailers/producer_mailer.rb +++ b/app/mailers/producer_mailer.rb @@ -6,6 +6,7 @@ class ProducerMailer < Spree::BaseMailer @order_cycle = order_cycle @line_items = aggregated_line_items_from(@order_cycle, @producer) @receival_instructions = @order_cycle.receival_instructions_for @producer + @total = total_from_line_items(@line_items) subject = "[#{Spree::Config.site_name}] Order cycle report for #{producer.name}" @@ -49,4 +50,8 @@ class ProducerMailer < Spree::BaseMailer lis end end + + def total_from_line_items(aggregated_line_items) + Spree::Money.new(aggregated_line_items.values.map(&:display_amount).reduce(:+)).to_s + end end diff --git a/app/views/producer_mailer/order_cycle_report.text.haml b/app/views/producer_mailer/order_cycle_report.text.haml index 93748395ce..ea035391b8 100644 --- a/app/views/producer_mailer/order_cycle_report.text.haml +++ b/app/views/producer_mailer/order_cycle_report.text.haml @@ -15,6 +15,9 @@ Here is a summary of the orders for your products: - @line_items.each_pair do |variant, line_item| #{variant.sku} - #{raw(variant.product.supplier.name)} - #{raw(variant.product_and_full_name)} (QTY: #{line_item.quantity}) @ #{line_item.single_money} = #{line_item.display_amount} \ +\ +Total: #{@total} +\ Thanks and best wishes, #{@coordinator.name} #{@coordinator.address.address1}, #{@coordinator.address.city}, #{@coordinator.address.zipcode} diff --git a/spec/mailers/producer_mailer_spec.rb b/spec/mailers/producer_mailer_spec.rb index 0c7e82b89d..4e3fd912d2 100644 --- a/spec/mailers/producer_mailer_spec.rb +++ b/spec/mailers/producer_mailer_spec.rb @@ -62,6 +62,10 @@ describe ProducerMailer do mail.body.should_not include p3.name end + it "includes the total" do + mail.body.should include 'Total: $20.00' + end + it "sends no mail when the producer has no orders" do expect do ProducerMailer.order_cycle_report(s3, order_cycle).deliver