mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Ensure in UI compatible VO count and on demand
This commit is contained in:
@@ -109,3 +109,15 @@ angular.module("admin.variantOverrides").controller "AdminVariantOverridesCtrl",
|
||||
StatusMessage.display 'success', t('js.variant_overrides.stock_reset')
|
||||
.error (data, status) ->
|
||||
$timeout -> StatusMessage.display 'failure', $scope.updateError(data, status)
|
||||
|
||||
$scope.selectLimitedStockIfCountOnHandSet = (hubId, variantId) ->
|
||||
variantOverride = $scope.variantOverrides[hubId][variantId]
|
||||
if variantOverride.count_on_hand? && variantOverride.count_on_hand != '' && variantOverride.on_demand != false
|
||||
variantOverride.on_demand = false
|
||||
DirtyVariantOverrides.set hubId, variantId, variantOverride.id, 'on_demand', false
|
||||
|
||||
$scope.clearCountOnHandUnlessLimitedStock = (hubId, variantId) ->
|
||||
variantOverride = $scope.variantOverrides[hubId][variantId]
|
||||
unless variantOverride.on_demand == false && variantOverride.count_on_hand?
|
||||
variantOverride.count_on_hand = null
|
||||
DirtyVariantOverrides.set hubId, variantId, variantOverride.id, 'count_on_hand', null
|
||||
|
||||
@@ -8,9 +8,9 @@
|
||||
%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'}, 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', change: 'selectLimitedStockIfCountOnHandSet(hub_id, variant.id)' }, placeholder: '{{ variant.on_hand }}', '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', options: 'option.value as option.description for option in onDemandOptions' }, 'ofn-track-variant-override' => 'on_demand' }
|
||||
%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")
|
||||
%td.reset{ ng: { show: 'columns.reset.visible' } }
|
||||
%input{name: 'variant-overrides-{{ variant.id }}-resettable', type: 'checkbox', ng: {model: 'variantOverrides[hub_id][variant.id].resettable'}, placeholder: '{{ variant.resettable }}', 'ofn-track-variant-override' => 'resettable'}
|
||||
|
||||
@@ -339,9 +339,43 @@ feature %q{
|
||||
first("div#bulk-actions-dropdown div.menu div.menu_item", text: "Reset Stock Levels To Defaults").click
|
||||
page.should have_content "Save changes first"
|
||||
end
|
||||
|
||||
describe "ensuring that on demand and count on hand settings are compatible" do
|
||||
it "changes to limited stock when count on hand is set" do
|
||||
# It sets on_demand to false when count_on_hand is filled.
|
||||
fill_in "variant-overrides-#{variant.id}-count_on_hand", with: "200"
|
||||
expect(page).to have_select "variant-overrides-#{variant.id}-on_demand", selected: I18n.t("js.variant_overrides.on_demand.no")
|
||||
|
||||
# It saves the changes.
|
||||
click_button I18n.t("save_changes")
|
||||
expect(page).to have_content I18n.t("js.changes_saved")
|
||||
|
||||
vo.reload
|
||||
expect(vo.count_on_hand).to eq(200)
|
||||
expect(vo.on_demand).to eq(false)
|
||||
end
|
||||
|
||||
it "clears count on hand when not limited stock" do
|
||||
# It clears count_on_hand when selecting true on_demand.
|
||||
fill_in "variant-overrides-#{variant.id}-count_on_hand", with: "200"
|
||||
select I18n.t("js.variant_overrides.on_demand.yes"), from: "variant-overrides-#{variant.id}-on_demand"
|
||||
expect(page).to have_input "variant-overrides-#{variant.id}-count_on_hand", with: ""
|
||||
|
||||
# It clears count_on_hand when selecting nil on_demand.
|
||||
fill_in "variant-overrides-#{variant.id}-count_on_hand", with: "200"
|
||||
select I18n.t("admin.variant_overrides.products_variants.on_demand.use_producer_settings"), from: "variant-overrides-#{variant.id}-on_demand"
|
||||
expect(page).to have_input "variant-overrides-#{variant.id}-count_on_hand", with: ""
|
||||
|
||||
# It saves the changes.
|
||||
click_button I18n.t("save_changes")
|
||||
expect(page).to have_content I18n.t("js.changes_saved")
|
||||
vo.reload
|
||||
expect(vo.count_on_hand).to be_nil
|
||||
expect(vo.on_demand).to be_nil
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe "when manually placing an order" do
|
||||
|
||||
@@ -87,3 +87,66 @@ describe "VariantOverridesCtrl", ->
|
||||
$httpBackend.flush()
|
||||
expect(VariantOverrides.updateData).toHaveBeenCalledWith variant_overrides_mock
|
||||
expect(StatusMessage.display).toHaveBeenCalledWith 'success', 'Stocks reset to defaults.'
|
||||
|
||||
describe "ensuring that on demand and count on hand settings are compatible", ->
|
||||
describe "changing to limited stock when count on hand is set", ->
|
||||
beforeEach ->
|
||||
scope.variantOverrides = {123: {2: {id: 5, on_demand: true}}}
|
||||
|
||||
describe "when count on hand is set", ->
|
||||
beforeEach ->
|
||||
scope.variantOverrides[123][2].count_on_hand = 1
|
||||
|
||||
it "changes to limited stock and registers dirty attribute", ->
|
||||
scope.selectLimitedStockIfCountOnHandSet(123, 2)
|
||||
expect(scope.variantOverrides[123][2].on_demand).toBe(false)
|
||||
dirtyVariantOverride = DirtyVariantOverrides.dirtyVariantOverrides[123][2]
|
||||
expect(dirtyVariantOverride.on_demand).toBe(false)
|
||||
|
||||
describe "when count on hand is null", ->
|
||||
beforeEach ->
|
||||
scope.variantOverrides[123][2].count_on_hand = null
|
||||
|
||||
it "does not change to limited stock", ->
|
||||
scope.selectLimitedStockIfCountOnHandSet(123, 2)
|
||||
expect(scope.variantOverrides[123][2].on_demand).toBe(true)
|
||||
|
||||
describe "when count on hand is blank string", ->
|
||||
beforeEach ->
|
||||
scope.variantOverrides[123][2].count_on_hand = ''
|
||||
|
||||
it "does not change to limited stock", ->
|
||||
scope.selectLimitedStockIfCountOnHandSet(123, 2)
|
||||
expect(scope.variantOverrides[123][2].on_demand).toBe(true)
|
||||
|
||||
describe "clearing count on hand when not limited stock", ->
|
||||
beforeEach ->
|
||||
scope.variantOverrides = {123: {2: {id: 5, count_on_hand: 1}}}
|
||||
|
||||
describe "when on demand is false", ->
|
||||
beforeEach ->
|
||||
scope.variantOverrides[123][2].on_demand = false
|
||||
|
||||
it "does not clear count on hand", ->
|
||||
scope.clearCountOnHandUnlessLimitedStock(123, 2)
|
||||
expect(scope.variantOverrides[123][2].count_on_hand).toEqual(1)
|
||||
|
||||
describe "when on demand is true", ->
|
||||
beforeEach ->
|
||||
scope.variantOverrides[123][2].on_demand = true
|
||||
|
||||
it "clears count on hand and registers dirty attribute", ->
|
||||
scope.clearCountOnHandUnlessLimitedStock(123, 2)
|
||||
expect(scope.variantOverrides[123][2].count_on_hand).toBeNull()
|
||||
dirtyVariantOverride = DirtyVariantOverrides.dirtyVariantOverrides[123][2]
|
||||
expect(dirtyVariantOverride.count_on_hand).toBeNull()
|
||||
|
||||
describe "when on demand is null", ->
|
||||
beforeEach ->
|
||||
scope.variantOverrides[123][2].on_demand = null
|
||||
|
||||
it "clears count on hand and registers dirty attribute", ->
|
||||
scope.clearCountOnHandUnlessLimitedStock(123, 2)
|
||||
expect(scope.variantOverrides[123][2].count_on_hand).toBeNull()
|
||||
dirtyVariantOverride = DirtyVariantOverrides.dirtyVariantOverrides[123][2]
|
||||
expect(dirtyVariantOverride.count_on_hand).toBeNull()
|
||||
|
||||
Reference in New Issue
Block a user