diff --git a/Koha/Hold.pm b/Koha/Hold.pm index b3bf4a02b7..8f0cd75ac2 100644 --- a/Koha/Hold.pm +++ b/Koha/Hold.pm @@ -980,10 +980,14 @@ sub store { sub _set_default_expirationdate { my $self = shift; - my $period = C4::Context->preference('DefaultHoldExpirationdatePeriod') || 0; + my $period = C4::Context->preference('DefaultHoldExpirationdatePeriod'); my $timeunit = C4::Context->preference('DefaultHoldExpirationdateUnitOfTime') || 'days'; - $self->expirationdate( dt_from_string( $self->reservedate )->add( $timeunit => $period ) ); + if ( defined C4::Context->preference('DefaultHoldExpirationdatePeriod') + && C4::Context->preference('DefaultHoldExpirationdatePeriod') ne '' ) + { + $self->expirationdate( dt_from_string( $self->reservedate )->add( $timeunit => $period ) ); + } } =head3 _move_to_old diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref index 291c6ccec6..c50abdfa3d 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref @@ -1078,6 +1078,7 @@ Circulation: months: months years: years - from reserve date. + -
NOTE: If DefaultHoldExpirationdatePeriod is left blank, no default expiration date is set.
- - When placing a hold via the staff interface default the pickup location to the - pref: DefaultHoldPickupLocation diff --git a/t/db_dependent/Hold.t b/t/db_dependent/Hold.t index 23e42c4291..21572e476c 100755 --- a/t/db_dependent/Hold.t +++ b/t/db_dependent/Hold.t @@ -160,7 +160,7 @@ $schema->storage->txn_rollback(); subtest "store() tests" => sub { - plan tests => 7; + plan tests => 8; $schema->storage->txn_begin(); @@ -292,6 +292,26 @@ subtest "store() tests" => sub { 'Expiration date set same as patron_expiration_date after reverting holds waiting status.' ); + # Do not set expiration date for hold if no period is set + t::lib::Mocks::mock_preference( 'DefaultHoldExpirationdatePeriod', '' ); + $hold = Koha::Hold->new( + { + biblionumber => $biblio->biblionumber, + itemnumber => $item->id, + reservedate => '2022-12-14', + waitingdate => '2022-12-14', + borrowernumber => $borrower->borrowernumber, + branchcode => $library->branchcode, + suspend => 0, + } + )->store; + $hold->discard_changes; + + is( + $hold->expirationdate, + undef, 'Expiration date not set if "DefaultHoldExpirationdatePeriod" is left empty.' + ); + $schema->storage->txn_rollback(); };