Can alter on_hand and price of individual variants

This commit is contained in:
Rob H
2013-06-01 21:13:40 +05:30
committed by Rohan Mitchell
parent f3d778af1a
commit 0ca0abd0b2
5 changed files with 91 additions and 9 deletions

View File

@@ -29,10 +29,19 @@
%td
%input{ 'ng-model' => 'product.master.price', 'ng-decimal' => :true, :name => 'master_price', :type => 'text' }
%td
%span{ 'ng-bind' => 'onHand(product)', :name => 'master_on_hand', 'ng-show' => 'product.variants.length > 0' }
%span{ 'ng-bind' => 'onHand(product)', :name => 'on_hand', 'ng-show' => 'product.variants.length > 0' }
%input.field{ 'ng-model' => 'product.master.on_hand', :name => 'master_on_hand', 'ng-show' => 'product.variants.length == 0', :type => 'number' }
%td
%input{ 'ng-model' => 'product.available_on', :name => 'available_on', :type => 'text' }
%tr{ 'ng-repeat' => 'variant in product.variants' }
%td
{{ variant.options_text }}
%td
%td
%input{ 'ng-model' => 'variant.price', 'ng-decimal' => :true, :name => 'variant_price', :type => 'text' }
%td
%input.field{ 'ng-model' => 'variant.on_hand', :name => 'variant_on_hand', :type => 'number' }
%td
%input{:type => 'button', :value => 'Update', 'ng-click' => 'prepareProductsForSubmit()'}
%span{ id: "update-status-message", 'ng-style' => 'updateStatusMessage.style' }
{{ updateStatusMessage.text }}

View File

@@ -10,6 +10,8 @@ r.list_of :products, @collection do
end
r.list_of :variants, Proc.new{ |product| product.variants.sort { |a,b| a.id <=> b.id } } do
r.element :id
r.element :options_text
r.element :price
r.element :on_hand
end
end

View File

@@ -39,9 +39,9 @@ describe Spree::Admin::ProductsController do
"on_hand" => p1.master.on_hand
},
"variants" => [ #ordered by id
{ "id" => v11.id, "on_hand" => v11.on_hand },
{ "id" => v12.id, "on_hand" => v12.on_hand },
{ "id" => v13.id, "on_hand" => v13.on_hand }
{ "id" => v11.id, "options_text" => v11.options_text, "price" => v11.price.to_s, "on_hand" => v11.on_hand },
{ "id" => v12.id, "options_text" => v12.options_text, "price" => v12.price.to_s, "on_hand" => v12.on_hand },
{ "id" => v13.id, "options_text" => v13.options_text, "price" => v13.price.to_s, "on_hand" => v13.on_hand }
]
}
p2r = {
@@ -55,7 +55,7 @@ describe Spree::Admin::ProductsController do
"on_hand" => p2.master.on_hand
},
"variants" => [ #ordered by id
{ "id" => v21.id, "on_hand" => v21.on_hand }
{ "id" => v21.id, "options_text" => v21.options_text, "price" => v21.price.to_s, "on_hand" => v21.on_hand }
]
}
json_response = JSON.parse(response.body)

View File

@@ -31,7 +31,7 @@ feature %q{
page.should have_field "product_name", with: p2.name
end
it "displays a select box for suppliers, with the appropriate supplier selected" do
it "displays a select box for suppliers, with the appropriate supplier selected" do
s1 = FactoryGirl.create(:supplier_enterprise)
s2 = FactoryGirl.create(:supplier_enterprise)
s3 = FactoryGirl.create(:supplier_enterprise)
@@ -78,7 +78,7 @@ feature %q{
visit '/admin/products/bulk_index'
page.should_not have_selector "span[name='master_on_hand']", text: "0"
page.should_not have_selector "span[name='on_hand']", text: "0"
page.should have_field "master_on_hand", with: "15"
page.should have_field "master_on_hand", with: "12"
end
@@ -95,10 +95,53 @@ feature %q{
visit '/admin/products/bulk_index'
page.should_not have_field "master_on_hand", with: "15"
page.should have_selector "span[name='master_on_hand']", text: "4"
page.should have_selector "span[name='on_hand']", text: "4"
page.should have_field "master_on_hand", with: "12"
end
end
describe "listing variants" do
before :each do
login_to_admin_section
end
it "displays a list of variants for each product" do
v1 = FactoryGirl.create(:variant)
v2 = FactoryGirl.create(:variant)
visit '/admin/products/bulk_index'
page.should have_field "product_name", with: v1.product.name
page.should have_field "product_name", with: v2.product.name
page.should have_selector "td", text: v1.options_text
page.should have_selector "td", text: v2.options_text
end
it "displays an on_hand input (for each variant) for each product" do
p1 = FactoryGirl.create(:product)
v1 = FactoryGirl.create(:variant, product: p1, is_master: false, on_hand: 15)
v2 = FactoryGirl.create(:variant, product: p1, is_master: false, on_hand: 6)
visit '/admin/products/bulk_index'
page.should have_selector "span[name='on_hand']", text: "21"
page.should have_field "variant_on_hand", with: "15"
page.should have_field "variant_on_hand", with: "6"
end
it "displays a price input (for each variant) for each product" do
p1 = FactoryGirl.create(:product, price: 2.0)
v1 = FactoryGirl.create(:variant, product: p1, is_master: false, price: 12.75)
v2 = FactoryGirl.create(:variant, product: p1, is_master: false, price: 2.50)
visit '/admin/products/bulk_index'
page.should have_field "master_price", with: "2.0"
page.should have_field "variant_price", with: "12.75"
page.should have_field "variant_price", with: "2.5"
end
end
scenario "create a new product" do
s = FactoryGirl.create(:supplier_enterprise)
@@ -161,6 +204,34 @@ feature %q{
page.should have_field "master_on_hand", with: "18"
end
scenario "updating a product with variants" do
s1 = FactoryGirl.create(:supplier_enterprise)
s2 = FactoryGirl.create(:supplier_enterprise)
p = FactoryGirl.create(:product, supplier: s1, available_on: Date.today)
v = FactoryGirl.create(:variant, product: p, price: 3.0, on_hand: 9)
login_to_admin_section
visit '/admin/products/bulk_index'
page.should have_field "variant_price", with: "3.0"
page.should have_field "variant_on_hand", with: "9"
page.should have_selector "span[name='on_hand']", text: "9"
fill_in "variant_price", with: "4.0"
fill_in "variant_on_hand", with: "10"
page.should have_selector "span[name='on_hand']", text: "10"
click_button 'Update'
page.find("span#update-status-message").should have_content "Update complete"
visit '/admin/products/bulk_index'
page.should have_field "variant_price", with: "4.0"
page.should have_field "variant_on_hand", with: "10"
end
scenario "updating a product mutiple times without refresh" do
p = FactoryGirl.create(:product, name: 'original name')
login_to_admin_section

View File

@@ -321,7 +321,7 @@ describe("AdminBulkProductsCtrl", function(){
});
it("sums variant on_hand properties", function(){
expect(onHand(p1)).toEqual(6);r
expect(onHand(p1)).toEqual(6);
});
it("ignores items in variants without an on_hand property (adds 0)", function(){