Bug 37868: Remove C4::Reserves::ToggleSuspend

We can easily replace the calls by ->suspend_hold and ->resume.

Test plan:
No behaviour changes expected.
Confirm that you can still suspend and resume holds (OPAC+staff)

Signed-off-by: Olivier V <olivier.vezina@inLibro.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Signed-off-by: Katrin Fischer <katrin.fischer@bsz-bw.de>
This commit is contained in:
Jonathan Druart 2024-09-09 14:53:05 +02:00 committed by Katrin Fischer
parent 197039eb02
commit d3051d2e23
No known key found for this signature in database
GPG Key ID: 0EF6E2C03357A834
6 changed files with 66 additions and 68 deletions

View File

@ -129,7 +129,6 @@ BEGIN {
ToggleLowestPriority
ReserveSlip
ToggleSuspend
SuspendAll
CalculatePriority
@ -1460,28 +1459,6 @@ sub ToggleLowestPriority {
_FixPriority({ reserve_id => $reserve_id, rank => '999999' });
}
=head2 ToggleSuspend
ToggleSuspend( $reserve_id );
This function sets the suspend field to true if is false, and false if it is true.
If the reserve is currently suspended with a suspend_until date, that date will
be cleared when it is unsuspended.
=cut
sub ToggleSuspend {
my ( $reserve_id, $suspend_until ) = @_;
my $hold = Koha::Holds->find( $reserve_id );
if ( $hold->is_suspended ) {
$hold->resume()
} else {
$hold->suspend_hold( $suspend_until );
}
}
=head2 SuspendAll
SuspendAll(

View File

@ -244,13 +244,15 @@
<td>
[% IF Koha.Preference('SuspendHoldsIntranet') %]
[% UNLESS ( hold.found ) %]
<button class="btn btn-default btn-xs toggle-suspend" data-reserve-id="[% hold.reserve_id | html %]" data-biblionumber="[% hold.biblionumber | html %]">
[% IF ( hold.suspend ) %]
[% IF ( hold.suspend ) %]
<button class="btn btn-default btn-xs unsuspend-hold" data-reserve-id="[% hold.reserve_id | html %]" data-biblionumber="[% hold.biblionumber | html %]">
<i class="fa fa-play" aria-hidden="true"></i> Unsuspend
[% ELSE %]
</button>
[% ELSE %]
<button class="btn btn-default btn-xs suspend-hold" data-reserve-id="[% hold.reserve_id | html %]" data-biblionumber="[% hold.biblionumber | html %]">
<i class="fa fa-pause" aria-hidden="true"></i> Suspend
[% END %]
</button>
</button>
[% END %]
[% IF Koha.Preference('AutoResumeSuspendedHolds') %]
<label for="suspend_until_[% hold.reserve_id | html %]">[% IF ( hold.suspend ) %] on [% ELSE %] until [% END %]</label>

View File

@ -445,37 +445,56 @@ $(document).ready(function() {
});
});
$(".toggle-suspend").on('click', function(e) {
e.preventDefault();
let reserve_id = $(this).data('reserve-id');
let biblionumber = $(this).data('biblionumber');
let suspend_until = $('#suspend_until_' + reserve_id).val();
function toggle_suspend(node, inputs) {
let reserve_id = $(node).data("reserve-id");
let biblionumber = $(node).data("biblionumber");
let suspendForm = $("#hold-actions-form").attr({
action: 'request.pl',
method: 'post'
});
let sus_op = $("<input />").attr({
type: 'hidden',
name: 'op',
value: 'cud-toggleSuspend'
action: "request.pl",
method: "post",
});
let sus_bn = $("<input />").attr({
type: 'hidden',
name: 'biblionumber',
value: biblionumber
type: "hidden",
name: "biblionumber",
value: biblionumber,
});
let sus_ri = $("<input />").attr({
type: 'hidden',
name: 'reserve_id',
type: "hidden",
name: "reserve_id",
value: reserve_id,
});
let sus_su = $("<input />").attr({
type: 'hidden',
name: 'suspend_until',
value: suspend_until
});
suspendForm.append( sus_op, sus_bn, sus_ri, sus_su );
inputs.push(sus_bn, sus_ri);
suspendForm.append(inputs);
$("#hold-actions-form").submit();
return false;
}
$(".suspend-hold").on("click", function (e) {
e.preventDefault();
let reserve_id = $(this).data("reserve-id");
let suspend_until = $("#suspend_until_" + reserve_id).val();
let inputs = [
$("<input />").attr({
type: "hidden",
name: "op",
value: "cud-suspend",
}),
$("<input />").attr({
type: "hidden",
name: "suspend_until",
value: suspend_until,
}),
];
return toggle_suspend(this, inputs);
});
$(".unsuspend-hold").on("click", function (e) {
e.preventDefault();
let inputs = [
$("<input />").attr({
type: "hidden",
name: "op",
value: "cud-unsuspend",
}),
];
return toggle_suspend(this, inputs);
});
});

