View | Details | Raw Unified | Return to bug 26498
Collapse All | Expand All

(-)a/Koha/Hold.pm (+15 lines)
Lines 505-510 sub cancel { Link Here
505
    return $self;
505
    return $self;
506
}
506
}
507
507
508
sub store {
509
    my ($self) = @_;
510
511
    if ( C4::Context->preference('DefaultHoldExpirationdate')
512
        and ( not defined $self->expirationdate or $self->expirationdate eq '' ) ){
513
514
        my $period = C4::Context->preference('DefaultHoldExpirationdatePeriod');
515
        my $timeunit = C4::Context->preference('DefaultHoldExpirationdateUnitOfTime');
516
        
517
        $self->expirationdate( dt_from_string( $self->reservedate )->add( $timeunit => $period ) );
518
    } 
519
520
    $self = $self->SUPER::store;
521
}
522
508
=head3 _move_to_old
523
=head3 _move_to_old
509
524
510
my $is_moved = $hold->_move_to_old;
525
my $is_moved = $hold->_move_to_old;
(-)a/installer/data/mysql/atomicupdate/Bug-26498-Set_default_expiration_date_for_holds.perl (+12 lines)
Line 0 Link Here
1
$DBversion = 'XXX'; # will be replaced by the RM
2
if( CheckVersion( $DBversion ) ) {
3
    # you can use $dbh here like:
4
    # $dbh->do( "ALTER TABLE biblio ADD COLUMN badtaste int" );
5
6
    $dbh->do(q{INSERT IGNORE INTO systempreferences (variable,value,options,explanation,type) VALUES ('DefaultHoldExpirationdate','1','','Automatically set default expiration date for holds','YesNo') });
7
    $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') });
8
    $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') });
9
10
    # Always end with this (adjust the bug info)
11
    NewVersion( $DBversion, 26498, "Bug 26498 - Add option to set a default expire date for holds at reservation time");
12
}
(-)a/installer/data/mysql/mandatory/sysprefs.sql (+3 lines)
Lines 151-156 INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` Link Here
151
('decreaseLoanHighHoldsValue',NULL,'','Specifies a threshold for the minimum number of holds needed to trigger a reduction in loan duration (used with decreaseLoanHighHolds)','Integer'),
151
('decreaseLoanHighHoldsValue',NULL,'','Specifies a threshold for the minimum number of holds needed to trigger a reduction in loan duration (used with decreaseLoanHighHolds)','Integer'),
152
('DefaultClassificationSource','ddc',NULL,'Default classification scheme used by the collection. E.g., Dewey, LCC, etc.','ClassSources'),
152
('DefaultClassificationSource','ddc',NULL,'Default classification scheme used by the collection. E.g., Dewey, LCC, etc.','ClassSources'),
153
('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'),
153
('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'),
154
('DefaultHoldExpirationdate','1','','Automatically set expiration date for holds','YesNo'),
155
('DefaultHoldExpirationdatePeriod','0','','How long into the future default expiration date is set to be.','integer'),
156
('DefaultHoldExpirationdateUnitOfTime','','days|months|years','Which unit of time is used when settimg default expiration date. ','choice'),
154
('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'),
157
('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'),
155
('DefaultLongOverdueSkipLostStatuses', '', NULL, 'Skip these lost statuses by default in longoverdue.pl', 'Free'),
158
('DefaultLongOverdueSkipLostStatuses', '', NULL, 'Skip these lost statuses by default in longoverdue.pl', 'Free'),
156
('DefaultLongOverdueChargeValue', '', NULL, "Charge a lost item to the borrower's account when the LOST value of the item changes to n.", 'integer'),
159
('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 (+15 lines)
Lines 893-898 Circulation: Link Here
893
            - pref: UpdateItemWhenLostFromHoldList
893
            - pref: UpdateItemWhenLostFromHoldList
894
              type: textarea
894
              type: textarea
895
              syntax: text/x-yaml
895
              syntax: text/x-yaml
896
        - 
897
            - pref: DefaultHoldExpirationdate
898
              choices:
899
                  yes: Set
900
                  no: Don't set
901
            - default expiration date for holds automatically.
902
            - If enabled, set expiration date 
903
            - pref: DefaultHoldExpirationdatePeriod
904
              class: integer
905
            - pref: DefaultHoldExpirationdateUnitOfTime
906
              choices:
907
                  days: days
908
                  months: months
909
                  years: years
910
            - from reserve date.
896
    Interlibrary loans:
911
    Interlibrary loans:
897
        -
912
        -
898
            - pref: ILLModule
913
            - pref: ILLModule
(-)a/t/db_dependent/Hold.t (-2 / +22 lines)
Lines 29-35 use Koha::Item; Link Here
29
use Koha::DateUtils;
29
use Koha::DateUtils;
30
use t::lib::TestBuilder;
30
use t::lib::TestBuilder;
31
31
32
use Test::More tests => 33;
32
use Test::More tests => 34;
33
use Test::Exception;
33
use Test::Exception;
34
use Test::Warn;
34
use Test::Warn;
35
35
Lines 142-147 ok( !$hold->is_at_destination(), "Waiting hold where hold branchcode is not the Link Here
142
$item->holdingbranch( $branches[1]->{branchcode} );
142
$item->holdingbranch( $branches[1]->{branchcode} );
143
ok( $hold->is_at_destination(), "Waiting hold where hold branchcode is the same as the item's holdingbranch is at destination" );
143
ok( $hold->is_at_destination(), "Waiting hold where hold branchcode is the same as the item's holdingbranch is at destination" );
144
144
145
# Test setting expiration date
146
t::lib::Mocks::mock_preference( 'DefaultHoldExpirationdate', 1 );
147
t::lib::Mocks::mock_preference( 'DefaultHoldExpirationdatePeriod', 2 );
148
t::lib::Mocks::mock_preference( 'DefaultHoldExpirationdateUnitOfTime', 'years' );
149
150
my $hold_2 = Koha::Hold->new(
151
    {
152
        biblionumber   => $biblionumber,
153
        itemnumber     => $item->id(),
154
        reservedate    => '2020-11-30',
155
        waitingdate    => '2020-11-30',
156
        borrowernumber => $borrower->{borrowernumber},
157
        branchcode     => $branches[1]->{branchcode},
158
        suspend        => 0,
159
    }
160
);
161
$hold_2->store();
162
163
my $expected_date = dt_from_string( $hold_2->reservedate )->add( years => 2); 
164
is($hold_2->expirationdate->ymd, $expected_date->ymd,'Expiration date is correctly set.');
165
145
$schema->storage->txn_rollback();
166
$schema->storage->txn_rollback();
146
167
147
subtest "delete() tests" => sub {
168
subtest "delete() tests" => sub {
148
- 

Return to bug 26498