[Koha-bugs] [Bug 26498] Add option to set a default expire date for holds at reservation time

bugzilla-daemon at bugs.koha-community.org bugzilla-daemon at bugs.koha-community.org
Wed Jun 16 12:51:22 CEST 2021


https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=26498

--- Comment #30 from Tadas <tadas.kaupa at gmail.com> ---
Comment on attachment 114663
  --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=114663
Bug 26498: Set default expiration date for holds

>From 9fcb4bc1baf12a5471bec6997af4ac41da9a3db7 Mon Sep 17 00:00:00 2001
>From: Emmi Takkinen <emmi.takkinen at outlook.com>
>Date: Thu, 26 Nov 2020 14:59:42 +0200
>Subject: [PATCH] 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 at ptfs-europe.com>
>---
> Koha/Hold.pm                                  | 15 ++++++++++++
> ...Set_default_expiration_date_for_holds.perl | 12 ++++++++++
> installer/data/mysql/mandatory/sysprefs.sql   |  3 +++
> .../admin/preferences/circulation.pref        | 18 +++++++++++++++
> t/db_dependent/Hold.t                         | 23 ++++++++++++++++++-
> 5 files changed, 70 insertions(+), 1 deletion(-)
> create mode 100644 installer/data/mysql/atomicupdate/Bug-26498-Set_default_expiration_date_for_holds.perl
>
>diff --git a/Koha/Hold.pm b/Koha/Hold.pm
>index 7754691238..33f474cfba 100644
>--- a/Koha/Hold.pm
>+++ b/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;
>diff --git a/installer/data/mysql/atomicupdate/Bug-26498-Set_default_expiration_date_for_holds.perl b/installer/data/mysql/atomicupdate/Bug-26498-Set_default_expiration_date_for_holds.perl
>new file mode 100644
>index 0000000000..0fc61b50e4
>--- /dev/null
>+++ b/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','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 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");
>+}
>\ No newline at end of file
>diff --git a/installer/data/mysql/mandatory/sysprefs.sql b/installer/data/mysql/mandatory/sysprefs.sql
>index 2ea427bdd2..5b6587ee05 100644
>--- a/installer/data/mysql/mandatory/sysprefs.sql
>+++ b/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 <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 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 <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'),
>diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref
>index 9bd26d5aa1..430aaaa25a 100644
>--- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref
>+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref
>@@ -893,6 +893,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
>diff --git a/t/db_dependent/Hold.t b/t/db_dependent/Hold.t
>index 5b71b64292..c86807e3a9 100755
>--- a/t/db_dependent/Hold.t
>+++ b/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 {
>-- 
>2.20.1

-- 
You are receiving this mail because:
You are watching all bug changes.


More information about the Koha-bugs mailing list