For a product with one or more on_demand variants, don't show 'On demand' at the product level

This commit is contained in:
Rohan Mitchell
2014-01-17 16:02:05 +11:00
parent ed78cc053b
commit 87cf596a30
4 changed files with 24 additions and 2 deletions

View File

@@ -316,6 +316,10 @@ productsApp.controller "AdminBulkProductsCtrl", [
Object.keys(product.variants).length > 0
$scope.hasOnDemandVariants = (product) ->
(variant for id, variant of product.variants when variant.on_demand).length > 0
$scope.updateProducts = (productsToSubmit) ->
$scope.displayUpdating()
$http(

View File

@@ -121,7 +121,7 @@
%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) || product.on_demand' }
%span{ 'ng-bind' => 'product.on_hand', :name => 'on_hand', 'ng-show' => '!hasOnDemandVariants(product) && (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" }

View File

@@ -148,7 +148,7 @@ feature %q{
visit '/admin/products/bulk_edit'
first("a.view-variants").click
page.should have_selector "span[name='on_hand']", text: "On demand"
page.should_not have_selector "span[name='on_hand']", text: "On demand", visible: true
page.should have_field "variant_on_hand", with: "4"
page.should_not have_field "variant_on_hand", with: "", visible: true
page.should have_selector "span[name='variant_on_hand']", text: "On demand"

View File

@@ -555,6 +555,24 @@ describe "AdminBulkProductsCtrl", ->
expect(scope.onHand(not_variants: [])).toEqual "error"
describe "determining whether a product has variants that are available on demand", ->
it "returns true when at least one variant does", ->
product =
variants: [
{on_demand: false}
{on_demand: true}
]
expect(scope.hasOnDemandVariants(product)).toBe(true)
it "returns false otherwise", ->
product =
variants: [
{on_demand: false}
{on_demand: false}
]
expect(scope.hasOnDemandVariants(product)).toBe(false)
describe "submitting products to be updated", ->
describe "packing products", ->
it "extracts variant_unit_with_scale into variant_unit and variant_unit_scale", ->