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 <martin.renvoize@ptfs-europe.com>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Fridolin Somers <fridolin.somers@biblibre.com>
This commit is contained in:
Tomás Cohen Arazi 2022-01-13 09:03:20 -03:00 committed by Fridolin Somers
parent 00beba6e5f
commit bbb30495ee

View file

@ -580,6 +580,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