Skip to content

Commit

Permalink
Raise error if intervening audit on items for Distribution update
Browse files Browse the repository at this point in the history
  • Loading branch information
jp524 committed May 31, 2024
1 parent 3e9963b commit ea72659
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions app/services/distribution_update_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ def initialize(old_distribution, new_distribution_params)
end

def call
prev_storage_location_id = @distribution.storage_location_id
new_storage_location_id = @params[:storage_location_id].to_i
if prev_storage_location_id != new_storage_location_id && Audit.finalized_since?(@distribution, [prev_storage_location_id, new_storage_location_id])
raise "Cannot change the storage location because there has been an intervening audit of some items. " \
"If you need to change the storage location, please reclaim this distribution and create a new distribution from the new storage location"
end

perform_distribution_service do
@old_issued_at = distribution.issued_at
@old_delivery_method = distribution.delivery_method
Expand All @@ -20,6 +27,8 @@ def call
@new_issued_at = distribution.issued_at
@new_delivery_method = distribution.delivery_method
end
rescue => e
OpenStruct.new(success?: false, error: e)
end

def resend_notification?
Expand Down

0 comments on commit ea72659

Please sign in to comment.