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

(-)a/Koha/Hold.pm (+15 lines)
Lines 562-567 sub cancel { Link Here
562
    return $self;
562
    return $self;
563
}
563
}
564
564
565
sub store {
566
    my ($self) = @_;
567
568
    if ( C4::Context->preference('DefaultHoldExpirationdate')
569
        and ( not defined $self->expirationdate or $self->expirationdate eq '' ) ){
570
571
        my $period = C4::Context->preference('DefaultHoldExpirationdatePeriod');
572
        my $timeunit = C4::Context->preference('DefaultHoldExpirationdateUnitOfTime');
573
574
        $self->expirationdate( dt_from_string( $self->reservedate )->add( $timeunit => $period ) );
575
    }
576
577
    $self = $self->SUPER::store;
578
}
579
565
=head3 _move_to_old
580
=head3 _move_to_old
566
581
567
my $is_moved = $hold->_move_to_old;
582
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','0','','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','days|months|years','Which unit of time is used when setting the 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 154-159 INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` Link Here
154
('decreaseLoanHighHoldsValue',NULL,'','Specifies a threshold for the minimum number of holds needed to trigger a reduction in loan duration (used with decreaseLoanHighHolds)','Integer'),
154
('decreaseLoanHighHoldsValue',NULL,'','Specifies a threshold for the minimum number of holds needed to trigger a reduction in loan duration (used with decreaseLoanHighHolds)','Integer'),
155
('DefaultClassificationSource','ddc',NULL,'Default classification scheme used by the collection. E.g., Dewey, LCC, etc.','ClassSources'),
155
('DefaultClassificationSource','ddc',NULL,'Default classification scheme used by the collection. E.g., Dewey, LCC, etc.','ClassSources'),
156
('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'),
156
('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'),
157
('DefaultHoldExpirationdate','0','','Automatically set expiration date for holds','YesNo'),
158
('DefaultHoldExpirationdatePeriod','0','','How long into the future default expiration date is set to be.','integer'),
159
('DefaultHoldExpirationdateUnitOfTime','days','days|months|years','Which unit of time is used when setting the default expiration date. ','choice'),
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'),
160
('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'),
158
('DefaultLongOverdueSkipLostStatuses', '', NULL, 'Skip these lost statuses by default in longoverdue.pl', 'Free'),
161
('DefaultLongOverdueSkipLostStatuses', '', NULL, 'Skip these lost statuses by default in longoverdue.pl', 'Free'),
159
('DefaultLongOverdueChargeValue', '', NULL, "Charge a lost item to the borrower's account when the LOST value of the item changes to n.", 'integer'),
162
('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 (+18 lines)
Lines 895-900 Circulation: Link Here
895
            - pref: UpdateItemWhenLostFromHoldList
895
            - pref: UpdateItemWhenLostFromHoldList
896
              type: textarea
896
              type: textarea
897
              syntax: text/x-yaml
897
              syntax: text/x-yaml
898
        -
899
            - pref: DefaultHoldExpirationdate
900
              default: 0
901
              choices:
902
                  yes: Set
903
                  no: Don't set
904
            - default expiration date for holds automatically.
905
            - If enabled, set expiration date
906
            - pref: DefaultHoldExpirationdatePeriod
907
              default: 0
908
              class: integer
909
            - pref: DefaultHoldExpirationdateUnitOfTime
910
              default: days
911
              choices:
912
                  days: days
913
                  months: months
914
                  years: years
915
            - from reserve date.
898
    Interlibrary loans:
916
    Interlibrary loans:
899
        -
917
        -
900
            - pref: ILLModule
918
            - 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