Adding SKU to Products and Inventory reports (except lettuceshare)

This commit is contained in:
Rob Harrington
2015-12-16 13:37:19 +11:00
parent befc558224
commit 5d28a7fdf8
3 changed files with 44 additions and 9 deletions

View File

@@ -12,7 +12,8 @@ module OpenFoodNetwork
"Variant Value",
"Price",
"Group Buy Unit Quantity",
"Amount"
"Amount",
"SKU"
]
end
@@ -27,10 +28,15 @@ module OpenFoodNetwork
variant.full_name,
variant.price,
variant.product.group_buy_unit_size,
""
"",
sku_for(variant)
]
end
end
def sku_for(variant)
return variant.sku unless variant.sku.blank?
variant.product.sku
end
end
end

View File

@@ -286,7 +286,7 @@ feature %q{
let(:supplier) { create(:supplier_enterprise, name: 'Supplier Name') }
let(:taxon) { create(:taxon, name: 'Taxon Name') }
let(:product1) { create(:simple_product, name: "Product Name", price: 100, supplier: supplier, primary_taxon: taxon) }
let(:product2) { create(:simple_product, name: "Product 2", price: 99.0, variant_unit: 'weight', variant_unit_scale: 1, unit_value: '100', supplier: supplier, primary_taxon: taxon) }
let(:product2) { create(:simple_product, name: "Product 2", price: 99.0, variant_unit: 'weight', variant_unit_scale: 1, unit_value: '100', supplier: supplier, primary_taxon: taxon, sku: "product_sku") }
let(:variant1) { product1.variants.first }
let(:variant2) { create(:variant, product: product1, price: 80.0) }
let(:variant3) { product2.variants.first }
@@ -297,8 +297,11 @@ feature %q{
product1.taxons = [taxon]
product2.taxons = [taxon]
variant1.update_column(:count_on_hand, 10)
variant1.update_column(:sku, "sku1")
variant2.update_column(:count_on_hand, 20)
variant2.update_column(:sku, "sku2")
variant3.update_column(:count_on_hand, 9)
variant3.update_column(:sku, "")
variant1.option_values = [create(:option_value, :presentation => "Test")]
variant2.option_values = [create(:option_value, :presentation => "Something")]
end
@@ -312,10 +315,10 @@ feature %q{
click_link 'Products & Inventory'
page.should have_content "Supplier"
page.should have_table_row ["Supplier", "Producer Suburb", "Product", "Product Properties", "Taxons", "Variant Value", "Price", "Group Buy Unit Quantity", "Amount"].map(&:upcase)
page.should have_table_row [product1.supplier.name, product1.supplier.address.city, "Product Name", product1.properties.map(&:presentation).join(", "), product1.primary_taxon.name, "Test", "100.0", product1.group_buy_unit_size.to_s, ""]
page.should have_table_row [product1.supplier.name, product1.supplier.address.city, "Product Name", product1.properties.map(&:presentation).join(", "), product1.primary_taxon.name, "Something", "80.0", product1.group_buy_unit_size.to_s, ""]
page.should have_table_row [product2.supplier.name, product1.supplier.address.city, "Product 2", product1.properties.map(&:presentation).join(", "), product2.primary_taxon.name, "100g", "99.0", product1.group_buy_unit_size.to_s, ""]
page.should have_table_row ["Supplier", "Producer Suburb", "Product", "Product Properties", "Taxons", "Variant Value", "Price", "Group Buy Unit Quantity", "Amount", "SKU"].map(&:upcase)
page.should have_table_row [product1.supplier.name, product1.supplier.address.city, "Product Name", product1.properties.map(&:presentation).join(", "), product1.primary_taxon.name, "Test", "100.0", product1.group_buy_unit_size.to_s, "", "sku1"]
page.should have_table_row [product1.supplier.name, product1.supplier.address.city, "Product Name", product1.properties.map(&:presentation).join(", "), product1.primary_taxon.name, "Something", "80.0", product1.group_buy_unit_size.to_s, "", "sku2"]
page.should have_table_row [product2.supplier.name, product1.supplier.address.city, "Product 2", product1.properties.map(&:presentation).join(", "), product2.primary_taxon.name, "100g", "99.0", product1.group_buy_unit_size.to_s, "", "product_sku"]
end
it "shows the LettuceShare report" do

View File

@@ -22,7 +22,8 @@ module OpenFoodNetwork
"Variant Value",
"Price",
"Group Buy Unit Quantity",
"Amount"
"Amount",
"SKU"
]
end
@@ -48,7 +49,8 @@ module OpenFoodNetwork
"Variant Name",
100,
21,
""
"",
"sku"
]]
end
@@ -68,9 +70,11 @@ module OpenFoodNetwork
user.save!
user
end
subject do
ProductsAndInventoryReport.new enterprise_user
end
describe "fetching child variants" do
it "returns some variants" do
product1 = create(:simple_product, supplier: supplier)
@@ -154,6 +158,28 @@ module OpenFoodNetwork
subject.filter(variants)
end
end
describe "fetching SKU for a variant" do
let(:variant) { create(:variant) }
let(:product) { variant.product }
before { product.update_attribute(:sku, "Product SKU") }
context "when the variant has an SKU set" do
before { variant.update_attribute(:sku, "Variant SKU") }
it "returns it" do
expect(subject.send(:sku_for, variant)).to eq "Variant SKU"
end
end
context "when the variant has bo SKU set" do
before { variant.update_attribute(:sku, "") }
it "returns the product's SKU" do
expect(subject.send(:sku_for, variant)).to eq "Product SKU"
end
end
end
end
end
end