Use correct placeholders for VO count_on_hand

This commit is contained in:
Kristina Lim
2018-11-29 15:18:01 +08:00
parent f5dc03e118
commit 4f2d96d763
5 changed files with 64 additions and 3 deletions

View File

@@ -110,6 +110,16 @@ angular.module("admin.variantOverrides").controller "AdminVariantOverridesCtrl",
.error (data, status) ->
$timeout -> StatusMessage.display 'failure', $scope.updateError(data, status)
$scope.countOnHandPlaceholder = (variant, hubId) ->
variantOverride = $scope.variantOverrides[hubId][variant.id]
if variantOverride.on_demand
t('js.variants.on_demand.yes')
else if variantOverride.on_demand == false
''
else
variant.on_hand
$scope.clearCountOnHandUnlessLimitedStock = (hubId, variantId) ->
variantOverride = $scope.variantOverrides[hubId][variantId]
unless variantOverride.on_demand == false && variantOverride.count_on_hand?

View File

@@ -8,7 +8,7 @@
%td.price{ ng: { show: 'columns.price.visible' } }
%input{name: 'variant-overrides-{{ variant.id }}-price', type: 'text', ng: {model: 'variantOverrides[hub_id][variant.id].price'}, placeholder: '{{ variant.price }}', 'ofn-track-variant-override' => 'price'}
%td.on_hand{ ng: { show: 'columns.on_hand.visible' } }
%input{name: 'variant-overrides-{{ variant.id }}-count_on_hand', type: 'text', ng: { model: 'variantOverrides[hub_id][variant.id].count_on_hand', readonly: 'variantOverrides[hub_id][variant.id].on_demand != false' }, placeholder: '{{ variant.on_hand }}', 'ofn-track-variant-override' => 'count_on_hand'}
%input{name: 'variant-overrides-{{ variant.id }}-count_on_hand', type: 'text', ng: { model: 'variantOverrides[hub_id][variant.id].count_on_hand', readonly: 'variantOverrides[hub_id][variant.id].on_demand != false' }, placeholder: '{{ countOnHandPlaceholder(variant, hub_id) }}', 'ofn-track-variant-override' => 'count_on_hand'}
%td.on_demand{ ng: { show: 'columns.on_demand.visible' } }
%select{ name: 'variant-overrides-{{ variant.id }}-on_demand', ng: { model: 'variantOverrides[hub_id][variant.id].on_demand', change: 'clearCountOnHandUnlessLimitedStock(hub_id, variant.id)', options: 'option.value as option.description for option in onDemandOptions' }, 'ofn-track-variant-override' => 'on_demand' }
%option{ value: '' }= t(".on_demand.use_producer_settings")

View File

@@ -2595,6 +2595,9 @@ See the %{link} to find out more about %{sitename}'s features and to start using
in your cart have reduced. Here's what's changed:
now_out_of_stock: is now out of stock.
only_n_remainging: "now only has %{num} remaining."
variants:
on_demand:
"yes": "On demand"
variant_overrides:
on_demand:
"yes": "Yes"

View File

@@ -237,7 +237,7 @@ feature %q{
it "product values are affected by overrides" do
page.should have_input "variant-overrides-#{variant.id}-price", with: '77.77', placeholder: '1.23'
page.should have_input "variant-overrides-#{variant.id}-count_on_hand", with: '11111', placeholder: '12'
page.should have_input "variant-overrides-#{variant.id}-count_on_hand", with: '11111', placeholder: I18n.t("js.variants.on_demand.yes")
expect(page).to have_select "variant-overrides-#{variant.id}-on_demand", selected: I18n.t("js.variant_overrides.on_demand.yes")
end
@@ -325,7 +325,7 @@ feature %q{
first("div#bulk-actions-dropdown div.menu div.menu_item", text: "Reset Stock Levels To Defaults").click
page.should have_content 'Stocks reset to defaults.'
vo.reload
page.should have_input "variant-overrides-#{variant.id}-count_on_hand", with: '1000', placeholder: '12'
page.should have_input "variant-overrides-#{variant.id}-count_on_hand", with: '1000', placeholder: I18n.t("js.variants.on_demand.yes")
vo.count_on_hand.should == 1000
end

View File

@@ -120,3 +120,51 @@ describe "VariantOverridesCtrl", ->
expect(scope.variantOverrides[123][2].count_on_hand).toBeNull()
dirtyVariantOverride = DirtyVariantOverrides.dirtyVariantOverrides[123][2]
expect(dirtyVariantOverride.count_on_hand).toBeNull()
describe "count on hand placeholder", ->
beforeEach ->
scope.variantOverrides = {123: {}}
describe "when variant is on demand", ->
variant = null
beforeEach ->
# Ideally, count_on_hand is blank when the variant is on demand. However, this rule is not
# enforced.
variant = {id: 2, on_demand: true, count_on_hand: 20, on_hand: t("on_demand")}
it "is 'On demand' when variant override uses producer stock settings", ->
scope.variantOverrides[123][2] = {on_demand: null, count_on_hand: 1}
placeholder = scope.countOnHandPlaceholder(variant, 123)
expect(placeholder).toBe(t("on_demand"))
it "is 'On demand' when variant override is on demand", ->
scope.variantOverrides[123][2] = {on_demand: true, count_on_hand: 1}
placeholder = scope.countOnHandPlaceholder(variant, 123)
expect(placeholder).toBe(t("js.variants.on_demand.yes"))
it "is blank when variant override is limited stock", ->
scope.variantOverrides[123][2] = {on_demand: false, count_on_hand: 1}
placeholder = scope.countOnHandPlaceholder(variant, 123)
expect(placeholder).toBe('')
describe "when variant is limited stock", ->
variant = null
beforeEach ->
variant = {id: 2, on_demand: false, count_on_hand: 20, on_hand: 20}
it "is variant count on hand when variant override uses producer stock settings", ->
scope.variantOverrides[123][2] = {on_demand: null, count_on_hand: 1}
placeholder = scope.countOnHandPlaceholder(variant, 123)
expect(placeholder).toBe(20)
it "is 'On demand' when variant override is on demand", ->
scope.variantOverrides[123][2] = {on_demand: true, count_on_hand: 1}
placeholder = scope.countOnHandPlaceholder(variant, 123)
expect(placeholder).toBe(t("js.variants.on_demand.yes"))
it "is blank when variant override is limited stock", ->
scope.variantOverrides[123][2] = {on_demand: false, count_on_hand: 1}
placeholder = scope.countOnHandPlaceholder(variant, 123)
expect(placeholder).toBe('')