Add total to producer emails

This commit is contained in:
Steve Pettitt
2016-05-01 12:59:55 +01:00
committed by Rohan Mitchell
parent f90e7d3239
commit c80255e9ab
3 changed files with 12 additions and 0 deletions

View File

@@ -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

View File

@@ -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}

View File

@@ -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