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 various issues when creating return for order (#12823)

Damian Kaczmarczykf7306786f6a8
diff --git a/admin/app/controllers/spree/admin/reimbursements_controller.rb b/admin/app/controllers/spree/admin/reimbursements_controller.rb
index 7ab8f0efaa..21ef76b6e6 100644
--- a/admin/app/controllers/spree/admin/reimbursements_controller.rb
+++ b/admin/app/controllers/spree/admin/reimbursements_controller.rb
@@ -44,7 +44,11 @@ module Spree
end
def permitted_resource_params
- params.require(:reimbursement).permit(permitted_reimbursement_attributes)
+ if params[:build_from_customer_return_id].present?
+ params.permit()
+ else
+ params.require(:reimbursement).permit(permitted_reimbursement_attributes)
+ end
end
end
end
diff --git a/admin/spec/controllers/spree/admin/orders/return_authorizations_controller_spec.rb b/admin/spec/controllers/spree/admin/orders/return_authorizations_controller_spec.rb
index 94322692b9..0db3d2dccb 100644
--- a/admin/spec/controllers/spree/admin/orders/return_authorizations_controller_spec.rb
+++ b/admin/spec/controllers/spree/admin/orders/return_authorizations_controller_spec.rb
@@ -37,7 +37,8 @@ RSpec.describe Spree::Admin::Orders::ReturnAuthorizationsController do
return_items_attributes: {
0 => {
inventory_unit_id: order.inventory_units.shipped.first.id,
- pre_tax_amount: 10
+ pre_tax_amount: 10,
+ preferred_reimbursement_type_id: reimbursement_type.id
}
}
}
@@ -53,6 +54,7 @@ RSpec.describe Spree::Admin::Orders::ReturnAuthorizationsController do
expect(return_auth.memo).to eq 'Test memo'
expect(return_auth.return_items.count).to eq 1
expect(return_auth.return_items.first.pre_tax_amount).to eq 10
+ expect(return_auth.return_items.first.preferred_reimbursement_type).to eq reimbursement_type
end
it 'redirects to the edit page of the return authorization' do
diff --git a/admin/spec/controllers/spree/admin/reimbursements_controller_spec.rb b/admin/spec/controllers/spree/admin/reimbursements_controller_spec.rb
index a68d6607ac..7c296f30aa 100644
--- a/admin/spec/controllers/spree/admin/reimbursements_controller_spec.rb
+++ b/admin/spec/controllers/spree/admin/reimbursements_controller_spec.rb
@@ -10,6 +10,25 @@ describe Spree::Admin::ReimbursementsController, type: :controller do
Spree::RefundReason.find_or_create_by!(name: Spree::RefundReason::RETURN_PROCESSING_REASON, mutable: false)
end
+ describe '#create' do
+ context 'when build_from_customer_return_id is present' do
+ subject do
+ post :create, params: { order_id: order.to_param, build_from_customer_return_id: customer_return.id }
+ end
+
+ let(:order) { create(:order) }
+ let(:customer_return) { create(:customer_return) }
+
+
+ it 'creates a reimbursement from a customer return' do
+ expect do
+ subject
+ end.to change { Spree::Reimbursement.count }.by(1)
+ expect(Spree::Reimbursement.last.customer_return).to eq(customer_return)
+ end
+ end
+ end
+
describe '#perform' do
subject do
post :perform, params: { order_id: order.to_param, id: reimbursement.to_param }
diff --git a/core/lib/spree/permitted_attributes.rb b/core/lib/spree/permitted_attributes.rb
index 3aa857a6a1..408bd11ba0 100644
--- a/core/lib/spree/permitted_attributes.rb
+++ b/core/lib/spree/permitted_attributes.rb
@@ -180,11 +180,17 @@ module Spree
@@report_attributes = [:type, :date_from, :date_to, :currency]
- @@return_authorization_attributes = [:amount, :memo, :stock_location_id, :inventory_units_attributes,
- :return_authorization_reason_id, {
- return_items_attributes: [:id, :inventory_unit_id, :return_authorization_id, :returned, :pre_tax_amount,
- :acceptance_status, :exchange_variant_id, :resellable]
- }]
+ @@return_authorization_attributes = [
+ :amount, :memo, :stock_location_id, :inventory_units_attributes,
+ :return_authorization_reason_id, {
+ return_items_attributes: [
+ :id, :inventory_unit_id,
+ :preferred_reimbursement_type_id,
+ :return_authorization_id, :returned, :pre_tax_amount,
+ :acceptance_status, :exchange_variant_id, :resellable
+ ]
+ }
+ ]
@@return_authorization_reason_attributes = [:name, :active]