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: Customer Return: don't try to call for non exiting inventory unit

Damian Legawiec131677f4e9c5
diff --git a/core/app/models/spree/customer_return.rb b/core/app/models/spree/customer_return.rb
index 781f9d826f..68f3d21cd8 100644
--- a/core/app/models/spree/customer_return.rb
+++ b/core/app/models/spree/customer_return.rb
@@ -45,6 +45,7 @@ module Spree
# Temporarily tie a customer_return to one order
def order
return nil if return_items.blank?
+ return nil if return_items.first.inventory_unit.blank?
return_items.first.inventory_unit.order
end
diff --git a/core/spec/models/spree/customer_return_spec.rb b/core/spec/models/spree/customer_return_spec.rb
index 1221a71b62..78283a39d3 100644
--- a/core/spec/models/spree/customer_return_spec.rb
+++ b/core/spec/models/spree/customer_return_spec.rb
@@ -144,6 +144,17 @@ describe Spree::CustomerReturn, type: :model do
it "returns the order associated with the return item's inventory unit" do
expect(subject).to eq return_item.inventory_unit.order
end
+
+ context 'return item without inventory unit' do
+ before do
+ return_item.inventory_unit.destroy
+ return_item.reload
+ end
+
+ it 'returns nil' do
+ expect(subject).to be_nil
+ end
+ end
end
describe '#order_id' do