From 2830e54e56389e40700f3a6120f6d85204c69ba5 Mon Sep 17 00:00:00 2001 From: Baptiste Date: Wed, 4 Dec 2024 16:43:15 +0100 Subject: [PATCH] Bug 35292: Have UpdateNotForLoanStatusOnCheckOut and UpdateNotForLoanStatusOnCheckIn use the same function MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Both sysprefs use the same codebase. Hence the recent upgrades for UpdateNotForLoanStatusOnCheckOut were not applyied to checkout. In this patch, we refacto code in order to have them both use the same function. 1 - Set UpdateNotForLoanStatusOnCheckin to 2: 0 2 - Set UpdateNotForLoanStatusOnCheckout to _ALL_: 0: 2 3 - Check out a book -> Its notforloan status is set to 2 3b - Check you have 2, 3 and 4 in notforloan, if not add those values with any description 4 - Check in the book -> Its notforloan status is set to 0, you get a notification 6 - APPLY PATCH and update database 7 - Set UpdateNotForLoanStatusOnCheckin to _ALL_: 2: 0 BK: 3: 0 CR: 4: 0 8 - Set UpdateNotForLoanStatusOnCheckOut to _ALL_: 0: 2 BK: 0: 3 CR: 0: 4 8 - Check out a book -> Its notforloan status is set to 3 9 - Check in the book -> Its notforloan status is set to 0, you get a notification 10 - Check out a continuing resource -> Its notforloan status is set to 4 11 - Check in a continuing resource -> Its notforloan status is set to 0 11 - Check out another type of resource -> Its notforloan status is set to 2 12 - Check in the document -> Its notforloan status is set to 0 Signed-off-by: Emmanuel Bétemps --- C4/Circulation.pm | 73 +++++++++++++++++++++++------------------------ 1 file changed, 35 insertions(+), 38 deletions(-) diff --git a/C4/Circulation.pm b/C4/Circulation.pm index 31794b7c02..79b6beb8a1 100644 --- a/C4/Circulation.pm +++ b/C4/Circulation.pm @@ -1836,17 +1836,7 @@ sub AddIssue { $item_unblessed->{charge} = $charge; } } - - my $rules = C4::Context->yaml_preference('UpdateNotForLoanStatusOnCheckout'); - if ($rules) { - foreach my $key ( keys %$rules ) { - if ( $item_object->notforloan eq $key ) { - $item_object->notforloan( $rules->{$key} ) - ->store( { log_action => 0, skip_record_index => 1 } ); - last; - } - } - } + _updateNotForLoanFromYaml( $item_object, 'UpdateNotForLoanStatusOnCheckout' ); # Record the fact that this book was issued. C4::Stats::UpdateStats( @@ -2175,7 +2165,7 @@ sub AddReturn { $branch = C4::Context->userenv->{'branch'} unless $branch; # we trust userenv to be a safe fallback/default my $return_date_specified = !!$return_date; $return_date //= dt_from_string(); - my $messages; + my $messages = {}; my $patron; my $doreturn = 1; my $validTransfer = 1; @@ -2256,32 +2246,7 @@ sub AddReturn { $messages->{$loc_msg_key} = $loc_messages->{$loc_msg_key}; } - my $rules = C4::Context->yaml_preference('UpdateNotForLoanStatusOnCheckin'); - if ($rules) { - if ( defined $rules->{ $item->itype } ) { - foreach my $notloan_rule_key ( keys %{ $rules->{ $item->itype } } ) { - if ( $item->notforloan eq $notloan_rule_key ) { - $messages->{'NotForLoanStatusUpdated'} = - { from => $item->notforloan, to => $rules->{ $item->itype }->{$notloan_rule_key} }; - $item->notforloan( $rules->{ $item->itype }->{$notloan_rule_key} ) - ->store( { log_action => 0, skip_record_index => 1, skip_holds_queue => 1 } ) - unless $rules->{ $item->itype }->{$notloan_rule_key} eq 'ONLYMESSAGE'; - last; - } - } - } elsif ( defined $rules->{'_ALL_'} ) { - foreach my $notloan_rule_key ( keys %{ $rules->{'_ALL_'} } ) { - if ( $item->notforloan eq $notloan_rule_key ) { - $messages->{'NotForLoanStatusUpdated'} = - { from => $item->notforloan, to => $rules->{'_ALL_'}->{$notloan_rule_key} }; - $item->notforloan( $rules->{'_ALL_'}->{$notloan_rule_key} ) - ->store( { log_action => 0, skip_record_index => 1, skip_holds_queue => 1 } ) - unless $rules->{'_ALL_'}->{$notloan_rule_key} eq 'ONLYMESSAGE'; - last; - } - } - } - } + _updateNotForLoanFromYaml( $item, 'UpdateNotForLoanStatusOnCheckin', $messages ); # check if the return is allowed at this branch my ( $returnallowed, $message ) = CanBookBeReturned( $item->unblessed, $branch ); @@ -4807,6 +4772,38 @@ sub _CanBookBeAutoRenewed { return "ok"; } +sub _updateNotForLoanFromYaml { + my ( $item, $NotForLoanUpdatePreference, $messages ) = @_; + + + my $rules = C4::Context->yaml_preference($NotForLoanUpdatePreference); + if ($rules) { + if ( defined $rules->{ $item->itype } ) { + foreach my $notloan_rule_key ( keys %{ $rules->{ $item->itype } } ) { + if ( $item->notforloan eq $notloan_rule_key ) { + $messages->{'NotForLoanStatusUpdated'} = + { from => $item->notforloan, to => $rules->{ $item->itype }->{$notloan_rule_key} }; + $item->notforloan( $rules->{ $item->itype }->{$notloan_rule_key} ) + ->store( { log_action => 0, skip_record_index => 1, skip_holds_queue => 1 } ) + unless $rules->{ $item->itype }->{$notloan_rule_key} eq 'ONLYMESSAGE'; + last; + } + } + } elsif ( defined $rules->{'_ALL_'} ) { + foreach my $notloan_rule_key ( keys %{ $rules->{'_ALL_'} } ) { + if ( $item->notforloan eq $notloan_rule_key ) { + $messages->{'NotForLoanStatusUpdated'} = + { from => $item->notforloan, to => $rules->{'_ALL_'}->{$notloan_rule_key} }; + $item->notforloan( $rules->{'_ALL_'}->{$notloan_rule_key} ) + ->store( { log_action => 0, skip_record_index => 1, skip_holds_queue => 1 } ) + unless $rules->{'_ALL_'}->{$notloan_rule_key} eq 'ONLYMESSAGE'; + last; + } + } + } + } +} + 1; __END__ -- 2.39.5