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.
This commit is contained in:
Maikel Linke
2018-06-28 14:55:24 +10:00
parent 289d0b937f
commit b84e524f2d

View File

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