mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-27 01:43:22 +00:00
Tidy syntax
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user