From ea7265912cdea85c23e9705bb5b1a5a0675c43d4 Mon Sep 17 00:00:00 2001 From: JP <85654561+jp524@users.noreply.github.com> Date: Fri, 31 May 2024 14:00:27 -0500 Subject: [PATCH] Raise error if intervening audit on items for Distribution update --- app/services/distribution_update_service.rb | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/app/services/distribution_update_service.rb b/app/services/distribution_update_service.rb index 5889d2a622..8c35ee860a 100644 --- a/app/services/distribution_update_service.rb +++ b/app/services/distribution_update_service.rb @@ -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 @@ -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?