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 152-157 INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` Link Here
152
('decreaseLoanHighHoldsValue',NULL,'','Specifies a threshold for the minimum number of holds needed to trigger a reduction in loan duration (used with decreaseLoanHighHolds)','Integer'),
152
('decreaseLoanHighHoldsValue',NULL,'','Specifies a threshold for the minimum number of holds needed to trigger a reduction in loan duration (used with decreaseLoanHighHolds)','Integer'),
153
('DefaultClassificationSource','ddc',NULL,'Default classification scheme used by the collection. E.g., Dewey, LCC, etc.','ClassSources'),
153
('DefaultClassificationSource','ddc',NULL,'Default classification scheme used by the collection. E.g., Dewey, LCC, etc.','ClassSources'),
154
('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
('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'),
155
('DefaultHoldExpirationdate','0','','Automatically set expiration date for holds','YesNo'),
156
('DefaultHoldExpirationdatePeriod','0','','How long into the future default expiration date is set to be.','integer'),
157
('DefaultHoldExpirationdateUnitOfTime','days','days|months|years','Which unit of time is used when setting the default expiration date. ','choice'),
155
('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
('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'),
156
('DefaultLongOverdueSkipLostStatuses', '', NULL, 'Skip these lost statuses by default in longoverdue.pl', 'Free'),
159
('DefaultLongOverdueSkipLostStatuses', '', NULL, 'Skip these lost statuses by default in longoverdue.pl', 'Free'),
157
('DefaultLongOverdueChargeValue', '', NULL, "Charge a lost item to the borrower's account when the LOST value of the item changes to n.", 'integer'),
160
('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 894-899 Circulation: Link Here
894
            - pref: UpdateItemWhenLostFromHoldList
894
            - pref: UpdateItemWhenLostFromHoldList
895
              type: textarea
895
              type: textarea
896
              syntax: text/x-yaml
896
              syntax: text/x-yaml
897
        -
898
            - pref: DefaultHoldExpirationdate
899
              default: 0
900
              choices:
901
                  yes: Set
902
                  no: Don't set
903
            - default expiration date for holds automatically.
904
            - If enabled, set expiration date
905
            - pref: DefaultHoldExpirationdatePeriod
906
              default: 0
907
              class: integer
908
            - pref: DefaultHoldExpirationdateUnitOfTime
909
              default: days
910
              choices:
911
                  days: days
912
                  months: months
913
                  years: years
914
            - from reserve date.
897
    Interlibrary loans:
915
    Interlibrary loans:
898
        -
916
        -
899
            - pref: ILLModule
917
            - 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