Bug 26498: Set default expiration date for holds

Koha doesn't automatically set expiration date for holds
so they can live in the system forever. This patch adds
new sysprefs to control setting of default expiration
date for holds. Note that expiration date is only set
if input field for it is left blank.

To test:
1. Apply patch and update database.
2. Enable syspref "DefaultHoldExpirationdate" and set some values
to "DefaultHoldExpirationdatePeriod" and
"DefaultHoldExpirationdateUnitOfTime".
3. Add some holds for patron from staff client or OPAC and leave
expiration date input field blank.
=> Holds expiration date should be set according your settings
4. Disable "DefaultHoldExpirationdate" and repeat step 3.
=> Expiration date shouldn't be set.

Also prove prove t/db_dependent/Hold.t

Sponsored-by: Koha-Suomi Oy
Signed-off-by: Andrew Isherwood <andrew.isherwood@ptfs-europe.com>
Signed-off-by: Victor Grousset/tuxayo <victor@tuxayo.net>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
This commit is contained in:
Emmi Takkinen 2020-11-26 14:59:42 +02:00 committed by Jonathan Druart
parent b258a06844
commit 9fe3c489f4
5 changed files with 70 additions and 1 deletions

View File

@ -562,6 +562,21 @@ sub cancel {
return $self;
}
sub store {
my ($self) = @_;
if ( C4::Context->preference('DefaultHoldExpirationdate')
and ( not defined $self->expirationdate or $self->expirationdate eq '' ) ){
my $period = C4::Context->preference('DefaultHoldExpirationdatePeriod');
my $timeunit = C4::Context->preference('DefaultHoldExpirationdateUnitOfTime');
$self->expirationdate( dt_from_string( $self->reservedate )->add( $timeunit => $period ) );
}
$self = $self->SUPER::store;
}
=head3 _move_to_old
my $is_moved = $hold->_move_to_old;

View File

@ -0,0 +1,12 @@
$DBversion = 'XXX'; # will be replaced by the RM
if( CheckVersion( $DBversion ) ) {
# you can use $dbh here like:
# $dbh->do( "ALTER TABLE biblio ADD COLUMN badtaste int" );
$dbh->do(q{INSERT IGNORE INTO systempreferences (variable,value,options,explanation,type) VALUES ('DefaultHoldExpirationdate','0','','Automatically set default expiration date for holds','YesNo') });
$dbh->do(q{INSERT IGNORE INTO systempreferences (variable,value,options,explanation,type) VALUES ('DefaultHoldExpirationdatePeriod','0','','How long into the future default expiration date is set to be.','integer') });
$dbh->do(q{INSERT IGNORE INTO systempreferences (variable,value,options,explanation,type) VALUES ('DefaultHoldExpirationdateUnitOfTime','days','days|months|years','Which unit of time is used when setting the default expiration date. ','choice') });
# Always end with this (adjust the bug info)
NewVersion( $DBversion, 26498, "Bug 26498 - Add option to set a default expire date for holds at reservation time");
}

View File

@ -154,6 +154,9 @@ INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, `
('decreaseLoanHighHoldsValue',NULL,'','Specifies a threshold for the minimum number of holds needed to trigger a reduction in loan duration (used with decreaseLoanHighHolds)','Integer'),
('DefaultClassificationSource','ddc',NULL,'Default classification scheme used by the collection. E.g., Dewey, LCC, etc.','ClassSources'),
('DefaultCountryField008','','','Fill in the default country code for field 008 Range 15-17 of MARC21 - Place of publication, production, or execution. See <a href=\"http://www.loc.gov/marc/countries/countries_code.html\">MARC Code List for Countries</a>','Free'),
('DefaultHoldExpirationdate','0','','Automatically set expiration date for holds','YesNo'),
('DefaultHoldExpirationdatePeriod','0','','How long into the future default expiration date is set to be.','integer'),
('DefaultHoldExpirationdateUnitOfTime','days','days|months|years','Which unit of time is used when setting the default expiration date. ','choice'),
('DefaultLanguageField008','','','Fill in the default language for field 008 Range 35-37 of MARC21 records (e.g. eng, nor, ger, see <a href=\"http://www.loc.gov/marc/languages/language_code.html\">MARC Code List for Languages</a>)','Free'),
('DefaultLongOverdueSkipLostStatuses', '', NULL, 'Skip these lost statuses by default in longoverdue.pl', 'Free'),
('DefaultLongOverdueChargeValue', '', NULL, "Charge a lost item to the borrower's account when the LOST value of the item changes to n.", 'integer'),

View File

@ -896,6 +896,24 @@ Circulation:
- pref: UpdateItemWhenLostFromHoldList
type: textarea
syntax: text/x-yaml
-
- pref: DefaultHoldExpirationdate
default: 0
choices:
yes: Set
no: Don't set
- default expiration date for holds automatically.
- If enabled, set expiration date
- pref: DefaultHoldExpirationdatePeriod
default: 0
class: integer
- pref: DefaultHoldExpirationdateUnitOfTime
default: days
choices:
days: days
months: months
years: years
- from reserve date.
Interlibrary loans:
-
- pref: ILLModule

View File

@ -29,7 +29,7 @@ use Koha::Item;
use Koha::DateUtils;
use t::lib::TestBuilder;
use Test::More tests => 33;
use Test::More tests => 34;
use Test::Exception;
use Test::Warn;
@ -142,6 +142,27 @@ ok( !$hold->is_at_destination(), "Waiting hold where hold branchcode is not the
$item->holdingbranch( $branches[1]->{branchcode} );
ok( $hold->is_at_destination(), "Waiting hold where hold branchcode is the same as the item's holdingbranch is at destination" );
# Test setting expiration date
t::lib::Mocks::mock_preference( 'DefaultHoldExpirationdate', 1 );
t::lib::Mocks::mock_preference( 'DefaultHoldExpirationdatePeriod', 2 );
t::lib::Mocks::mock_preference( 'DefaultHoldExpirationdateUnitOfTime', 'years' );
my $hold_2 = Koha::Hold->new(
{
biblionumber => $biblionumber,
itemnumber => $item->id(),
reservedate => '2020-11-30',
waitingdate => '2020-11-30',
borrowernumber => $borrower->{borrowernumber},
branchcode => $branches[1]->{branchcode},
suspend => 0,
}
);
$hold_2->store();
my $expected_date = dt_from_string( $hold_2->reservedate )->add( years => 2);
is($hold_2->expirationdate->ymd, $expected_date->ymd,'Expiration date is correctly set.');
$schema->storage->txn_rollback();
subtest "delete() tests" => sub {