From 079b248bb4fbd5f34ea4ddaab412cddbed8a6fc1 Mon Sep 17 00:00:00 2001 From: Mike Rylander Date: Mon, 10 Jul 2017 14:41:19 -0400 Subject: [PATCH] serials: Respect the "Previous Issuance Copy Location" YAOUS Signed-off-by: Mike Rylander --- .../src/perlmods/lib/OpenILS/Application/Serial.pm | 52 ++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Serial.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Serial.pm index 73c8d5b778..f58c805796 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Serial.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Serial.pm @@ -1340,6 +1340,7 @@ sub unitize_items { } my %found_stream_ids; my %found_types; + my $prev_loc_setting_map = {}; my %stream_ids_by_unit_id; @@ -1443,6 +1444,57 @@ sub unitize_items { my $evt = _update_sitem($editor, undef, $item); return $evt if $evt; + + if ($mode eq 'receive') { + my $sdists = $editor->search_serial_distribution([ + {"+sstr" => {"id" => $stream_id}}, + { + "join" => {"sstr" => {}}, + "flesh" => 1, + "flesh_fields" => {"sdist" => ["subscription"]} + }]); + + #------------------------------------------------------------------------- + # The following is copied from open-ils.serial.receive_items.one_unit_per + + # Fetch a list of issuances with received copies already existing + # on this distribution (and with the same holding type on the + # issuance). This will be used in up to two places: once when building + # a summary, once when changing the copy location of the previous + # issuance's copy. + my $issuances_received = _issuances_received($editor, $item); + if ($U->event_code($issuances_received)) { + $editor->rollback; + return $issuances_received; + } + + # Find out if we need to to deal with previous copy location changing. + my $ou = $sdists->[0]->holding_lib; + unless (exists $prev_loc_setting_map->{$ou}) { + $prev_loc_setting_map->{$ou} = $U->ou_ancestor_setting_value( + $ou, "serial.prev_issuance_copy_location", $editor + ); + } + + # If there is a previous copy location setting, we need the previous + # issuance, from which we can in turn look up the item attached to the + # same stream we're on now. + if ($prev_loc_setting_map->{$ou}) { + if (my $prev_iss = + _previous_issuance($issuances_received, $item->issuance)) { + + # Now we can change the copy location of the previous unit, + # if needed. + return $editor->event if defined $U->event_code( + move_previous_unit( + $editor, $prev_iss, $item, $prev_loc_setting_map->{$ou} + ) + ); + } + } + #------------------------------------------------------------------------- + } + } # cleanup 'dead' units (units which are now emptied of their items) -- 2.11.0