mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-25 05:45:15 +00:00
Group buy report handles nil variant weight gracefully
This commit is contained in:
@@ -38,8 +38,8 @@ module OpenFoodWeb
|
||||
end
|
||||
|
||||
# Sum quantities for each product (Total line)
|
||||
sum_quantities = line_items_by_product.sum { |li| li.variant.weight * li.quantity }
|
||||
sum_max_quantities = line_items_by_product.sum { |li| li.variant.weight * (li.max_quantity || 0) }
|
||||
sum_quantities = line_items_by_product.sum { |li| (li.variant.weight || 0) * li.quantity }
|
||||
sum_max_quantities = line_items_by_product.sum { |li| (li.variant.weight || 0) * (li.max_quantity || 0) }
|
||||
variants_and_quantities << GroupBuyProductRow.new(product, sum_quantities, sum_max_quantities)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -3,7 +3,7 @@ require 'spec_helper'
|
||||
module OpenFoodWeb
|
||||
describe GroupBuyReport do
|
||||
|
||||
before(:each) do
|
||||
before(:all) do
|
||||
@orders = []
|
||||
bill_address = create(:address)
|
||||
distributor_address = create(:address, :address1 => "distributor address", :city => 'The Shire', :zipcode => "1234")
|
||||
@@ -36,7 +36,7 @@ module OpenFoodWeb
|
||||
@orders << order2
|
||||
|
||||
@supplier2 = create(:supplier)
|
||||
@variant3 = create(:variant)
|
||||
@variant3 = create(:variant, :weight => nil)
|
||||
@variant3.product.supplier = @supplier2
|
||||
@variant3.product.save!
|
||||
product_distribution = create(:product_distribution, :product => @variant3.product, :distributor => distributor, :shipping_method => create(:shipping_method))
|
||||
@@ -82,16 +82,16 @@ module OpenFoodWeb
|
||||
|
||||
table_row_objects = subject.variants_and_quantities
|
||||
|
||||
variant_rows = table_row_objects.select{ |r| r.class == OpenFoodWeb::GroupBuyVariantRow }
|
||||
product_rows = table_row_objects.select{ |r| r.class == OpenFoodWeb::GroupBuyProductRow }
|
||||
variant_rows = table_row_objects.select { |r| r.class == OpenFoodWeb::GroupBuyVariantRow }
|
||||
product_rows = table_row_objects.select { |r| r.class == OpenFoodWeb::GroupBuyProductRow }
|
||||
|
||||
supplier_groups = variant_rows.group_by { |r| r.variant.product.supplier }
|
||||
variant_groups = variant_rows.group_by{ |r| r.variant }
|
||||
product_groups = product_rows.group_by{ |r| r.product }
|
||||
variant_groups = variant_rows.group_by { |r| r.variant }
|
||||
product_groups = product_rows.group_by { |r| r.product }
|
||||
|
||||
supplier_groups.length.should == 2
|
||||
variant_groups.length.should == 3
|
||||
product_groups.length.should == 3
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user