View | Details | Raw Unified | Return to bug 15261
Collapse All | Expand All

(-)a/C4/Circulation.pm (-21 / +18 lines)
Lines 27-33 use Encode; Link Here
27
use Koha::DateUtils qw( dt_from_string output_pref );
27
use Koha::DateUtils qw( dt_from_string output_pref );
28
use C4::Context;
28
use C4::Context;
29
use C4::Stats qw( UpdateStats );
29
use C4::Stats qw( UpdateStats );
30
use C4::Reserves qw( CheckReserves CanItemBeReserved MoveReserve ModReserve ModReserveMinusPriority RevertWaitingStatus IsItemOnHoldAndFound IsAvailableForItemLevelRequest );
30
use C4::Reserves qw( CheckReserves ReservesOnSamePeriod CanItemBeReserved MoveReserve ModReserve ModReserveMinusPriority RevertWaitingStatus IsItemOnHoldAndFound IsAvailableForItemLevelRequest );
31
use C4::Biblio qw( UpdateTotalIssues );
31
use C4::Biblio qw( UpdateTotalIssues );
32
use C4::Items qw( ModItemTransfer ModDateLastSeen CartToShelf );
32
use C4::Items qw( ModItemTransfer ModDateLastSeen CartToShelf );
33
use C4::Accounts;
33
use C4::Accounts;
Lines 1111-1119 sub CanBookBeIssued { Link Here
1111
                    $needsconfirmation{'ressurname'} = $patron->surname;
1111
                    $needsconfirmation{'ressurname'} = $patron->surname;
1112
                    $needsconfirmation{'rescardnumber'} = $patron->cardnumber;
1112
                    $needsconfirmation{'rescardnumber'} = $patron->cardnumber;
1113
                    $needsconfirmation{'resborrowernumber'} = $patron->borrowernumber;
1113
                    $needsconfirmation{'resborrowernumber'} = $patron->borrowernumber;
1114
                    $needsconfirmation{'resbranchcode'} = $res->{branchcode};
1114
                    $needsconfirmation{'resbranchcode'} = $res->branchcode;
1115
                    $needsconfirmation{'reswaitingdate'} = $res->{'waitingdate'};
1115
                    $needsconfirmation{'reswaitingdate'} = $res->{'waitingdate'};
1116
                    $needsconfirmation{'reserve_id'} = $res->{reserve_id};
1116
                    $needsconfirmation{'reserve_id'} = $res->{'reserve_id'};
1117
                }
1117
                }
