@@ -, +, @@ --- Koha/Hold.pm | 15 ++++++++++++ ...Set_default_expiration_date_for_holds.perl | 12 ++++++++++ installer/data/mysql/mandatory/sysprefs.sql | 3 +++ .../admin/preferences/circulation.pref | 15 ++++++++++++ t/db_dependent/Hold.t | 23 ++++++++++++++++++- 5 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 installer/data/mysql/atomicupdate/Bug-26498-Set_default_expiration_date_for_holds.perl --- a/Koha/Hold.pm +++ a/Koha/Hold.pm @@ -505,6 +505,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; --- a/installer/data/mysql/atomicupdate/Bug-26498-Set_default_expiration_date_for_holds.perl +++ a/installer/data/mysql/atomicupdate/Bug-26498-Set_default_expiration_date_for_holds.perl @@ -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','1','','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|months|years','Which unit of time is used when settimg 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"); +} --- a/installer/data/mysql/mandatory/sysprefs.sql +++ a/installer/data/mysql/mandatory/sysprefs.sql @@ -151,6 +151,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 MARC Code List for Countries','Free'), +('DefaultHoldExpirationdate','1','','Automatically set expiration date for holds','YesNo'), +('DefaultHoldExpirationdatePeriod','0','','How long into the future default expiration date is set to be.','integer'), +('DefaultHoldExpirationdateUnitOfTime','','days|months|years','Which unit of time is used when settimg 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 MARC Code List for Languages)','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'), --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref +++ a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref @@ -893,6 +893,21 @@ Circulation: - pref: UpdateItemWhenLostFromHoldList type: textarea syntax: text/x-yaml + - + - pref: DefaultHoldExpirationdate + choices: + yes: Set + no: Don't set + - default expiration date for holds automatically. + - If enabled, set expiration date + - pref: DefaultHoldExpirationdatePeriod + class: integer + - pref: DefaultHoldExpirationdateUnitOfTime + choices: + days: days + months: months + years: years + - from reserve date. Interlibrary loans: - - pref: ILLModule --- a/t/db_dependent/Hold.t +++ a/t/db_dependent/Hold.t @@ -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 { --