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.

FIX passing incorrect id (#13799)

brozekabbef99f27f0
diff --git a/spree/admin/app/views/spree/admin/orders/customer_returns/_customer_return.html.erb b/spree/admin/app/views/spree/admin/orders/customer_returns/_customer_return.html.erb
index cd0d8fb182..44d4ed213d 100644
--- a/spree/admin/app/views/spree/admin/orders/customer_returns/_customer_return.html.erb
+++ b/spree/admin/app/views/spree/admin/orders/customer_returns/_customer_return.html.erb
@@ -42,7 +42,7 @@
url: edit_link,
) %>
<%= form_for [:admin, @order, Spree::Reimbursement.new] do |f| %>
- <%= hidden_field_tag :build_from_customer_return_id, customer_return.id %>
+ <%= hidden_field_tag :build_from_customer_return_id, customer_return.prefixed_id %>
<%= f.button class: 'dropdown-item' do %>
<%= icon "plus" %>
<%= Spree.t(:create_reimbursement) %>
diff --git a/spree/admin/app/views/spree/admin/orders/customer_returns/edit.html.erb b/spree/admin/app/views/spree/admin/orders/customer_returns/edit.html.erb
index 3e17fcbace..a501eec03b 100644
--- a/spree/admin/app/views/spree/admin/orders/customer_returns/edit.html.erb
+++ b/spree/admin/app/views/spree/admin/orders/customer_returns/edit.html.erb
@@ -117,7 +117,7 @@
<% if @customer_return.can_create_reimbursement? && can?(:create, Spree::Reimbursement) %>
<%= form_for [:admin, @order, Spree::Reimbursement.new] do |f| %>
- <%= hidden_field_tag :build_from_customer_return_id, @customer_return.id %>
+ <%= hidden_field_tag :build_from_customer_return_id, @customer_return.prefixed_id %>
<%= f.button class: 'btn btn-primary' do %>
<%= icon "plus" %>
<%= Spree.t(:create_reimbursement) %>
diff --git a/spree/admin/app/views/spree/admin/shipments/split.html.erb b/spree/admin/app/views/spree/admin/shipments/split.html.erb
index 9db03c80ec..c2d42b6081 100644
--- a/spree/admin/app/views/spree/admin/shipments/split.html.erb
+++ b/spree/admin/app/views/spree/admin/shipments/split.html.erb
@@ -1,6 +1,6 @@
<%= turbo_frame_tag dom_id(@variant, :shipment_item), class: "border-b py-2 px-4 shipment-line-items__row" do %>
<%= form_with url: transfer_admin_order_shipment_path(@order, @shipment), class: "shipment-line-items__form" do |f| %>
- <%= hidden_field_tag :variant_id, @variant.id %>
+ <%= hidden_field_tag :variant_id, @variant.prefixed_id %>
<div class="flex flex-row gap-2 items-center w-full form-group mb-0">
<%= label_tag :destination, Spree.t(:move_variant_to), class: 'mb-0 text-gray-600 text-sm font-bold' %>
<%= tom_select_tag :destination, grouped_options: { Spree.t('existing_shipments') => shipments_for_transfer(@shipment), Spree.t('new_shipment_at_location') => stock_locations_for_split(@variant) }, class: "grow" %>
diff --git a/spree/admin/spec/controllers/spree/admin/shipments_controller_spec.rb b/spree/admin/spec/controllers/spree/admin/shipments_controller_spec.rb
index 89f7258b07..4d2f8cad62 100644
--- a/spree/admin/spec/controllers/spree/admin/shipments_controller_spec.rb
+++ b/spree/admin/spec/controllers/spree/admin/shipments_controller_spec.rb
@@ -54,4 +54,108 @@ RSpec.describe Spree::Admin::ShipmentsController, type: :controller do
end
end
end
+
+ describe 'GET #split' do
+ let(:variant) { shipment.inventory_units.first.variant }
+
+ it 'assigns the variant and calculates max quantity' do
+ get :split, params: { order_id: order.to_param, id: shipment.to_param, variant_id: variant.to_param }
+ expect(response).to be_successful
+ expect(assigns(:variant)).to eq(variant)
+ expect(assigns(:max_quantity)).to eq(shipment.inventory_units.where(variant_id: variant.id).sum(:quantity))
+ end
+ end
+
+ describe 'POST #transfer' do
+ let(:variant) { shipment.inventory_units.first.variant }
+ let(:stock_location) { shipment.stock_location }
+
+ context 'to a new stock location' do
+ let(:destination_stock_location) { create(:stock_location) }
+
+ it 'builds a FulfilmentChanger with the destination location and runs it' do
+ fulfilment_changer = instance_double(Spree::FulfilmentChanger, valid?: true, run!: true)
+ expect(Spree::FulfilmentChanger).to receive(:new).with(
+ satisfy { |params|
+ params[:current_stock_location] == stock_location &&
+ params[:desired_stock_location] == destination_stock_location &&
+ params[:current_shipment] == shipment &&
+ params[:desired_shipment].is_a?(Spree::Shipment) &&
+ params[:desired_shipment].new_record? &&
+ params[:desired_shipment].stock_location == destination_stock_location &&
+ params[:variant] == variant &&
+ params[:quantity] == 1
+ }
+ ).and_return(fulfilment_changer)
+
+ post :transfer, params: {
+ order_id: order.to_param,
+ id: shipment.to_param,
+ variant_id: variant.to_param,
+ destination: "stock-location_#{destination_stock_location.id}",
+ quantity: 1
+ }
+
+ expect(flash[:success]).to eq(Spree.t(:shipment_transfer_success))
+ end
+ end
+
+ context 'to an existing shipment' do
+ let(:destination_shipment) { create(:shipment, order: order, stock_location: stock_location) }
+
+ it 'builds a FulfilmentChanger with the destination shipment and runs it' do
+ fulfilment_changer = instance_double(Spree::FulfilmentChanger, valid?: true, run!: true)
+ expect(Spree::FulfilmentChanger).to receive(:new).with(
+ current_stock_location: stock_location,
+ desired_stock_location: stock_location,
+ current_shipment: shipment,
+ desired_shipment: destination_shipment,
+ variant: variant,
+ quantity: 1
+ ).and_return(fulfilment_changer)
+
+ post :transfer, params: {
+ order_id: order.to_param,
+ id: shipment.to_param,
+ variant_id: variant.to_param,
+ destination: "shipment_#{destination_shipment.id}",
+ quantity: 1
+ }
+
+ expect(flash[:success]).to eq(Spree.t(:shipment_transfer_success))
+ end
+ end
+
+ context 'with invalid quantity' do
+ it 'flashes an error and does not move inventory' do
+ expect {
+ post :transfer, params: {
+ order_id: order.to_param,
+ id: shipment.to_param,
+ variant_id: variant.to_param,
+ destination: "stock-location_#{stock_location.id}",
+ quantity: 0
+ }
+ }.not_to change { order.shipments.count }
+
+ expect(flash[:error]).to be_present
+ end
+ end
+
+ context 'with invalid destination' do
+ it 'flashes an error and does not move inventory' do
+ expect {
+ post :transfer, params: {
+ order_id: order.to_param,
+ id: shipment.to_param,
+ variant_id: variant.to_param,
+ destination: 'invalid_destination',
+ quantity: 1
+ }
+ }.not_to change { order.shipments.count }
+
+ expect(flash[:error]).to include(Spree.t('admin.shipment_transfer.wrong_destination'))
+ end
+ end
+ end
end
diff --git a/spree/core/config/locales/en.yml b/spree/core/config/locales/en.yml
index dccd1d9584..faf0c38362 100644
--- a/spree/core/config/locales/en.yml
+++ b/spree/core/config/locales/en.yml
@@ -50,6 +50,8 @@ en:
spree/customer_group:
description: Description
name: Name
+ spree/customer_return:
+ stock_location_id: Stock Location
spree/gift_card:
amount_used: Amount used
expires_at: Expires at