From 02a3587c7c0266e7358e29a77bd945e0bcf579db Mon Sep 17 00:00:00 2001 From: Aleisha Amohia Date: Wed, 9 Jul 2025 03:25:01 +0000 Subject: [PATCH] Bug 39985: Set items.onloan when recall adjusts checkout due date This enhancement ensures the due date stored in items.onloan is changed when a recall causes a checkout due date to change. To test: 1. Enable UseRecalls syspref and set corresponding circulation rules: - Recalls allowed - Recalls per record - On shelf recalls allowed - set to "If any unavailable" - Recall due date interval - set to 1 - Recall pickup period 2. Check out an item to a patron (Patron A) 2a. Make sure this patron has a primary email address set 2b. Check the patron's messaging preferences - make sure this patron has the 'Email' checkbox checked for the 'Return recalled item' notice 3. Go to Tools -> Notices & slips and find the RETURN_RECALLED_ITEM notice. In the Email notice, change "[% checkout.date_due | $KohaDates %]" to "[% item.onloan | $KohaDates %]" and Save. 4. Log into the OPAC as another patron 5. Search for the item checked out in step 2, and place a recall on that item 6. Search for that item in the staff interface => Note that the item status says, "Checked out to : due " 7. Create the following SQL report in the reports module, using the barcode of the item that was recalled: SELECT onloan FROM items WHERE barcode='xxxxxxxxx' 8. Run the report => The onloan value is still set to the item's original due date, not the updated due date of tomorrow 9. Go to Patron A's account again and view their Notices tab. Click on the 'Notification to return a recalled item' => The original due date is used in the notice. 10. Apply the patch and restart services 11. Reset to run the tests again: - Check in the item, but do not confirm the recall in the pop-up - Go to the biblio detail page and cancel the recall 12. Repeat steps 2 to 5. 13. Run your report again (step 8) => The onloan value should now show the updated due date of tomorrow 14. View Patron A's latest 'Notification to return a recalled item' notice (step 9) => The updated due date should be used in the notice. 15. Confirm tests pass - t/db_dependent/Koha/Recalls.t Sponsored-by: Auckland University of Technology --- Koha/Recalls.pm | 9 +++++++-- t/db_dependent/Koha/Recalls.t | 8 +++++++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/Koha/Recalls.pm b/Koha/Recalls.pm index 2881f5948fa..fb11be78c99 100644 --- a/Koha/Recalls.pm +++ b/Koha/Recalls.pm @@ -157,8 +157,13 @@ sub add_recall { second => $checkout_due_date->second } )->add( days => $due_interval ); - $checkout->update( { date_due => $recall_due_date } ) - if DateTime->compare( $recall_due_date, $checkout_due_date ) == -1; + + # update checkout due date if recall due date is sooner + if ( DateTime->compare( $recall_due_date, $checkout_due_date ) == -1 ) { + $checkout->update( { date_due => $recall_due_date } ); + $checkout->item->onloan( $recall_due_date->ymd() ); + $checkout->item->store( { log_action => 0, skip_holds_queue => 1 } ); + } # get itemnumber of most relevant checkout if a biblio-level recall unless ( $recall->item_level ) { $itemnumber = $checkout->itemnumber; } diff --git a/t/db_dependent/Koha/Recalls.t b/t/db_dependent/Koha/Recalls.t index e44ad141118..083fbe142f3 100755 --- a/t/db_dependent/Koha/Recalls.t +++ b/t/db_dependent/Koha/Recalls.t @@ -18,7 +18,7 @@ use Modern::Perl; use Test::NoWarnings; -use Test::More tests => 24; +use Test::More tests => 25; use t::lib::Dates; use t::lib::TestBuilder; use t::lib::Mocks; @@ -141,6 +141,12 @@ ok( $checkout_due_date_after_recall lt $initial_checkout_due_date, "Checkout due date has been moved backwards" ); +$item2 = Koha::Items->find( $item2->itemnumber ); +$checkout_due_date_after_recall = dt_from_string($checkout_due_date_after_recall); +is( + t::lib::Dates::compare( $checkout_due_date_after_recall->ymd(), $item2->onloan ), 0, + "items.onloan is updated with adjusted due date" +); Koha::CirculationRules->set_rule( { -- 2.39.5