From 4da384e261ac45e6603df58b0e030bd654570db8 Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Thu, 13 Jan 2022 09:03:20 -0300 Subject: [PATCH] Bug 29869: Add Koha::Hold->fill This patch introduces a new method for marking a hold as filled. The code is the result of tracking the following methods in C4::Reserves: - ModReserveFill - GetReserveFee - ChargeReserveFee To test: 1. Apply this patches 2. Run: $ kshell k$ prove t/db_dependent/Koha/Hold.t => SUCCESS: Tests pass! 3. Sign off :-D Signed-off-by: Martin Renvoize Signed-off-by: Kyle M Hall --- Koha/Hold.pm | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/Koha/Hold.pm b/Koha/Hold.pm index 9736dc527f0..451ffa0a8c4 100644 --- a/Koha/Hold.pm +++ b/Koha/Hold.pm @@ -574,6 +574,57 @@ sub cancel { return $self; } +=head3 fill + + $hold->fill; + +This method marks the hold as filled. It effectively moves it to old_reserves. + +=cut + +sub fill { + my ( $self ) = @_; + $self->_result->result_source->schema->txn_do( + sub { + my $patron = $self->patron; + + $self->set( + { + found => 'F', + priority => 0, + } + ); + + $self->_move_to_old; + $self->SUPER::delete(); # Do not add a DELETE log + + # now fix the priority on the others.... + C4::Reserves::_FixPriority({ biblionumber => $self->biblionumber }); + + if ( C4::Context->preference('HoldFeeMode') eq 'any_time_is_collected' ) { + my $fee = $patron->category->reservefee // 0; + if ( $fee > 0 ) { + $patron->account->add_debit( + { + amount => $fee, + description => $self->biblio->title, + user_id => C4::Context->userenv ? C4::Context->userenv->{'number'} : undef, + library_id => C4::Context->userenv ? C4::Context->userenv->{'branch'} : undef, + interface => C4::Context->interface, + type => 'RESERVE', + item_id => $self->itemnumber + } + ); + } + } + + C4::Log::logaction( 'HOLDS', 'FILL', $self->id, $self ) + if C4::Context->preference('HoldsLog'); + } + ); + return $self; +} + =head3 store Override base store method to set default -- 2.30.2