From 25609f5c7c010d72d6415cbb6df18789c822c2ee Mon Sep 17 00:00:00 2001 From: Marc Altmann Date: Tue, 1 Mar 2016 15:07:25 +0100 Subject: [PATCH] Refactoring of one statistics function --- app/models/statistic.rb | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/app/models/statistic.rb b/app/models/statistic.rb index e1c330cbd9..97abda7893 100644 --- a/app/models/statistic.rb +++ b/app/models/statistic.rb @@ -149,14 +149,10 @@ def revenue_last_month fair = 0 fee = 0 - BusinessTransaction.where( - 'sold_at > ? - AND sold_at < ? - AND business_transactions.state = ?', - 1.month.ago.at_beginning_of_month, - 1.month.ago.at_end_of_month, - 'sold' - ).select { |bt| bt.seller.is_a?(LegalEntity) }.each do |t| + BusinessTransaction + .where(sold_at: 1.month.ago.beginning_of_month..1.month.ago.end_of_month) + .select { |bt| bt.seller.is_a?(LegalEntity) } + .each do |t| if t.article unless t.refund fair += t.quantity_bought * t.article.calculated_fair_cents