Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix stock item form to allow changing backorder value #3159

Merged
merged 1 commit into from
Jun 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
Expand Down Expand Up @@ -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;
Expand All @@ -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() {
Expand Down
17 changes: 17 additions & 0 deletions backend/spec/features/admin/products/stock_management_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down