From ff3153bc9ce7e152cb09c7134076984a221b0124 Mon Sep 17 00:00:00 2001 From: John Doe Date: Thu, 10 Mar 2022 15:04:45 +0000 Subject: [PATCH] Bug 15261: Trying to fix after rebase https://bugs.koha-community.org/show_bug.cgi?id=1526 --- C4/Circulation.pm | 39 +++++++++----------- C4/Reserves.pm | 12 ++---- t/db_dependent/Circulation.t | 9 +++-- t/db_dependent/Circulation/CanBookBeIssued.t | 6 +-- 4 files changed, 30 insertions(+), 36 deletions(-) diff --git a/C4/Circulation.pm b/C4/Circulation.pm index d686a56b20..9cdef44bb4 100644 --- a/C4/Circulation.pm +++ b/C4/Circulation.pm @@ -27,7 +27,7 @@ use Encode; use Koha::DateUtils qw( dt_from_string output_pref ); use C4::Context; use C4::Stats qw( UpdateStats ); -use C4::Reserves qw( CheckReserves CanItemBeReserved MoveReserve ModReserve ModReserveMinusPriority RevertWaitingStatus IsItemOnHoldAndFound IsAvailableForItemLevelRequest ); +use C4::Reserves qw( CheckReserves ReservesOnSamePeriod CanItemBeReserved MoveReserve ModReserve ModReserveMinusPriority RevertWaitingStatus IsItemOnHoldAndFound IsAvailableForItemLevelRequest ); use C4::Biblio qw( UpdateTotalIssues ); use C4::Items qw( ModItemTransfer ModDateLastSeen CartToShelf ); use C4::Accounts; @@ -1111,9 +1111,9 @@ sub CanBookBeIssued { $needsconfirmation{'ressurname'} = $patron->surname; $needsconfirmation{'rescardnumber'} = $patron->cardnumber; $needsconfirmation{'resborrowernumber'} = $patron->borrowernumber; - $needsconfirmation{'resbranchcode'} = $res->{branchcode}; + $needsconfirmation{'resbranchcode'} = $res->branchcode; $needsconfirmation{'reswaitingdate'} = $res->{'waitingdate'}; - $needsconfirmation{'reserve_id'} = $res->{reserve_id}; + $needsconfirmation{'reserve_id'} = $res->{'reserve_id'}; } elsif ( $restype eq "Reserved" ) { # The item is on reserve for someone else. @@ -1123,8 +1123,8 @@ sub CanBookBeIssued { $needsconfirmation{'rescardnumber'} = $patron->cardnumber; $needsconfirmation{'resborrowernumber'} = $patron->borrowernumber; $needsconfirmation{'resbranchcode'} = $patron->branchcode; - $needsconfirmation{'resreservedate'} = $res->{reservedate}; - $needsconfirmation{'reserve_id'} = $res->{reserve_id}; + $needsconfirmation{'resreservedate'} = $res->{'reservedate'}; + $needsconfirmation{'reserve_id'} = $res->{'reserve_id'}; } elsif ( $restype eq "Transferred" ) { # The item is determined hold being transferred for someone else. @@ -1134,8 +1134,8 @@ sub CanBookBeIssued { $needsconfirmation{'rescardnumber'} = $patron->cardnumber; $needsconfirmation{'resborrowernumber'} = $patron->borrowernumber; $needsconfirmation{'resbranchcode'} = $patron->branchcode; - $needsconfirmation{'resreservedate'} = $res->{reservedate}; - $needsconfirmation{'reserve_id'} = $res->{reserve_id}; + $needsconfirmation{'resreservedate'} = $res->{'reservedate'}; + $needsconfirmation{'reserve_id'} = $res->{'reserve_id'}; } elsif ( $restype eq "Processing" ) { # The item is determined hold being processed for someone else. @@ -1145,8 +1145,8 @@ sub CanBookBeIssued { $needsconfirmation{'rescardnumber'} = $patron->cardnumber; $needsconfirmation{'resborrowernumber'} = $patron->borrowernumber; $needsconfirmation{'resbranchcode'} = $patron->branchcode; - $needsconfirmation{'resreservedate'} = $res->{reservedate}; - $needsconfirmation{'reserve_id'} = $res->{reserve_id}; + $needsconfirmation{'resreservedate'} = $res->{'reservedate'}; + $needsconfirmation{'reserve_id'} = $res->{'reserve_id'}; } } } @@ -1158,15 +1158,15 @@ sub CanBookBeIssued { if ($reserves_on_same_period) { my $reserve = $reserves_on_same_period->[0]; if ($reserve->{borrowernumber} ne $patron->borrowernumber) { - my $patron = Koha::Patrons->find( $reserve->{borrowernumber} ); + my $patron = Koha::Patrons->find( $reserve->borrowernumber ); $needsconfirmation{RESERVED} = 1; $needsconfirmation{resfirstname} = $patron->firstname; $needsconfirmation{ressurname} = $patron->surname; $needsconfirmation{rescardnumber} = $patron->cardnumber; $needsconfirmation{resborrowernumber} = $patron->borrowernumber; $needsconfirmation{resbranchcode} = $patron->branchcode; - $needsconfirmation{resreservedate} = $reserve->{reservedate}; - $needsconfirmation{reserve_id} = $reserve->{reserve_id}; + $needsconfirmation{resreservedate} = $reserve->{'reservedate'}; + $needsconfirmation{reserve_id} = $reserve->{'reserve_id'}; } } } @@ -2775,7 +2775,6 @@ sub CanBookBeRenewed { } elsif ( ($hasoverdues and $overduesblockrenewing eq 'block') || ($issue->is_overdue and $overduesblockrenewing eq 'blockitem') ) { return ( 0, 'overdue'); } - $auto_renew = _CanBookBeAutoRenewed({ patron => $patron, item => $item, @@ -2850,6 +2849,8 @@ sub CanBookBeRenewed { } if ( C4::Context->preference("PreventCheckoutOnSameReservePeriod") ) { + warn $date_due; + warn "Inside"; unless ($date_due) { my $itemtype = $item->effective_itemtype; my $patron_unblessed = $patron->unblessed; @@ -2867,16 +2868,12 @@ sub CanBookBeRenewed { } } - if( $cron ) { #The cron wants to return 'too_soon' over 'on_reserve' - return ( 0, $auto_renew ) if $auto_renew =~ 'too_soon';#$auto_renew ne "no" && $auto_renew ne "ok"; - return ( 0, "on_reserve" ) if $resfound; # '' when no hold was found - } else { # For other purposes we want 'on_reserve' before 'too_soon' - return ( 0, "on_reserve" ) if $resfound; # '' when no hold was found - return ( 0, $auto_renew ) if $auto_renew =~ 'too_soon';#$auto_renew ne "no" && $auto_renew ne "ok"; - } + return ( 0, $auto_renew ) if ($auto_renew =~ 'too_soon') && $cron;#$auto_renew ne "no" && $auto_renew ne "ok" and $cron; + return ( 0, "on_reserve" ) if $resfound; # '' when no hold was found + return ( 0, $auto_renew ) if $auto_renew =~ 'too_soon';#$auto_renew ne "no" && $auto_renew ne "ok"; if ( GetSoonestRenewDate($borrowernumber, $itemnumber) > dt_from_string() ){ - return (0, "too_soon") unless $override_limit; + return (0, "too_soon") unless $override_limit; } return ( 0, "auto_renew" ) if $auto_renew eq "ok" && !$override_limit; # 0 if auto-renewal should not succeed diff --git a/C4/Reserves.pm b/C4/Reserves.pm index 8dfdc6a881..7bb2521938 100644 --- a/C4/Reserves.pm +++ b/C4/Reserves.pm @@ -2282,22 +2282,18 @@ sub ReservesOnSamePeriod { my @reserves = Koha::Holds->search({ biblionumber => $biblionumber }); - $resdate = output_pref({ str => $resdate, dateonly => 1, dateformat => 'iso' }); - $expdate = output_pref({ str => $expdate, dateonly => 1, dateformat => 'iso' }); - my @reserves_overlaps; foreach my $reserve ( @reserves ) { - - unless ($reserve->reservedate && $reserve->expirationdate) { + unless ($reserve->{'reservedate'} && $reserve->{'expirationdate'}) { next; } if (date_ranges_overlap($resdate, $expdate, - $reserve->reservedate, - $reserve->expirationdate)) { + $reserve->{'reservedate'}, + $reserve->{'expirationdate'})) { # If reserve is item level and the requested periods overlap. - if ($itemnumber && $reserve->itemnumber == $itemnumber ) { + if ($itemnumber && $reserve->{'itemnumber'} == $itemnumber ) { return [$reserve->unblessed]; } push @reserves_overlaps, $reserve->unblessed; diff --git a/t/db_dependent/Circulation.t b/t/db_dependent/Circulation.t index e3dd4d5386..7b729839fe 100755 --- a/t/db_dependent/Circulation.t +++ b/t/db_dependent/Circulation.t @@ -1761,20 +1761,21 @@ subtest "AllowRenewalIfOtherItemsAvailable tests" => sub { value => { biblionumber => $biblionumber, itemnumber => $itemnumber, - reservedate => $reservedate->ymd, - expirationdate => $expirationdate->ymd + reservedate => $reservedate, + expirationdate => $expirationdate } }); my $requested_date_due = $due_date->clone; $requested_date_due->add( days => 4 ); - my ( $renewed, $error ) = CanBookBeRenewed( $issue->{borrowernumber}, $itemnumber, 1, $requested_date_due ); + my ( $renewed, $error ) = CanBookBeRenewed( $issue->{borrowernumber}, $itemnumber, 1, 0, $requested_date_due ); is( $renewed, 1, 'CanBookBeRenewed should allow to renew if no reserve date overlap' ); $requested_date_due->add( days => 2 ); - ( $renewed, $error ) = CanBookBeRenewed( $issue->{borrowernumber}, $itemnumber, 1, $requested_date_due ); + ( $renewed, $error ) = CanBookBeRenewed( $issue->{borrowernumber}, $itemnumber, 1, 0, $requested_date_due ); is( $renewed, 0, 'CanBookBeRenewed should not allow to renew if reserve date overlap' ); + t::lib::Mocks::mock_preference( 'PreventCheckoutOnSameReservePeriod', 0 ); } diff --git a/t/db_dependent/Circulation/CanBookBeIssued.t b/t/db_dependent/Circulation/CanBookBeIssued.t index e697a14fa8..aa8b21b7fd 100644 --- a/t/db_dependent/Circulation/CanBookBeIssued.t +++ b/t/db_dependent/Circulation/CanBookBeIssued.t @@ -19,9 +19,9 @@ use Modern::Perl; use Test::More tests => 1; use C4::Members; -use C4::Reserves; -use C4::Circulation; -use Koha::DateUtils; +use C4::Reserves qw( AddReserve ReservesOnSamePeriod ); +use C4::Circulation qw( CanBookBeIssued ); +use Koha::DateUtils qw( dt_from_string ); use t::lib::Mocks; use t::lib::TestBuilder; -- 2.30.2