From f8c7e4f7740f4cbf080b87640a59696961963c93 Mon Sep 17 00:00:00 2001 From: Magnus Enger Date: Fri, 13 Dec 2019 13:17:55 +0100 Subject: [PATCH] Bug 24239: Let the ILL module set ad hoc hard due dates The Swedish Libris ILL backend lets librarians store a specific due date when an ILL loan is received. This is stored as a ILL request attribute. This patch adds a syspref that can take the name of the illrequestattribute used to store the specific date. If the syspref is set, and if an item is connected to an ILL request, the due date will be taken from the illrequestattribute, instead of being calculated in the regular way, based on patroncategory and itemtype. To test: - Apply the patch and make sure the atomic database update is run - Use the FreeForm backend to add one ILL request. Take note of the illrequest_id of the request you created. We refer to this as "x" below. - Connect a biblio (with biblionumber y), that has an item with a barcode, to the ILL request directly in the database: UPADTE illrequests SET biblio_id = y WHERE illrequest_id = x; - Add an attribute to the ILL request directly in the database: INSERT INTO illrequestattributes SET illrequest_id = x, type = 'illduedate', value = '2023-01-01'; - Enter 'illduedate' as a value for the ILLUseExactDueDate syspref. - Go to circulation and issue the barcode of the item to the patron associated with the FreeForm ILL request. Verify that the loan gets a due date of 2023-01-01. - Ideally: return the item and issue it again through SIP2 and SCO, and verify that the due date is still 2023-01-01. (I don't think the REST API supports issuing yet?) - Verify that there are no regressions, so that regular calculation of due dates still work, if ILLUseExactDueDate is empty or not. --- C4/Circulation.pm | 23 ++++++++++++++++++++++ .../bug24239-ad-hoc-due-date-for-ill.perl | 10 ++++++++++ installer/data/mysql/sysprefs.sql | 1 + .../en/modules/admin/preferences/circulation.pref | 4 ++++ 4 files changed, 38 insertions(+) create mode 100644 installer/data/mysql/atomicupdate/bug24239-ad-hoc-due-date-for-ill.perl diff --git a/C4/Circulation.pm b/C4/Circulation.pm index 67a986b417..2a51504bf4 100644 --- a/C4/Circulation.pm +++ b/C4/Circulation.pm @@ -1362,6 +1362,29 @@ sub AddIssue { $datedue = CalcDateDue( $issuedate, $itype, $branchcode, $borrower ); } + + # Check if we need to use an exact due date set by the ILL module + if ( C4::Context->preference('ILLUseExactDueDate') ) { + # Check if there is an ILL connected with the biblio of the item we are issuing + my $biblionumber = $item_object->biblionumber; + my @illrequests = Koha::Illrequests->search({ biblio_id => $biblionumber }); + if ( @illrequests ) { + # There could be more than one ILL request connected with a + # given biblio, so we need to make sure we find the right one + foreach my $req ( @illrequests ) { + if ( $borrower->{ 'borrowernumber' } == $req->borrowernumber ) { + # We found the right request, now get the proper attribute + my $ill_date_string = $req->illrequestattributes->find({ type => C4::Context->preference('ILLUseExactDueDate') })->value; + warn $ill_date_string; + my $ill_dt = dt_from_string( $ill_date_string ); + $ill_dt->set_hour(23); + $ill_dt->set_minute(59); + $datedue = $ill_dt; + } + } + } + } + $datedue->truncate( to => 'minute' ); my $patron = Koha::Patrons->find( $borrower ); diff --git a/installer/data/mysql/atomicupdate/bug24239-ad-hoc-due-date-for-ill.perl b/installer/data/mysql/atomicupdate/bug24239-ad-hoc-due-date-for-ill.perl new file mode 100644 index 0000000000..cde66c0e30 --- /dev/null +++ b/installer/data/mysql/atomicupdate/bug24239-ad-hoc-due-date-for-ill.perl @@ -0,0 +1,10 @@ +$DBversion = 'XXX'; +if( CheckVersion( $DBversion ) ) { + $dbh->do( q{ + INSERT IGNORE INTO systempreferences (variable,value,options,explanation,type) + VALUES ('ILLUseExactDueDate',NULL,NULL,'Use this ILL request attribute to set a specific due date when a document on ILL loan is issued.','multiple') + }); + + SetVersion( $DBversion ); + print "Upgrade to $DBversion done (Bug 24239 - Let the ILL module set ad hoc hard due dates)\n"; +} diff --git a/installer/data/mysql/sysprefs.sql b/installer/data/mysql/sysprefs.sql index d67a02b367..8c6bea43f8 100644 --- a/installer/data/mysql/sysprefs.sql +++ b/installer/data/mysql/sysprefs.sql @@ -239,6 +239,7 @@ INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` ('ILLModuleCopyrightClearance','','70|10','Enter text to enable the copyright clearance stage of request creation. Text will be displayed','Textarea'), ('ILLModuleUnmediated','0','','If enabled, try to immediately progress newly placed ILL requests.','YesNo'), ('ILLOpacbackends',NULL,NULL,'ILL backends to enabled for OPAC initiated requests','multiple'), +('ILLUseExactDueDate',NULL,NULL,'Use this ILL request attribute to set a specific due date when a document on ILL loan is issued.','multiple'), ('ILS-DI','0','','Enables ILS-DI services at OPAC.','YesNo'), ('ILS-DI:AuthorizedIPs','','Restricts usage of ILS-DI to some IPs','.','Free'), ('ImageLimit','5','','Limit images stored in the database by the Patron Card image manager to this number.','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 f2379e797e..fa37ba025e 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 @@ -881,6 +881,10 @@ Circulation: no: Disable - unmediated Interlibrary loan requests. If enabled and the ILL backend supports it, the newly created requests are immediately requested by backend. - + - Use the ILL request attribute + - pref: ILLUseExactDueDate + - to set an exact due date for an ILL loan, from the ILL module. Leave empty to calculate due dates the standard way. + - - pref: CirculateILL default: 0 choices: -- 2.11.0