From 2df27fca52a275ae983ba88abeb7afc82bb8cfcf Mon Sep 17 00:00:00 2001 From: Holger Hans Peter Freyther Date: Thu, 28 Feb 2013 15:32:37 +0100 Subject: [PATCH] calculate the number of days it takes until the stock might be gone --- app/mailers/spree/stock_mailer.rb | 4 +++- app/views/spree/stock_mailer/stock_report_email.text.erb | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/app/mailers/spree/stock_mailer.rb b/app/mailers/spree/stock_mailer.rb index f8f9286..f59b8d5 100644 --- a/app/mailers/spree/stock_mailer.rb +++ b/app/mailers/spree/stock_mailer.rb @@ -42,8 +42,10 @@ module Spree else name = "Sku " + var.sku end + days = var.count_on_hand / mean - {'weighted_mean' => mean, 'variant' => var, 'product' => var.product, 'name' => name} + {'weighted_mean' => mean, 'days' => days, 'variant' => var, + 'product' => var.product, 'name' => name} end def generate_forecast() diff --git a/app/views/spree/stock_mailer/stock_report_email.text.erb b/app/views/spree/stock_mailer/stock_report_email.text.erb index 9e75e53..0e144e0 100644 --- a/app/views/spree/stock_mailer/stock_report_email.text.erb +++ b/app/views/spree/stock_mailer/stock_report_email.text.erb @@ -5,7 +5,7 @@ will run low. Estimates: <% @forecast.each do |dict| %> -<%= dict['name'] %> => <%= dict['weighted_mean'].round(2) %> days until sold out. +<%= dict['name'] %> => <%= dict['days'].round(2) %> days until sold out. <% end %>