View File

@ -19,7 +19,7 @@ use Modern::Perl;
use CGI qw ( -utf8 );
use C4::Output;
use C4::Reserves qw( ToggleSuspend SuspendAll );
use C4::Reserves qw( SuspendAll );
use C4::Auth qw( get_template_and_user );
use Koha::Patrons;
@ -38,11 +38,14 @@ my $suspend = $query->param('suspend');
my $suspend_until = $query->param('suspend_until') || undef;
my $reserve_id = $query->param('reserve_id');
if ( ( $op eq 'cud-suspend' || $op eq 'cud-unsuspend' ) && $reserve_id ) {
if ( $op eq 'cud-suspend' ) {
my $patron = Koha::Patrons->find($borrowernumber);
my $hold = $patron->holds->find($reserve_id);
ToggleSuspend( $reserve_id, $suspend_until )
if $hold && $hold->is_cancelable_from_opac;
$hold->suspend_hold($suspend_until) if $hold && $hold->is_cancelable_from_opac;
} elsif ( $op eq 'cud-unsuspend' ) {
my $patron = Koha::Patrons->find($borrowernumber);
my $hold = $patron->holds->find($reserve_id);
$hold->resume if $hold && $hold->is_cancelable_from_opac;
}
elsif( $op eq 'cud-suspend_all' || $op eq 'cud-unsuspend_all' ) {
SuspendAll(

View File

@ -33,7 +33,7 @@ use List::MoreUtils qw( uniq );
use Date::Calc qw( Date_to_Days );
use C4::Output qw( output_html_with_http_headers );
use C4::Auth qw( get_template_and_user );
use C4::Reserves qw( RevertWaitingStatus AlterPriority ToggleLowestPriority ToggleSuspend CanBookBeReserved GetMaxPatronHoldsForRecord CanItemBeReserved IsAvailableForItemLevelRequest );
use C4::Reserves qw( RevertWaitingStatus AlterPriority ToggleLowestPriority CanBookBeReserved GetMaxPatronHoldsForRecord CanItemBeReserved IsAvailableForItemLevelRequest );
use C4::Items qw( get_hostitemnumbers_of );
use C4::Koha qw( getitemtypeimagelocation );
use C4::Serials qw( CountSubscriptionFromBiblionumber );
@ -120,10 +120,15 @@ elsif ( $op eq 'cud-setLowestPriority' ) {
my $reserve_id = $input->param('reserve_id');
ToggleLowestPriority($reserve_id);
}
elsif ( $op eq 'cud-toggleSuspend' ) {
elsif ( $op eq 'cud-suspend' ) {
my $reserve_id = $input->param('reserve_id');
my $suspend_until = $input->param('suspend_until');
ToggleSuspend( $reserve_id, $suspend_until );
my $hold = Koha::Holds->find($reserve_id);
$hold->suspend_hold($suspend_until) if $hold;
} elsif ( $op eq 'cud-unsuspend' ) {
my $reserve_id = $input->param('reserve_id');
my $hold = Koha::Holds->find($reserve_id);
$hold->resume() if $hold;
}
elsif ( $op eq 'cud-cancel_bulk' ) {
my $cancellation_reason = $input->param("cancellation-reason");

View File

@ -7,7 +7,7 @@ use t::lib::TestBuilder;
use C4::Context;
use Test::More tests => 74;
use Test::More tests => 72;
use Test::Exception;
use MARC::Record;
@ -15,7 +15,7 @@ use MARC::Record;
use C4::Biblio;
use C4::Calendar;
use C4::Items;
use C4::Reserves qw( AddReserve CalculatePriority ModReserve ToggleSuspend AutoUnsuspendReserves SuspendAll ModReserveMinusPriority AlterPriority CanItemBeReserved CheckReserves MoveReserve );
use C4::Reserves qw( AddReserve CalculatePriority ModReserve AutoUnsuspendReserves SuspendAll ModReserveMinusPriority AlterPriority CanItemBeReserved CheckReserves MoveReserve );
use C4::Circulation qw( CanBookBeRenewed );
use Koha::Biblios;
@ -160,14 +160,6 @@ ModReserve({ # call without reserve_id
$hold = Koha::Holds->find( $reserve_id );
ok( $hold->priority eq '3', "Test ModReserve, priority changed correctly" );
ToggleSuspend( $reserve_id );
$hold = Koha::Holds->find( $reserve_id );
ok( ! $hold->suspend, "Test ToggleSuspend(), no date" );
ToggleSuspend( $reserve_id, '2012-01-01' );
$hold = Koha::Holds->find( $reserve_id );
is( $hold->suspend_until, '2012-01-01 00:00:00', "Test ToggleSuspend(), with date" );
AutoUnsuspendReserves();
$hold = Koha::Holds->find( $reserve_id );
ok( ! $hold->suspend, "Test AutoUnsuspendReserves()" );