Skip to content

Commit

Permalink
Deprecate skip_customer_return_processing
Browse files Browse the repository at this point in the history
Walk back the use of skip_customer_return_processing and restore the
call to process_return! within process_inventory_unit!.
  • Loading branch information
elia committed Mar 6, 2020
1 parent 6e42e0b commit cad0a4c
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,6 @@ def build_return_items_from_params
return_item = item_params[:id] ? Spree::ReturnItem.find(item_params[:id]) : Spree::ReturnItem.new
return_item.assign_attributes(item_params)

return_item.skip_customer_return_processing = true

if item_params[:reception_status_event].blank?
return redirect_to(new_object_url, flash: { error: 'Reception status choice required' })
end
Expand Down
16 changes: 12 additions & 4 deletions core/app/models/spree/return_item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,13 @@ def reception_completed?
COMPLETED_RECEPTION_STATUSES.map(&:to_s).include?(reception_status.to_s)
end


attr_accessor :skip_customer_return_processing
def skip_customer_return_processing=(value)
@skip_customer_return_processing = value
Deprecation.warn \
'From Solidus v2.11 onwards, #skip_customer_return_processing does ' \
'nothing, and #process_inventory_unit! will restore calling ' \
'customer_return#process_return!', caller(1)
end

# @param inventory_unit [Spree::InventoryUnit] the inventory for which we
# want a return item
Expand Down Expand Up @@ -201,8 +206,11 @@ def process_inventory_unit!
customer_return.stock_location.restock(inventory_unit.variant, 1, customer_return)
end

if customer_return && !skip_customer_return_processing
Deprecation.warn 'From Solidus v2.9 onwards, #process_inventory_unit! will not call customer_return#process_return!'
unless @skip_customer_return_processing.nil?
Deprecation.warn \
'From Solidus v2.11 onwards, #skip_customer_return_processing does ' \
'nothing, and #process_inventory_unit! will restore calling ' \
'customer_return#process_return!'
end

customer_return&.process_return!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

FactoryBot.define do
factory :return_item, class: 'Spree::ReturnItem' do
skip_customer_return_processing { true }
association(:inventory_unit, factory: :inventory_unit, state: :shipped)
association(:return_reason, factory: :return_reason)
return_authorization do |_return_item|
Expand Down
16 changes: 14 additions & 2 deletions core/spec/models/spree/return_item_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@
subject
end

context 'when the `skip_customer_return_processing` flag is not set to true' do
before { return_item.skip_customer_return_processing = false }
context 'when the `skip_customer_return_processing` flag is set' do
before { Spree::Deprecation.silence { return_item.skip_customer_return_processing = false } }

it 'shows a deprecation warning' do
expect(Spree::Deprecation).to receive(:warn)
Expand Down Expand Up @@ -811,4 +811,16 @@
end
end
end

describe '#skip_customer_return_processing=' do
context 'when it receives a value' do
let(:return_item) { described_class.new }
subject { return_item.skip_customer_return_processing = :foo }

it 'shows a deprecation warning' do
expect(Spree::Deprecation).to receive(:warn)
subject
end
end
end
end
1 change: 0 additions & 1 deletion sample/db/samples/reimbursements.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
stock_location: stock_location
)
return_item.reload
return_item.skip_customer_return_processing = true
return_item.receive!
customer_return.process_return!

Expand Down

0 comments on commit cad0a4c

Please sign in to comment.