1118
                elsif ( $restype eq "Reserved" ) {
1118
                elsif ( $restype eq "Reserved" ) {
1119
                    # The item is on reserve for someone else.
1119
                    # The item is on reserve for someone else.
Lines 1123-1130 sub CanBookBeIssued { Link Here
1123
                    $needsconfirmation{'rescardnumber'} = $patron->cardnumber;
1123
                    $needsconfirmation{'rescardnumber'} = $patron->cardnumber;
1124
                    $needsconfirmation{'resborrowernumber'} = $patron->borrowernumber;
1124
                    $needsconfirmation{'resborrowernumber'} = $patron->borrowernumber;
1125
                    $needsconfirmation{'resbranchcode'} = $patron->branchcode;
1125
                    $needsconfirmation{'resbranchcode'} = $patron->branchcode;
1126
                    $needsconfirmation{'resreservedate'} = $res->{reservedate};
1126
                    $needsconfirmation{'resreservedate'} = $res->{'reservedate'};
1127
                    $needsconfirmation{'reserve_id'} = $res->{reserve_id};
1127
                    $needsconfirmation{'reserve_id'} = $res->{'reserve_id'};
1128
                }
1128
                }
1129
                elsif ( $restype eq "Transferred" ) {
1129
                elsif ( $restype eq "Transferred" ) {
1130
                    # The item is determined hold being transferred for someone else.
1130
                    # The item is determined hold being transferred for someone else.
Lines 1134-1141 sub CanBookBeIssued { Link Here
1134
                    $needsconfirmation{'rescardnumber'} = $patron->cardnumber;
1134
                    $needsconfirmation{'rescardnumber'} = $patron->cardnumber;
1135
                    $needsconfirmation{'resborrowernumber'} = $patron->borrowernumber;
1135
                    $needsconfirmation{'resborrowernumber'} = $patron->borrowernumber;
1136
                    $needsconfirmation{'resbranchcode'} = $patron->branchcode;
1136
                    $needsconfirmation{'resbranchcode'} = $patron->branchcode;
1137
                    $needsconfirmation{'resreservedate'} = $res->{reservedate};
1137
                    $needsconfirmation{'resreservedate'} = $res->{'reservedate'};
1138
                    $needsconfirmation{'reserve_id'} = $res->{reserve_id};
1138
                    $needsconfirmation{'reserve_id'} = $res->{'reserve_id'};
1139
                }
1139
                }
1140
                elsif ( $restype eq "Processing" ) {
1140
                elsif ( $restype eq "Processing" ) {
1141
                    # The item is determined hold being processed for someone else.
1141
                    # The item is determined hold being processed for someone else.
Lines 1145-1152 sub CanBookBeIssued { Link Here
1145
                    $needsconfirmation{'rescardnumber'} = $patron->cardnumber;
1145
                    $needsconfirmation{'rescardnumber'} = $patron->cardnumber;
1146
                    $needsconfirmation{'resborrowernumber'} = $patron->borrowernumber;
1146
                    $needsconfirmation{'resborrowernumber'} = $patron->borrowernumber;
1147
                    $needsconfirmation{'resbranchcode'} = $patron->branchcode;
1147
                    $needsconfirmation{'resbranchcode'} = $patron->branchcode;
1148
                    $needsconfirmation{'resreservedate'} = $res->{reservedate};
1148
                    $needsconfirmation{'resreservedate'} = $res->{'reservedate'};
1149
                    $needsconfirmation{'reserve_id'} = $res->{reserve_id};
1149
                    $needsconfirmation{'reserve_id'} = $res->{'reserve_id'};
1150
                }
1150
                }
1151
            }
1151
            }
1152
        }
1152
        }
Lines 1158-1172 sub CanBookBeIssued { Link Here
1158
            if ($reserves_on_same_period) {
1158
            if ($reserves_on_same_period) {
1159
                my $reserve = $reserves_on_same_period->[0];
1159
                my $reserve = $reserves_on_same_period->[0];
1160
                if ($reserve->{borrowernumber} ne $patron->borrowernumber) {
1160
                if ($reserve->{borrowernumber} ne $patron->borrowernumber) {
1161
                    my $patron = Koha::Patrons->find( $reserve->{borrowernumber} );
1161
                    my $patron = Koha::Patrons->find( $reserve->borrowernumber );
1162
                    $needsconfirmation{RESERVED} = 1;
1162
                    $needsconfirmation{RESERVED} = 1;
1163
                    $needsconfirmation{resfirstname} = $patron->firstname;
1163
                    $needsconfirmation{resfirstname} = $patron->firstname;
1164
                    $needsconfirmation{ressurname} = $patron->surname;
1164
                    $needsconfirmation{ressurname} = $patron->surname;
1165
                    $needsconfirmation{rescardnumber} = $patron->cardnumber;
1165
                    $needsconfirmation{rescardnumber} = $patron->cardnumber;
1166
                    $needsconfirmation{resborrowernumber} = $patron->borrowernumber;
1166
                    $needsconfirmation{resborrowernumber} = $patron->borrowernumber;
1167
                    $needsconfirmation{resbranchcode} = $patron->branchcode;
1167
                    $needsconfirmation{resbranchcode} = $patron->branchcode;
1168
                    $needsconfirmation{resreservedate} = $reserve->{reservedate};
1168
                    $needsconfirmation{resreservedate} = $reserve->{'reservedate'};
1169
                    $needsconfirmation{reserve_id} = $reserve->{reserve_id};
1169
                    $needsconfirmation{reserve_id} = $reserve->{'reserve_id'};
1170
                }
1170
                }
1171
            }
1171
            }
1172
        }
1172
        }
