diff --git a/lib/open_food_network/products_and_inventory_report.rb b/lib/open_food_network/products_and_inventory_report.rb index 2b797bd944..7d695f4345 100644 --- a/lib/open_food_network/products_and_inventory_report.rb +++ b/lib/open_food_network/products_and_inventory_report.rb @@ -2,6 +2,7 @@ module OpenFoodNetwork class ProductsAndInventoryReport attr_reader :params + def initialize(user, params = {}) @user = user @params = params @@ -9,41 +10,40 @@ module OpenFoodNetwork def header [ - "Supplier", - "Producer Suburb", - "Product", - "Product Properties", - "Taxons", - "Variant Value", - "Price", - "Group Buy Unit Quantity", - "Amount" - ] + "Supplier", + "Producer Suburb", + "Product", + "Product Properties", + "Taxons", + "Variant Value", + "Price", + "Group Buy Unit Quantity", + "Amount" + ] end def table variants.map do |variant| - [variant.product.supplier.name, - variant.product.supplier.address.city, - variant.product.name, - variant.product.properties.map(&:name).join(", "), - variant.product.taxons.map(&:name).join(", "), - variant.full_name, - variant.price, - variant.product.group_buy_unit_size, - "" + [ + variant.product.supplier.name, + variant.product.supplier.address.city, + variant.product.name, + variant.product.properties.map(&:name).join(", "), + variant.product.taxons.map(&:name).join(", "), + variant.full_name, + variant.price, + variant.product.group_buy_unit_size, + "" ] end end def permissions - return @permissions unless @permissions.nil? - @permissions = OpenFoodNetwork::Permissions.new(@user) + @permissions ||= OpenFoodNetwork::Permissions.new(@user) end def visible_products - return @visible_products unless @visible_products.nil? - @visible_products = permissions.visible_products + @visible_products ||= permissions.visible_products end def variants @@ -51,15 +51,16 @@ module OpenFoodNetwork end def child_variants - Spree::Variant.where(:is_master => false) - .joins(:product) - .merge(visible_products) - .order("spree_products.name") + Spree::Variant. + where(is_master: false). + joins(:product). + merge(visible_products). + order('spree_products.name') end def filter(variants) # NOTE: Ordering matters. - # filter_to_order_cycle and filter_to_distributor return Arrays not Arel + # filter_to_order_cycle and filter_to_distributor return arrays not relations filter_to_distributor filter_to_order_cycle filter_on_hand filter_to_supplier filter_not_deleted variants end @@ -68,8 +69,8 @@ module OpenFoodNetwork end def filter_on_hand(variants) - if params[:report_type] == "inventory" - variants.where("spree_variants.count_on_hand > 0") + if params[:report_type] == 'inventory' + variants.where('spree_variants.count_on_hand > 0') else variants end