Skip to content

Commit

Permalink
Merge pull request #5048 from solidusio/backport/v3.3/pr-5039
Browse files Browse the repository at this point in the history
[v3.3] Allow to disable track inventory for product without variants
  • Loading branch information
waiting-for-dev authored Apr 27, 2023
2 parents 072442d + 05ec777 commit e4d7414
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 1 deletion.
9 changes: 8 additions & 1 deletion backend/app/views/spree/admin/products/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,14 @@
</div>
<% end %>
</div>

<div data-hook="admin_product_form_track_inventory">
<%= f.field_container :track_inventory do %>
<label>
<%= f.check_box :track_inventory %>
<%= Spree::Variant.human_attribute_name(:track_inventory) %>
</label>
<% end %>
</div>
<% end %>

<div data-hook="admin_product_form_shipping_categories">
Expand Down
24 changes: 24 additions & 0 deletions backend/spec/features/admin/products/products_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,13 @@ def build_option_type_with_values(name, values)
it "should show default tax category" do
expect(page).to have_select('product_tax_category_id', selected: 'Alcohol taxes')
end

it "can disable track_inventory" do
expect(page).to have_field("product_track_inventory", checked: true)
uncheck "product_track_inventory"
click_button "Create"
expect(page).to have_field("product_track_inventory", checked: false)
end
end

context "cloning a product", js: true do
Expand Down Expand Up @@ -343,6 +350,23 @@ def build_option_type_with_values(name, values)
end
end
end

it "can disable track_inventory" do
visit spree.admin_product_path(product)
expect(page).to have_field("product_track_inventory", checked: true)
uncheck "product_track_inventory"
click_button "Update"
expect(page).to have_field("product_track_inventory", checked: false)
end

context "with variants" do
let(:product) { create(:variant).product }

it "cannot disable track_inventory" do
visit spree.admin_product_path(product)
expect(page).to_not have_field("product_track_inventory")
end
end
end

context 'deleting a product', js: true do
Expand Down
1 change: 1 addition & 0 deletions core/app/models/spree/product.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ def find_or_build_master
:height,
:price,
:sku,
:track_inventory,
:weight,
:width,
]
Expand Down
18 changes: 18 additions & 0 deletions core/spec/models/spree/product_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -653,4 +653,22 @@ class Extension < Spree::Base
end
end
end

describe "inventory tracking" do
let(:product) { build(:product) }

describe "#track_inventory=" do
it "delegates to master variant" do
expect(product.master).to receive(:track_inventory=).with(true)
product.track_inventory = true
end
end

describe "#track_inventory" do
it "delegates to master variant" do
expect(product.master).to receive(:track_inventory) { true }
expect(product.track_inventory).to be(true)
end
end
end
end

0 comments on commit e4d7414

Please sign in to comment.