From b84e524f2d30b7357857fa349007ef1b281b7034 Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Thu, 28 Jun 2018 14:55:24 +1000 Subject: [PATCH] Prepare inventory report for Spree upgrade This change could impact the performance of the report. But therefore it takes VariantOverrides into consideration. The old code ignored the distributor for this filter. It also ignored the `on_demand` flag. --- lib/open_food_network/products_and_inventory_report_base.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/open_food_network/products_and_inventory_report_base.rb b/lib/open_food_network/products_and_inventory_report_base.rb index dff53fdb9a..121df3221e 100644 --- a/lib/open_food_network/products_and_inventory_report_base.rb +++ b/lib/open_food_network/products_and_inventory_report_base.rb @@ -29,16 +29,18 @@ module OpenFoodNetwork end def filter(variants) - filter_to_distributor filter_to_order_cycle filter_on_hand filter_to_supplier filter_not_deleted variants + filter_on_hand filter_to_distributor filter_to_order_cycle filter_to_supplier filter_not_deleted variants end def filter_not_deleted(variants) variants.not_deleted end + # Using the `in_stock?` method allows overrides by distributors. + # It also allows the upgrade to Spree 2.0. def filter_on_hand(variants) if params[:report_type] == 'inventory' - variants.where('spree_variants.count_on_hand > 0') + variants.select(&:in_stock?) else variants end