diff --git a/app/assets/javascripts/admin/variant_overrides/controllers/variant_overrides_controller.js.coffee b/app/assets/javascripts/admin/variant_overrides/controllers/variant_overrides_controller.js.coffee index 0fe051f496..1bf77e160b 100644 --- a/app/assets/javascripts/admin/variant_overrides/controllers/variant_overrides_controller.js.coffee +++ b/app/assets/javascripts/admin/variant_overrides/controllers/variant_overrides_controller.js.coffee @@ -13,6 +13,10 @@ angular.module("admin.variantOverrides").controller "AdminVariantOverridesCtrl", $scope.RequestMonitor = RequestMonitor $scope.selectView = Views.selectView $scope.currentView = -> Views.currentView + $scope.onDemandOptions = [ + { description: t('js.yes'), value: true }, + { description: t('js.no'), value: false } + ] $scope.views = Views.setViews inventory: { name: t('js.variant_overrides.inventory_products'), visible: true } diff --git a/app/views/admin/variant_overrides/_products_variants.html.haml b/app/views/admin/variant_overrides/_products_variants.html.haml index 7c530a1cb2..5a3f3b2b39 100644 --- a/app/views/admin/variant_overrides/_products_variants.html.haml +++ b/app/views/admin/variant_overrides/_products_variants.html.haml @@ -10,7 +10,8 @@ %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'} %td.on_demand{ ng: { show: 'columns.on_demand.visible' } } - %input.field{ :type => 'checkbox', name: 'variant-overrides-{{ variant.id }}-on_demand', ng: { model: 'variantOverrides[hub_id][variant.id].on_demand' }, 'ofn-track-variant-override' => 'on_demand' } + %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' } + %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'} %td.reset{ ng: { show: 'columns.reset.visible' } } @@ -24,4 +25,4 @@ %button.icon-remove.hide.fullwidth{ :type => 'button', ng: { click: "setVisibility(hub_id,variant.id,false)" } } = t('admin.variant_overrides.index.hide') %td.import_date{ ng: { show: 'columns.import_date.visible' } } - %span {{variantOverrides[hub_id][variant.id].import_date | date:"MMMM dd, yyyy HH:mm"}} \ No newline at end of file + %span {{variantOverrides[hub_id][variant.id].import_date | date:"MMMM dd, yyyy HH:mm"}} diff --git a/config/locales/en.yml b/config/locales/en.yml index de1222902e..25a5fcc179 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -623,6 +623,9 @@ en: new_powertip: These products are available to be added to your inventory. Click 'Add' to add a product to your inventory, or 'Hide' to hide it from view. You can always change your mind later! controls: back_to_my_inventory: Back to my inventory + products_variants: + on_demand: + use_producer_settings: "Use producer settings" orders: invoice_email_sent: 'Invoice email has been sent' order_email_resent: 'Order email has been resent' @@ -2445,6 +2448,8 @@ See the %{link} to find out more about %{sitename}'s features and to start using pending: Pending shipped: Shipped js: + "yes": "Yes" + "no": "No" saving: 'Saving...' changes_saved: 'Changes saved.' save_changes_first: Save changes first. diff --git a/spec/features/admin/variant_overrides_spec.rb b/spec/features/admin/variant_overrides_spec.rb index 60130ddc6d..1421cb496c 100644 --- a/spec/features/admin/variant_overrides_spec.rb +++ b/spec/features/admin/variant_overrides_spec.rb @@ -141,7 +141,7 @@ feature %q{ fill_in "variant-overrides-#{variant.id}-sku", with: 'NEWSKU' fill_in "variant-overrides-#{variant.id}-price", with: '777.77' fill_in "variant-overrides-#{variant.id}-count_on_hand", with: '123' - check "variant-overrides-#{variant.id}-on_demand" + select I18n.t("js.yes"), from: "variant-overrides-#{variant.id}-on_demand" page.should have_content "Changes to one override remain unsaved." expect do @@ -218,7 +218,7 @@ feature %q{ end context "with overrides" do - let!(:vo) { create(:variant_override, variant: variant, hub: hub, price: 77.77, count_on_hand: 11111, default_stock: 1000, resettable: true, tag_list: ["tag1","tag2","tag3"]) } + let!(:vo) { create(:variant_override, variant: variant, hub: hub, price: 77.77, on_demand: true, count_on_hand: 11111, default_stock: 1000, resettable: true, tag_list: ["tag1","tag2","tag3"]) } let!(:vo_no_auth) { create(:variant_override, variant: variant, hub: hub2, price: 1, count_on_hand: 2) } let!(:product2) { create(:simple_product, supplier: producer, variant_unit: 'weight', variant_unit_scale: 1) } let!(:variant2) { create(:variant, product: product2, unit_value: 8, price: 1.00, on_hand: 12) } @@ -236,6 +236,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' + expect(page).to have_select "variant-overrides-#{variant.id}-on_demand", selected: I18n.t("js.yes") end it "updates existing overrides" do @@ -255,10 +256,32 @@ feature %q{ vo.count_on_hand.should == 8888 end + it "updates on_demand settings" do + select I18n.t("js.no"), from: "variant-overrides-#{variant.id}-on_demand" + click_button I18n.t("save_changes") + expect(page).to have_content I18n.t("js.changes_saved") + + vo.reload + expect(vo.on_demand).to eq(false) + + select I18n.t("js.yes"), from: "variant-overrides-#{variant.id}-on_demand" + click_button I18n.t("save_changes") + expect(page).to have_content I18n.t("js.changes_saved") + + vo.reload + expect(vo.on_demand).to eq(true) + + select I18n.t("admin.variant_overrides.products_variants.on_demand.use_producer_settings"), from: "variant-overrides-#{variant.id}-on_demand" + click_button I18n.t("save_changes") + expect(page).to have_content I18n.t("js.changes_saved") + + vo.reload + expect(vo.on_demand).to be_nil + end + # Any new fields added to the VO model need to be added to this test it "deletes overrides when values are cleared" do first("div#columns-dropdown", :text => "COLUMNS").click - first("div#columns-dropdown div.menu div.menu_item", text: "On Demand").click first("div#columns-dropdown div.menu div.menu_item", text: "Enable Stock Reset?").click first("div#columns-dropdown div.menu div.menu_item", text: "Tags").click first("div#columns-dropdown", :text => "COLUMNS").click @@ -272,6 +295,7 @@ feature %q{ # Clearing values manually fill_in "variant-overrides-#{variant.id}-price", with: '' fill_in "variant-overrides-#{variant.id}-count_on_hand", with: '' + select I18n.t("admin.variant_overrides.products_variants.on_demand.use_producer_settings"), from: "variant-overrides-#{variant.id}-on_demand" fill_in "variant-overrides-#{variant.id}-default_stock", with: '' within "tr#v_#{variant.id}" do vo.tag_list.each do |tag|