diff --git a/backend/app/assets/javascripts/spree/backend/views/stock/edit_stock_item_row.js b/backend/app/assets/javascripts/spree/backend/views/stock/edit_stock_item_row.js index c0859a07de3..e4ca4e29b3d 100644 --- a/backend/app/assets/javascripts/spree/backend/views/stock/edit_stock_item_row.js +++ b/backend/app/assets/javascripts/spree/backend/views/stock/edit_stock_item_row.js @@ -13,7 +13,8 @@ Spree.Views.Stock.EditStockItemRow = Backbone.View.extend({ "click .submit": "onSubmit", "submit form": "onSubmit", "click .cancel": "onCancel", - 'input [name="count_on_hand"]': "countOnHandChanged" + 'input [name="count_on_hand"]': "countOnHandChanged", + 'input [name="backorderable"]': "backorderableChanged" }, template: HandlebarsTemplates['stock_items/stock_location_stock_item'], @@ -43,6 +44,20 @@ Spree.Views.Stock.EditStockItemRow = Backbone.View.extend({ this.render(); }, + onChange: function() { + var count_on_hand_changed = this.previousAttributes.count_on_hand != this.model.attributes.count_on_hand; + var backorderable_changed = this.previousAttributes.backorderable != this.model.attributes.backorderable; + var changed = count_on_hand_changed || backorderable_changed; + + this.$el.toggleClass('changed', changed); + }, + + backorderableChanged: function(ev) { + this.model.set("backorderable", ev.target.checked); + + this.onChange(); + }, + countOnHandChanged: function(ev) { var diff = parseInt(ev.currentTarget.value), newCount; if (isNaN(diff)) diff = 0; @@ -56,7 +71,8 @@ Spree.Views.Stock.EditStockItemRow = Backbone.View.extend({ this.model.set("count_on_hand", newCount); this.$count_on_hand_display.text(newCount); } - this.$el.toggleClass('changed', diff !== 0); + + this.onChange(); }, onSuccess: function() { diff --git a/backend/spec/features/admin/products/stock_management_spec.rb b/backend/spec/features/admin/products/stock_management_spec.rb index 2da44f4b102..5d1ba5c0b63 100644 --- a/backend/spec/features/admin/products/stock_management_spec.rb +++ b/backend/spec/features/admin/products/stock_management_spec.rb @@ -57,6 +57,15 @@ expect(stock_item.stock_movements.first.quantity).to eq(-4) end + it "can toggle backorderable", js: true do + toggle_backorderable(value: false) + + click_link "Product Stock" + within("tr#spree_variant_#{variant.id}") do + expect(find(:css, "input[type='checkbox']")).not_to be_checked + end + end + def adjust_count_on_hand(count_on_hand) within("tr#spree_variant_#{variant.id}") do find(:css, "input[type='number']").set(count_on_hand) @@ -65,6 +74,14 @@ def adjust_count_on_hand(count_on_hand) expect(page).to have_content('Updated Successfully') end + def toggle_backorderable(value: true) + within("tr#spree_variant_#{variant.id}") do + find(:css, "input[type='checkbox']").set(value) + click_icon :check + end + expect(page).to have_content('Updated Successfully') + end + context "with stock locations that don't have stock items for variant yet" do before do create(:stock_location, name: 'Other location', propagate_all_variants: false)