From 4518e30849fa5cb87d27a6b4e21f7cf9b167f3dd Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Fri, 17 Jan 2014 14:53:32 +1100 Subject: [PATCH] Display infinite on_hand as read-only --- .../spree/admin/products/bulk_edit.html.haml | 7 +++--- .../admin/bulk_product_update_spec.rb | 24 +++++++++++++++++++ 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/app/views/spree/admin/products/bulk_edit.html.haml b/app/views/spree/admin/products/bulk_edit.html.haml index e5a4d4a3b7..2c4ab6995b 100644 --- a/app/views/spree/admin/products/bulk_edit.html.haml +++ b/app/views/spree/admin/products/bulk_edit.html.haml @@ -121,8 +121,8 @@ %td{ 'ng-show' => 'columns.price.visible' } %input{ 'ng-model' => 'product.price', 'ofn-decimal' => :true, :name => 'price', 'ofn-track-product' => 'price', :type => 'text' } %td{ 'ng-show' => 'columns.on_hand.visible' } - %span{ 'ng-bind' => 'product.on_hand', :name => 'on_hand', 'ng-show' => 'hasVariants(product)' } - %input.field{ 'ng-model' => 'product.on_hand', :name => 'on_hand', 'ofn-track-product' => 'on_hand', 'ng-show' => '!hasVariants(product)', :type => 'number' } + %span{ 'ng-bind' => 'product.on_hand', :name => 'on_hand', 'ng-show' => 'hasVariants(product) || product.on_demand' } + %input.field{ 'ng-model' => 'product.on_hand', :name => 'on_hand', 'ofn-track-product' => 'on_hand', 'ng-hide' => 'hasVariants(product) || product.on_demand', :type => 'number' } %td{ 'ng-show' => 'columns.available_on.visible' } %input{ 'ng-model' => 'product.available_on', :name => 'available_on', 'ofn-track-product' => 'available_on', 'datetimepicker' => 'product.available_on', type: "text" } %td.actions @@ -142,7 +142,8 @@ %td{ 'ng-show' => 'columns.price.visible' } %input{ 'ng-model' => 'variant.price', 'ofn-decimal' => :true, :name => 'variant_price', 'ofn-track-variant' => 'price', :type => 'text' } %td{ 'ng-show' => 'columns.on_hand.visible' } - %input.field{ 'ng-model' => 'variant.on_hand', 'ng-change' => 'updateOnHand(product)', :name => 'variant_on_hand', 'ofn-track-variant' => 'on_hand', :type => 'number' } + %input.field{ 'ng-model' => 'variant.on_hand', 'ng-change' => 'updateOnHand(product)', :name => 'variant_on_hand', 'ng-hide' => 'variant.on_demand', 'ofn-track-variant' => 'on_hand', :type => 'number' } + %span{ 'ng-bind' => 'variant.on_hand', :name => 'variant_on_hand', 'ng-show' => 'variant.on_demand' } %td{ 'ng-show' => 'columns.available_on.visible' } %td.actions %a{ 'ng-click' => 'editWarn(product,variant)', :class => "edit-variant icon-edit no-text" } diff --git a/spec/features/admin/bulk_product_update_spec.rb b/spec/features/admin/bulk_product_update_spec.rb index b4be4df0a6..a97c8ba96a 100644 --- a/spec/features/admin/bulk_product_update_spec.rb +++ b/spec/features/admin/bulk_product_update_spec.rb @@ -130,6 +130,30 @@ feature %q{ page.should have_field "on_hand", with: "12" end + it "displays 'on demand' for the on hand count when the product is available on demand" do + p1 = FactoryGirl.create(:product, on_demand: true) + p1.master.on_demand = true; p1.master.save! + + visit '/admin/products/bulk_edit' + + page.should have_selector "span[name='on_hand']", text: "On demand" + page.should_not have_field "on_hand", visible: true + end + + it "displays 'on demand' for any variant that is available on demand" do + p1 = FactoryGirl.create(:product) + v1 = FactoryGirl.create(:variant, product: p1, is_master: false, on_hand: 4) + v2 = FactoryGirl.create(:variant, product: p1, is_master: false, on_hand: 0, on_demand: true) + + visit '/admin/products/bulk_edit' + first("a.view-variants").click + + page.should have_selector "span[name='on_hand']", text: "On demand" + page.should have_field "variant_on_hand", with: "4" + page.should_not have_field "variant_on_hand", with: "", visible: true + page.should have_selector ".variant span[name='on_hand']", text: "On demand" + end + it "displays a select box for the unit of measure for the product's variants" do p = FactoryGirl.create(:product, variant_unit: 'weight', variant_unit_scale: 1, variant_unit_name: '')