Skip to content

armgit / spree

Public Imported from GitHub
0

Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.

Fixed Stock Movement form and added missing Stock Movement spec

Damian Legawiecb6b2e9fc852c
diff --git a/backend/app/views/spree/admin/stock_locations/index.html.erb b/backend/app/views/spree/admin/stock_locations/index.html.erb
index fecd858c4e..8584b3fea3 100644
--- a/backend/app/views/spree/admin/stock_locations/index.html.erb
+++ b/backend/app/views/spree/admin/stock_locations/index.html.erb
@@ -19,12 +19,12 @@
</thead>
<tbody>
<% @stock_locations.each do |stock_location|
- @edit_url = edit_admin_stock_location_path(stock_location)
- @delete_url = admin_stock_location_path(stock_location)
+ @edit_url = spree.edit_admin_stock_location_path(stock_location)
+ @delete_url = spree.admin_stock_location_path(stock_location)
%>
<tr id="<%= spree_dom_id stock_location %>" data-hook="stock_location_row">
<td><%= display_name(stock_location) %></td>
- <td><%= link_to Spree.t(:stock_movements), admin_stock_location_stock_movements_path(stock_location.id) %> </td>
+ <td><%= link_to Spree.t(:stock_movements), spree.admin_stock_location_stock_movements_path(stock_location.id) %> </td>
<td><%= active_badge(stock_location.active, label: Spree.t(state(stock_location))) %></td>
<td class="actions actions-2 text-center">
<%= link_to_edit(stock_location, no_text: true) if can? :create, stock_location %>
diff --git a/backend/app/views/spree/admin/stock_movements/_form.html.erb b/backend/app/views/spree/admin/stock_movements/_form.html.erb
index b5439cce90..2805022a8a 100644
--- a/backend/app/views/spree/admin/stock_movements/_form.html.erb
+++ b/backend/app/views/spree/admin/stock_movements/_form.html.erb
@@ -5,7 +5,7 @@
<% end %>
<%= f.field_container :stock_item_id, class: ['form-group'] do %>
<%= f.label :stock_item_id, Spree.t(:stock_item_id) %>
- <%= f.text_field 'stock_item_id', :'data-stock-location-id' => params[:stock_location_id] %>
+ <%= select_tag 'stock_movement[stock_item_id]', nil , class: 'variant_autocomplete d-block w-100', :'data-stock-location-id' => params[:stock_location_id] %>
<% end %>
</div>
diff --git a/backend/app/views/spree/admin/stock_movements/index.html.erb b/backend/app/views/spree/admin/stock_movements/index.html.erb
index 237923f580..6ace30a050 100644
--- a/backend/app/views/spree/admin/stock_movements/index.html.erb
+++ b/backend/app/views/spree/admin/stock_movements/index.html.erb
@@ -17,7 +17,7 @@
</colgroup>
<thead>
<tr data-hook="admin_stock_movements_index_headers">
- <th><%= Spree.t(:stock_item) %>
+ <th><%= Spree.t(:variant) %>
<th><%= Spree.t(:quantity) %></th>
<th><%= Spree.t(:action) %></th>
</tr>
diff --git a/backend/spec/features/admin/configuration/stock_movement_spec.rb b/backend/spec/features/admin/configuration/stock_movement_spec.rb
new file mode 100644
index 0000000000..7991df0c05
--- /dev/null
+++ b/backend/spec/features/admin/configuration/stock_movement_spec.rb
@@ -0,0 +1,47 @@
+require 'spec_helper'
+
+describe 'Stock Movements', type: :feature do
+ stub_authorization!
+ let!(:stock_location) { create(:stock_location_with_items) }
+ let(:stock_item) { stock_location.stock_items.first }
+ let!(:stock_movement) { create(:stock_movement, stock_item: stock_item, quantity: 10) }
+
+ describe 'listing' do
+ before do
+ visit spree.admin_stock_locations_path
+ within "#spree_stock_location_#{stock_location.id}" do
+ click_on 'Stock Movements'
+ end
+ end
+
+ it 'renders list of stock movements for this stock location' do
+ expect(page).to have_content(stock_item.variant.name)
+ expect(page).to have_content(stock_item.variant.options_text)
+ expect(page).to have_content(stock_movement.quantity)
+ end
+ end
+
+ describe 'creation', js: true do
+ let!(:product) { create(:product_in_stock) }
+
+ before do
+ visit spree.admin_stock_location_stock_movements_path(stock_location.id)
+ click_on 'New Stock Movement', match: :first
+ end
+
+ it 'creates new stock movement' do
+ fill_in 'Quantity', with: 10
+
+ select2_open label: 'Stock Item'
+ select2_search product.name, from: 'Stock Item'
+ select2_select product.name, from: 'Stock Item', match: :first
+
+ click_button 'Create'
+
+ expect(page).to have_content(product.name)
+ expect(page).to have_content(10)
+
+ expect(page).to have_content('has been successfully created!')
+ end
+ end
+end