Lines 2775-2781 sub CanBookBeRenewed { Link Here
2775
        } elsif ( ($hasoverdues and $overduesblockrenewing eq 'block') || ($issue->is_overdue and $overduesblockrenewing eq 'blockitem') ) {
2775
        } elsif ( ($hasoverdues and $overduesblockrenewing eq 'block') || ($issue->is_overdue and $overduesblockrenewing eq 'blockitem') ) {
2776
            return ( 0, 'overdue');
2776
            return ( 0, 'overdue');
2777
        }
2777
        }
2778
2779
        $auto_renew = _CanBookBeAutoRenewed({
2778
        $auto_renew = _CanBookBeAutoRenewed({
2780
            patron     => $patron,
2779
            patron     => $patron,
2781
            item       => $item,
2780
            item       => $item,
Lines 2850-2855 sub CanBookBeRenewed { Link Here
2850
    }
2849
    }
2851
2850
2852
    if ( C4::Context->preference("PreventCheckoutOnSameReservePeriod") ) {
2851
    if ( C4::Context->preference("PreventCheckoutOnSameReservePeriod") ) {
2852
	    warn $date_due;
2853
	    warn "Inside";
2853
        unless ($date_due) {
2854
        unless ($date_due) {
2854
            my $itemtype = $item->effective_itemtype;
2855
            my $itemtype = $item->effective_itemtype;
2855
            my $patron_unblessed = $patron->unblessed;
2856
            my $patron_unblessed = $patron->unblessed;
Lines 2867-2882 sub CanBookBeRenewed { Link Here
2867
        }
2868
        }
2868
    }
2869
    }
2869
2870
2870
    if( $cron ) { #The cron wants to return 'too_soon' over 'on_reserve'
2871
    return ( 0, $auto_renew  ) if ($auto_renew =~ 'too_soon') && $cron;#$auto_renew ne "no" && $auto_renew ne "ok" and $cron;
2871
        return ( 0, $auto_renew  ) if $auto_renew =~ 'too_soon';#$auto_renew ne "no" && $auto_renew ne "ok";
2872
    return ( 0, "on_reserve" ) if $resfound;    # '' when no hold was found
2872
        return ( 0, "on_reserve" ) if $resfound;    # '' when no hold was found
2873
    return ( 0, $auto_renew  ) if $auto_renew =~ 'too_soon';#$auto_renew ne "no" && $auto_renew ne "ok";
2873
    } else { # For other purposes we want 'on_reserve' before 'too_soon'
2874
        return ( 0, "on_reserve" ) if $resfound;    # '' when no hold was found
2875
        return ( 0, $auto_renew  ) if $auto_renew =~ 'too_soon';#$auto_renew ne "no" && $auto_renew ne "ok";
2876
    }
2877
2874
2878
    if ( GetSoonestRenewDate($borrowernumber, $itemnumber) > dt_from_string() ){
2875
    if ( GetSoonestRenewDate($borrowernumber, $itemnumber) > dt_from_string() ){
2879
      return (0, "too_soon") unless $override_limit;
2876
        return (0, "too_soon") unless $override_limit;
2880
    }
2877
    }
2881
2878
2882
    return ( 0, "auto_renew" ) if $auto_renew eq "ok" && !$override_limit; # 0 if auto-renewal should not succeed
2879
    return ( 0, "auto_renew" ) if $auto_renew eq "ok" && !$override_limit; # 0 if auto-renewal should not succeed
(-)a/C4/Reserves.pm (-8 / +4 lines)
Lines 2282-2303 sub ReservesOnSamePeriod { Link Here
2282
2282
2283
    my @reserves = Koha::Holds->search({ biblionumber => $biblionumber });
2283
    my @reserves = Koha::Holds->search({ biblionumber => $biblionumber });
2284
2284
2285
    $resdate = output_pref({ str => $resdate, dateonly => 1, dateformat => 'iso' });
2286
    $expdate = output_pref({ str => $expdate, dateonly => 1, dateformat => 'iso' });
2287
2288
    my @reserves_overlaps;
2285
    my @reserves_overlaps;
2289
    foreach my $reserve ( @reserves ) {
2286
    foreach my $reserve ( @reserves ) {
2290
2287
        unless ($reserve->{'reservedate'} && $reserve->{'expirationdate'}) {
2291
        unless ($reserve->reservedate && $reserve->expirationdate) {
2292
            next;
2288
            next;
2293
        }
2289
        }
2294
2290
2295
        if (date_ranges_overlap($resdate, $expdate,
2291
        if (date_ranges_overlap($resdate, $expdate,
2296
                                $reserve->reservedate,
2292
                                $reserve->{'reservedate'},
2297
                                $reserve->expirationdate)) {
2293
                                $reserve->{'expirationdate'})) {
2298
2294
2299
            # If reserve is item level and the requested periods overlap.
2295
            # If reserve is item level and the requested periods overlap.
2300
            if ($itemnumber && $reserve->itemnumber == $itemnumber ) {
2296
            if ($itemnumber && $reserve->{'itemnumber'} == $itemnumber ) {
2301
                return [$reserve->unblessed];
2297
                return [$reserve->unblessed];
2302
            }
2298
            }
2303
            push @reserves_overlaps, $reserve->unblessed;
2299
            push @reserves_overlaps, $reserve->unblessed;
(-)a/t/db_dependent/Circulation.t (-4 / +5 lines)
Lines 1761-1780 subtest "AllowRenewalIfOtherItemsAvailable tests" => sub { Link Here
1761
        value => {
1761
        value => {
1762
            biblionumber => $biblionumber,
1762
            biblionumber => $biblionumber,
1763
            itemnumber => $itemnumber,
1763
            itemnumber => $itemnumber,
1764
            reservedate => $reservedate->ymd,
1764
            reservedate => $reservedate,
1765
            expirationdate => $expirationdate->ymd
1765
            expirationdate => $expirationdate
1766
        }
1766
        }
1767
    });
1767
    });
1768
1768
1769
    my $requested_date_due = $due_date->clone;
1769
    my $requested_date_due = $due_date->clone;
1770
    $requested_date_due->add( days => 4 );
1770
    $requested_date_due->add( days => 4 );
1771
    my ( $renewed, $error ) = CanBookBeRenewed( $issue->{borrowernumber}, $itemnumber, 1, $requested_date_due );
1771
    my ( $renewed, $error ) = CanBookBeRenewed( $issue->{borrowernumber}, $itemnumber, 1, 0, $requested_date_due );
1772
    is( $renewed, 1, 'CanBookBeRenewed should allow to renew if no reserve date overlap' );
1772
    is( $renewed, 1, 'CanBookBeRenewed should allow to renew if no reserve date overlap' );
1773
1773
1774
    $requested_date_due->add( days => 2 );
1774
    $requested_date_due->add( days => 2 );
1775
    ( $renewed, $error ) = CanBookBeRenewed( $issue->{borrowernumber}, $itemnumber, 1, $requested_date_due );
1775
    ( $renewed, $error ) = CanBookBeRenewed( $issue->{borrowernumber}, $itemnumber, 1, 0, $requested_date_due );
1776
    is( $renewed, 0, 'CanBookBeRenewed should not allow to renew if reserve date overlap' );
1776
    is( $renewed, 0, 'CanBookBeRenewed should not allow to renew if reserve date overlap' );
1777
1777
1778
1778
    t::lib::Mocks::mock_preference( 'PreventCheckoutOnSameReservePeriod', 0 );
1779
    t::lib::Mocks::mock_preference( 'PreventCheckoutOnSameReservePeriod', 0 );
1779
}
1780
}
1780
1781
(-)a/t/db_dependent/Circulation/CanBookBeIssued.t (-4 / +3 lines)
Lines 19-27 use Modern::Perl; Link Here
19
19
20
use Test::More tests => 1;
20
use Test::More tests => 1;
21
use C4::Members;
21
use C4::Members;
22
use C4::Reserves;
22
use C4::Reserves qw( AddReserve ReservesOnSamePeriod );
23
use C4::Circulation;
23
use C4::Circulation qw( CanBookBeIssued );
24
use Koha::DateUtils;
24
use Koha::DateUtils qw( dt_from_string );
25
25
26
use t::lib::Mocks;
26
use t::lib::Mocks;
27
use t::lib::TestBuilder;
27
use t::lib::TestBuilder;
28
- 

Return to bug 15261