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

(-)a/C4/Circulation.pm (-113 / +6 lines)
Lines 2781-2786 sub CanBookBeRenewed { Link Here
2781
        return ( 0, "too_many" )
2781
        return ( 0, "too_many" )
2782
          if not $issuing_rule->{renewalsallowed} or $issuing_rule->{renewalsallowed} <= $issue->renewals;
2782
          if not $issuing_rule->{renewalsallowed} or $issuing_rule->{renewalsallowed} <= $issue->renewals;
2783
2783
2784
        return ( 0, "too_unseen" )
2785
          if C4::Context->preference('UnseenRenewals') &&
2786
            $issuing_rule->{unseen_renewals_allowed} &&
2787
            $issuing_rule->{unseen_renewals_allowed} <= $issue->unseen_renewals;
2788
2784
        my $overduesblockrenewing = C4::Context->preference('OverduesBlockRenewing');
2789
        my $overduesblockrenewing = C4::Context->preference('OverduesBlockRenewing');
2785
        my $restrictionblockrenewing = C4::Context->preference('RestrictionBlockRenewing');
2790
        my $restrictionblockrenewing = C4::Context->preference('RestrictionBlockRenewing');
2786
        $patron         = Koha::Patrons->find($borrowernumber); # FIXME Is this really useful?
2791
        $patron         = Koha::Patrons->find($borrowernumber); # FIXME Is this really useful?
Lines 2952-3069 sub CanBookBeRenewed { Link Here
2952
2957
2953
    return ( 0, "auto_renew" ) if $auto_renew eq "ok" && !$override_limit; # 0 if auto-renewal should not succeed
2958
    return ( 0, "auto_renew" ) if $auto_renew eq "ok" && !$override_limit; # 0 if auto-renewal should not succeed
2954
2959
2955
    return ( 1, undef ) if $override_limit;
2956
2957
    my $branchcode = _GetCircControlBranch( $item->unblessed, $patron->unblessed );
2958
    my $issuing_rule = Koha::CirculationRules->get_effective_rules(
2959
        {
2960
            categorycode => $patron->categorycode,
2961
            itemtype     => $item->effective_itemtype,
2962
            branchcode   => $branchcode,
2963
            rules => [
2964
                'renewalsallowed',
2965
                'no_auto_renewal_after',
2966
                'no_auto_renewal_after_hard_limit',
2967
                'lengthunit',
2968
                'norenewalbefore',
2969
                'unseen_renewals_allowed'
2970
            ]
2971
        }
2972
    );
2973
2974
    return ( 0, "too_many" )
2975
      if not $issuing_rule->{renewalsallowed} or $issuing_rule->{renewalsallowed} <= $issue->renewals;
2976
2977
    return ( 0, "too_unseen" )
2978
      if C4::Context->preference('UnseenRenewals') &&
2979
        $issuing_rule->{unseen_renewals_allowed} &&
2980
        $issuing_rule->{unseen_renewals_allowed} <= $issue->unseen_renewals;
2981
2982
    my $overduesblockrenewing = C4::Context->preference('OverduesBlockRenewing');
2983
    my $restrictionblockrenewing = C4::Context->preference('RestrictionBlockRenewing');
2984
    $patron         = Koha::Patrons->find($borrowernumber); # FIXME Is this really useful?
2985
    my $restricted  = $patron->is_debarred;
2986
    my $hasoverdues = $patron->has_overdues;
2987
2988
    if ( $restricted and $restrictionblockrenewing ) {
2989
        return ( 0, 'restriction');
2990
    } elsif ( ($hasoverdues and $overduesblockrenewing eq 'block') || ($issue->is_overdue and $overduesblockrenewing eq 'blockitem') ) {
2991
        return ( 0, 'overdue');
2992
    }
2993
2994
    if ( $issue->auto_renew ) {
2995
2996
        if ( $patron->category->effective_BlockExpiredPatronOpacActions and $patron->is_expired ) {
2997
            return ( 0, 'auto_account_expired' );
2998
        }
2999
3000
        if ( defined $issuing_rule->{no_auto_renewal_after}
3001
                and $issuing_rule->{no_auto_renewal_after} ne "" ) {
3002
            # Get issue_date and add no_auto_renewal_after
3003
            # If this is greater than today, it's too late for renewal.
3004
            my $maximum_renewal_date = dt_from_string($issue->issuedate, 'sql');
3005
            $maximum_renewal_date->add(
3006
                $issuing_rule->{lengthunit} => $issuing_rule->{no_auto_renewal_after}
3007
            );
3008
            my $now = dt_from_string;
3009
            if ( $now >= $maximum_renewal_date ) {
3010
                return ( 0, "auto_too_late" );
3011
            }
3012
        }
3013
        if ( defined $issuing_rule->{no_auto_renewal_after_hard_limit}
3014
                      and $issuing_rule->{no_auto_renewal_after_hard_limit} ne "" ) {
3015
            # If no_auto_renewal_after_hard_limit is >= today, it's also too late for renewal
3016
            if ( dt_from_string >= dt_from_string( $issuing_rule->{no_auto_renewal_after_hard_limit} ) ) {
3017
                return ( 0, "auto_too_late" );
3018
            }
3019
        }
3020
3021
        if ( C4::Context->preference('OPACFineNoRenewalsBlockAutoRenew') ) {
3022
            my $fine_no_renewals = C4::Context->preference("OPACFineNoRenewals");
3023
            my $amountoutstanding =
3024
              C4::Context->preference("OPACFineNoRenewalsIncludeCredit")
3025
              ? $patron->account->balance
3026
              : $patron->account->outstanding_debits->total_outstanding;
3027
            if ( $amountoutstanding and $amountoutstanding > $fine_no_renewals ) {
3028
                return ( 0, "auto_too_much_oweing" );
3029
            }
3030
        }
3031
    }
3032
3033
    if ( defined $issuing_rule->{norenewalbefore}
3034
        and $issuing_rule->{norenewalbefore} ne "" )
3035
    {
3036
3037
        # Calculate soonest renewal by subtracting 'No renewal before' from due date
3038
        my $soonestrenewal = dt_from_string( $issue->date_due, 'sql' )->subtract(
3039
            $issuing_rule->{lengthunit} => $issuing_rule->{norenewalbefore} );
3040
3041
        # Depending on syspref reset the exact time, only check the date
3042
        if ( C4::Context->preference('NoRenewalBeforePrecision') eq 'date'
3043
            and $issuing_rule->{lengthunit} eq 'days' )
3044
        {
3045
            $soonestrenewal->truncate( to => 'day' );
3046
        }
3047
3048
        if ( $soonestrenewal > dt_from_string() )
3049
        {
3050
            return ( 0, "auto_too_soon" ) if $issue->auto_renew;
3051
            return ( 0, "too_soon" );
3052
        }
3053
        elsif ( $issue->auto_renew ) {
3054
            return ( 0, "auto_renew" );
3055
        }
3056
    }
3057
3058
    # Fallback for automatic renewals:
3059
    # If norenewalbefore is undef, don't renew before due date.
3060
    if ( $issue->auto_renew ) {
3061
        my $now = dt_from_string;
3062
        return ( 0, "auto_renew" )
3063
          if $now >= dt_from_string( $issue->date_due, 'sql' );
3064
        return ( 0, "auto_too_soon" );
3065
    }
3066
3067
    return ( 1, undef );
2960
    return ( 1, undef );
3068
}
2961
}
3069
2962
Lines 3287-3293 sub GetRenewCount { Link Here
3287
    my $patron = Koha::Patrons->find( $bornum );
3180
    my $patron = Koha::Patrons->find( $bornum );
3288
    my $item   = Koha::Items->find($itemno);
3181
    my $item   = Koha::Items->find($itemno);
3289
3182
3290
    return (0, 0, 0) unless $patron or $item; # Wrong call, no renewal allowed
3183
    return (0, 0, 0, 0, 0, 0) unless $patron or $item; # Wrong call, no renewal allowed
3291
3184
3292
    # Look in the issues table for this item, lent to this borrower,
3185
    # Look in the issues table for this item, lent to this borrower,
3293
    # and not yet returned.
3186
    # and not yet returned.
(-)a/installer/data/mysql/en/mandatory/sample_notices.yml (+2 lines)
Lines 1204-1209 tables: Link Here
1204
            - "It's too late to renew this item."
1204
            - "It's too late to renew this item."
1205
            - "[% ELSIF checkout.auto_renew_error == 'auto_too_much_oweing' %]"
1205
            - "[% ELSIF checkout.auto_renew_error == 'auto_too_much_oweing' %]"
1206
            - "Your total unpaid fines are too high."
1206
            - "Your total unpaid fines are too high."
1207
            - "[% ELSIF checkout.auto_renew_error == 'too_unseen' %]"
1208
            - "This item must be renewed at the library."
1207
            - "[% END %]"
1209
            - "[% END %]"
1208
            - "[% ELSE %]"
1210
            - "[% ELSE %]"
1209
            - "The following item, [% biblio.title %], has correctly been renewed and is now due on [% checkout.date_due | $KohaDates as_due_date => 1 %]"
1211
            - "The following item, [% biblio.title %], has correctly been renewed and is now due on [% checkout.date_due | $KohaDates as_due_date => 1 %]"
(-)a/installer/data/mysql/fr-CA/obligatoire/sample_notices.sql (+2 lines)
Lines 285-290 You have overdue items. Link Here
285
It\'s too late to renew this item.
285
It\'s too late to renew this item.
286
[% ELSIF checkout.auto_renew_error == 'auto_too_much_oweing' %]
286
[% ELSIF checkout.auto_renew_error == 'auto_too_much_oweing' %]
287
Your total unpaid fines are too high.
287
Your total unpaid fines are too high.
288
[% ELSIF checkout.auto_renew_error == 'too_unseen' %]
289
This item must be renewed at the library.
288
[% END %]
290
[% END %]
289
[% ELSE %]
291
[% ELSE %]
290
The following item, [% biblio.title %], has correctly been renewed and is now due on [% checkout.date_due | $KohaDates as_due_date => 1 %]
292
The following item, [% biblio.title %], has correctly been renewed and is now due on [% checkout.date_due | $KohaDates as_due_date => 1 %]
(-)a/installer/data/mysql/fr-FR/1-Obligatoire/sample_notices.sql (+2 lines)
Lines 396-401 You have overdue items. Link Here
396
It\'s too late to renew this item.
396
It\'s too late to renew this item.
397
[% ELSIF checkout.auto_renew_error == 'auto_too_much_oweing' %]
397
[% ELSIF checkout.auto_renew_error == 'auto_too_much_oweing' %]
398
Your total unpaid fines are too high.
398
Your total unpaid fines are too high.
399
[% ELSIF checkout.auto_renew_error == 'too_unseen' %]
400
This item must be renewed at the library.
399
[% END %]
401
[% END %]
400
[% ELSE %]
402
[% ELSE %]
401
The following item, [% biblio.title %], has correctly been renewed and is now due on [% checkout.date_due | $KohaDates as_due_date => 1 %]
403
The following item, [% biblio.title %], has correctly been renewed and is now due on [% checkout.date_due | $KohaDates as_due_date => 1 %]
(-)a/installer/data/mysql/it-IT/necessari/notices.sql (+2 lines)
Lines 399-404 You have overdue items. Link Here
399
It\'s too late to renew this item.
399
It\'s too late to renew this item.
400
[% ELSIF checkout.auto_renew_error == 'auto_too_much_oweing' %]
400
[% ELSIF checkout.auto_renew_error == 'auto_too_much_oweing' %]
401
Your total unpaid fines are too high.
401
Your total unpaid fines are too high.
402
[% ELSIF checkout.auto_renew_error == 'too_unseen' %]
403
This item must be renewed at the library.
402
[% END %]
404
[% END %]
403
[% ELSE %]
405
[% ELSE %]
404
The following item, [% biblio.title %], has correctly been renewed and is now due on [% checkout.date_due | $KohaDates as_due_date => 1 %]
406
The following item, [% biblio.title %], has correctly been renewed and is now due on [% checkout.date_due | $KohaDates as_due_date => 1 %]
(-)a/installer/data/mysql/nb-NO/1-Obligatorisk/sample_notices.sql (+2 lines)
Lines 414-419 You have overdue items. Link Here
414
It\'s too late to renew this item.
414
It\'s too late to renew this item.
415
[% ELSIF checkout.auto_renew_error == 'auto_too_much_oweing' %]
415
[% ELSIF checkout.auto_renew_error == 'auto_too_much_oweing' %]
416
Your total unpaid fines are too high.
416
Your total unpaid fines are too high.
417
[% ELSIF checkout.auto_renew_error == 'too_unseen' %]
418
This item must be renewed at the library.
417
[% END %]
419
[% END %]
418
[% ELSE %]
420
[% ELSE %]
419
The following item, [% biblio.title %], has correctly been renewed and is now due on [% checkout.date_due | $KohaDates as_due_date => 1 %]
421
The following item, [% biblio.title %], has correctly been renewed and is now due on [% checkout.date_due | $KohaDates as_due_date => 1 %]
(-)a/installer/data/mysql/pl-PL/mandatory/sample_notices.sql (+2 lines)
Lines 393-398 You have overdue items. Link Here
393
It\'s too late to renew this item.
393
It\'s too late to renew this item.
394
[% ELSIF checkout.auto_renew_error == 'auto_too_much_oweing' %]
394
[% ELSIF checkout.auto_renew_error == 'auto_too_much_oweing' %]
395
Your total unpaid fines are too high.
395
Your total unpaid fines are too high.
396
[% ELSIF checkout.auto_renew_error == 'too_unseen' %]
397
This item must be renewed at the library.
396
[% END %]
398
[% END %]
397
[% ELSE %]
399
[% ELSE %]
398
The following item, [% biblio.title %], has correctly been renewed and is now due on [% checkout.date_due | $KohaDates as_due_date => 1 %]
400
The following item, [% biblio.title %], has correctly been renewed and is now due on [% checkout.date_due | $KohaDates as_due_date => 1 %]
(-)a/installer/data/mysql/ru-RU/mandatory/sample_notices.sql (+2 lines)
Lines 395-400 You have overdue items. Link Here
395
It\'s too late to renew this item.
395
It\'s too late to renew this item.
396
[% ELSIF checkout.auto_renew_error == 'auto_too_much_oweing' %]
396
[% ELSIF checkout.auto_renew_error == 'auto_too_much_oweing' %]
397
Your total unpaid fines are too high.
397
Your total unpaid fines are too high.
398
[% ELSIF checkout.auto_renew_error == 'too_unseen' %]
399
This item must be renewed at the library.
398
[% END %]
400
[% END %]
399
[% ELSE %]
401
[% ELSE %]
400
The following item, [% biblio.title %], has correctly been renewed and is now due on [% checkout.date_due | $KohaDates as_due_date => 1 %]
402
The following item, [% biblio.title %], has correctly been renewed and is now due on [% checkout.date_due | $KohaDates as_due_date => 1 %]
(-)a/installer/data/mysql/uk-UA/mandatory/sample_notices.sql (+2 lines)
Lines 486-491 You have overdue items. Link Here
486
It\'s too late to renew this item.
486
It\'s too late to renew this item.
487
[% ELSIF checkout.auto_renew_error == 'auto_too_much_oweing' %]
487
[% ELSIF checkout.auto_renew_error == 'auto_too_much_oweing' %]
488
Your total unpaid fines are too high.
488
Your total unpaid fines are too high.
489
[% ELSIF checkout.auto_renew_error == 'too_unseen' %]
490
This item must be renewed at the library.
489
[% END %]
491
[% END %]
490
[% ELSE %]
492
[% ELSE %]
491
The following item, [% biblio.title %], has correctly been renewed and is now due on [% checkout.date_due | $KohaDates as_due_date => 1 %]
493
The following item, [% biblio.title %], has correctly been renewed and is now due on [% checkout.date_due | $KohaDates as_due_date => 1 %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tt (-1 / +3 lines)
Lines 417-423 Link Here
417
                    <td><input type="text" name="maxsuspensiondays" id="maxsuspensiondays" size="3" /> </td>
417
                    <td><input type="text" name="maxsuspensiondays" id="maxsuspensiondays" size="3" /> </td>
418
                    <td><input type="text" name="suspension_chargeperiod" id="suspension_chargeperiod" size="3" /> </td>
418
                    <td><input type="text" name="suspension_chargeperiod" id="suspension_chargeperiod" size="3" /> </td>
419
                    <td><input type="text" name="renewalsallowed" id="renewalsallowed" size="2" /></td>
419
                    <td><input type="text" name="renewalsallowed" id="renewalsallowed" size="2" /></td>
420
                    <td><input type="text" name="unseen_renewals_allowed" id="unseen_renewals_allowed" size="2" /></td>
420
                    [% IF Koha.Preference('UnseenRenewals') %]
421
                        <td><input type="text" name="unseen_renewals_allowed" id="unseen_renewals_allowed" size="2" /></td>
422
                    [% END %]
421
                    <td><input type="text" name="renewalperiod" id="renewalperiod" size="3" /></td>
423
                    <td><input type="text" name="renewalperiod" id="renewalperiod" size="3" /></td>
422
                    <td><input type="text" name="norenewalbefore" id="norenewalbefore" size="3" /></td>
424
                    <td><input type="text" name="norenewalbefore" id="norenewalbefore" size="3" /></td>
423
                    <td>
425
                    <td>
(-)a/koha-tmpl/intranet-tmpl/prog/js/checkouts.js (-4 / +2 lines)
Lines 559-571 $(document).ready(function() { Link Here
559
                            content += "<span class='renewals'>(";
559
                            content += "<span class='renewals'>(";
560
                            content + __("%s of %s renewals remaining").format(oObj.renewals_remaining, oObj.renewals_allowed);
560
                            content + __("%s of %s renewals remaining").format(oObj.renewals_remaining, oObj.renewals_allowed);
561
                            if (UnseenRenewals && oObj.unseen_allowed) {
561
                            if (UnseenRenewals && oObj.unseen_allowed) {
562
                                content += __(" / %s of %s unseen renewals remaining").format(oObj.unseen_remaining, oObj.unseen_allowed);
562
                                content += __("%s of %s unseen renewals remaining").format(oObj.unseen_remaining, oObj.unseen_allowed);
563
                            }
563
                            }
564
                                    + ")</span>";
564
                            content += ")</span>";
565
                        }
565
                        }
566
566
567
                        content += "</span>";
568
569
                        return content;
567
                        return content;
570
                    }
568
                    }
571
                },
569
                },
(-)a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-user.tt (+2 lines)
Lines 378-383 Link Here
378
                                                            Not renewable <span class="renewals">(on hold)</span>
378
                                                            Not renewable <span class="renewals">(on hold)</span>
379
                                                        [% ELSIF ( ISSUE.too_many ) %]
379
                                                        [% ELSIF ( ISSUE.too_many ) %]
380
                                                            Not renewable
380
                                                            Not renewable
381
                                                        [% ELSIF ( ISSUE.too_unseen ) %]
382
                                                            Item must be renewed at the library. [% ISSUE.renewsleft | html %] renewals remaining
381
                                                        [% ELSIF ( ISSUE.norenew_overdue ) %]
383
                                                        [% ELSIF ( ISSUE.norenew_overdue ) %]
382
                                                            Not allowed <span class="renewals">(overdue)</span>
384
                                                            Not allowed <span class="renewals">(overdue)</span>
383
                                                        [% ELSIF ( ISSUE.auto_too_late ) %]
385
                                                        [% ELSIF ( ISSUE.auto_too_late ) %]
(-)a/t/db_dependent/Circulation.t (-3 / +25 lines)
Lines 284-290 Koha::CirculationRules->set_rules( Link Here
284
284
285
my ( $reused_itemnumber_1, $reused_itemnumber_2 );
285
my ( $reused_itemnumber_1, $reused_itemnumber_2 );
286
subtest "CanBookBeRenewed tests" => sub {
286
subtest "CanBookBeRenewed tests" => sub {
287
    plan tests => 87;
287
    plan tests => 89;
288
288
289
    C4::Context->set_preference('ItemsDeniedRenewal','');
289
    C4::Context->set_preference('ItemsDeniedRenewal','');
290
    # Generate test biblio
290
    # Generate test biblio
Lines 1164-1175 subtest "CanBookBeRenewed tests" => sub { Link Here
1164
    is( $error, 'too_many', 'Cannot renew, 0 renewals allowed (returned code is too_many)');
1164
    is( $error, 'too_many', 'Cannot renew, 0 renewals allowed (returned code is too_many)');
1165
1165
1166
    # Too many unseen renewals
1166
    # Too many unseen renewals
1167
    $dbh->do('UPDATE issuingrules SET unseen_renewals_allowed = 2, renewalsallowed = 10');
1167
    Koha::CirculationRules->set_rules(
1168
        {
1169
            categorycode => undef,
1170
            branchcode   => undef,
1171
            itemtype     => undef,
1172
            rules        => {
1173
                unseen_renewals_allowed => 2,
1174
                renewalsallowed => 10,
1175
            }
1176
        }
1177
    );
1178
    t::lib::Mocks::mock_preference('UnseenRenewals', 1);
1168
    $dbh->do('UPDATE issues SET unseen_renewals = 2 where borrowernumber = ? AND itemnumber = ?', undef, ($renewing_borrowernumber, $item_1->itemnumber));
1179
    $dbh->do('UPDATE issues SET unseen_renewals = 2 where borrowernumber = ? AND itemnumber = ?', undef, ($renewing_borrowernumber, $item_1->itemnumber));
1169
    ( $renewokay, $error ) = CanBookBeRenewed($renewing_borrowernumber, $item_1->itemnumber);
1180
    ( $renewokay, $error ) = CanBookBeRenewed($renewing_borrowernumber, $item_1->itemnumber);
1170
    is( $renewokay, 0, 'Cannot renew, 0 unseen renewals allowed');
1181
    is( $renewokay, 0, 'Cannot renew, 0 unseen renewals allowed');
1171
    is( $error, 'too_unseen', 'Cannot renew, returned code is too_unseen');
1182
    is( $error, 'too_unseen', 'Cannot renew, returned code is too_unseen');
1172
    $dbh->do('UPDATE issuingrules SET norenewalbefore = NULL, renewalsallowed = 0');
1183
    Koha::CirculationRules->set_rules(
1184
        {
1185
            categorycode => undef,
1186
            branchcode   => undef,
1187
            itemtype     => undef,
1188
            rules        => {
1189
                norenewalbefore => undef,
1190
                renewalsallowed => 0,
1191
            }
1192
        }
1193
    );
1194
    t::lib::Mocks::mock_preference('UnseenRenewals', 0);
1173
1195
1174
    # Test WhenLostForgiveFine and WhenLostChargeReplacementFee
1196
    # Test WhenLostForgiveFine and WhenLostChargeReplacementFee
1175
    t::lib::Mocks::mock_preference('WhenLostForgiveFine','1');
1197
    t::lib::Mocks::mock_preference('WhenLostForgiveFine','1');
(-)a/t/db_dependent/Circulation/issue.t (-24 / +41 lines)
Lines 17-23 Link Here
17
17
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use Test::More tests => 46;
20
use Test::More tests => 48;
21
use DateTime::Duration;
21
use DateTime::Duration;
22
22
23
use t::lib::Mocks;
23
use t::lib::Mocks;
Lines 297-316 subtest 'Show that AddRenewal respects OpacRenewalBranch and interface' => sub { Link Here
297
    }
297
    }
298
};
298
};
299
299
300
# Unseen rewnewals
301
t::lib::Mocks::mock_preference('UnseenRenewals', 1);
302
303
# Does an unseen renewal increment the issue's count
304
my ( $unseen_before ) = ( C4::Circulation::GetRenewCount( $opac_renew_issue->{borrowernumber}, $opac_renew_issue->{itemnumber} ) )[3];
305
AddRenewal( $opac_renew_issue->{borrowernumber}, $opac_renew_issue->{itemnumber}, $branchcode_1, undef, undef, 0 );
306
my ( $unseen_after ) = ( C4::Circulation::GetRenewCount( $opac_renew_issue->{borrowernumber}, $opac_renew_issue->{itemnumber} ) )[3];
307
is( $unseen_after, $unseen_before + 1, 'unseen_renewals increments' );
308
309
# Does a seen renewal reset the unseen count
310
AddRenewal( $opac_renew_issue->{borrowernumber}, $opac_renew_issue->{itemnumber}, $branchcode_1, undef, undef, 1 );
311
my ( $unseen_reset ) = ( C4::Circulation::GetRenewCount( $opac_renew_issue->{borrowernumber}, $opac_renew_issue->{itemnumber} ) )[3];
312
is( $unseen_reset, 0, 'seen renewal resets the unseen count' );
313
314
#Test GetBiblioIssues
300
#Test GetBiblioIssues
315
is( GetBiblioIssues(), undef, "GetBiblio Issues without parameters" );
301
is( GetBiblioIssues(), undef, "GetBiblio Issues without parameters" );
316
302
Lines 327-345 my $issue3 = C4::Circulation::AddIssue( $borrower_1, $barcode_1 ); Link Here
327
@renewcount = C4::Circulation::GetRenewCount();
313
@renewcount = C4::Circulation::GetRenewCount();
328
is_deeply(
314
is_deeply(
329
    \@renewcount,
315
    \@renewcount,
330
    [ 0, 0, 0 ], # FIXME Need to be fixed, see FIXME in GetRenewCount
316
    [ 0, 0, 0, 0, 0, 0 ], # FIXME Need to be fixed, see FIXME in GetRenewCount
331
    "Without issuing rules and without parameter, GetRenewCount returns renewcount = 0, renewsallowed = undef, renewsleft = 0"
317
    "Without issuing rules and without parameter, GetRenewCount returns renewcount = 0, renewsallowed = undef, renewsleft = 0"
332
);
318
);
333
@renewcount = C4::Circulation::GetRenewCount(-1);
319
@renewcount = C4::Circulation::GetRenewCount(-1);
334
is_deeply(
320
is_deeply(
335
    \@renewcount,
321
    \@renewcount,
336
    [ 0, 0, 0 ], # FIXME Need to be fixed
322
    [ 0, 0, 0, 0, 0, 0 ], # FIXME Need to be fixed
337
    "Without issuing rules and without wrong parameter, GetRenewCount returns renewcount = 0, renewsallowed = undef, renewsleft = 0"
323
    "Without issuing rules and without wrong parameter, GetRenewCount returns renewcount = 0, renewsallowed = undef, renewsleft = 0"
338
);
324
);
339
@renewcount = C4::Circulation::GetRenewCount($borrower_id1, $item_id1);
325
@renewcount = C4::Circulation::GetRenewCount($borrower_id1, $item_id1);
340
is_deeply(
326
is_deeply(
341
    \@renewcount,
327
    \@renewcount,
342
    [ 2, 0, 0 ],
328
    [ 2, 0, 0, 0, 0, 0 ],
343
    "Without issuing rules and with a valid parameter, renewcount = 2, renewsallowed = undef, renewsleft = 0"
329
    "Without issuing rules and with a valid parameter, renewcount = 2, renewsallowed = undef, renewsleft = 0"
344
);
330
);
345
331
Lines 347-365 is_deeply( Link Here
347
@renewcount = C4::Circulation::GetRenewCount();
333
@renewcount = C4::Circulation::GetRenewCount();
348
is_deeply(
334
is_deeply(
349
    \@renewcount,
335
    \@renewcount,
350
    [ 0, 0, 0 ],
336
    [ 0, 0, 0, 0, 0, 0 ],
351
    "With issuing rules (renewal disallowed) and without parameter, GetRenewCount returns renewcount = 0, renewsallowed = 0, renewsleft = 0"
337
    "With issuing rules (renewal disallowed) and without parameter, GetRenewCount returns renewcount = 0, renewsallowed = 0, renewsleft = 0"
352
);
338
);
353
@renewcount = C4::Circulation::GetRenewCount(-1);
339
@renewcount = C4::Circulation::GetRenewCount(-1);
354
is_deeply(
340
is_deeply(
355
    \@renewcount,
341
    \@renewcount,
356
    [ 0, 0, 0 ],
342
    [ 0, 0, 0, 0, 0, 0 ],
357
    "With issuing rules (renewal disallowed) and without wrong parameter, GetRenewCount returns renewcount = 0, renewsallowed = 0, renewsleft = 0"
343
    "With issuing rules (renewal disallowed) and without wrong parameter, GetRenewCount returns renewcount = 0, renewsallowed = 0, renewsleft = 0"
358
);
344
);
359
@renewcount = C4::Circulation::GetRenewCount($borrower_id1, $item_id1);
345
@renewcount = C4::Circulation::GetRenewCount($borrower_id1, $item_id1);
360
is_deeply(
346
is_deeply(
361
    \@renewcount,
347
    \@renewcount,
362
    [ 2, 0, 0 ],
348
    [ 2, 0, 0, 0, 0, 0 ],
363
    "With issuing rules (renewal disallowed) and with a valid parameter, Getrenewcount returns renewcount = 2, renewsallowed = 0, renewsleft = 0"
349
    "With issuing rules (renewal disallowed) and with a valid parameter, Getrenewcount returns renewcount = 2, renewsallowed = 0, renewsleft = 0"
364
);
350
);
365
351
Lines 377-383 Koha::CirculationRules->set_rules( Link Here
377
@renewcount = C4::Circulation::GetRenewCount($borrower_id1, $item_id1);
363
@renewcount = C4::Circulation::GetRenewCount($borrower_id1, $item_id1);
378
is_deeply(
364
is_deeply(
379
    \@renewcount,
365
    \@renewcount,
380
    [ 2, 3, 1 ],
366
    [ 2, 3, 1, 0, 0, 0 ],
381
    "With issuing rules (renewal allowed) and with a valid parameter, Getrenewcount of item1 returns 3 renews left"
367
    "With issuing rules (renewal allowed) and with a valid parameter, Getrenewcount of item1 returns 3 renews left"
382
);
368
);
383
369
Lines 386-392 AddRenewal( $borrower_id1, $item_id1, $branchcode_1, Link Here
386
@renewcount = C4::Circulation::GetRenewCount($borrower_id1, $item_id1);
372
@renewcount = C4::Circulation::GetRenewCount($borrower_id1, $item_id1);
387
is_deeply(
373
is_deeply(
388
    \@renewcount,
374
    \@renewcount,
389
    [ 3, 3, 0 ],
375
    [ 3, 3, 0, 0, 0, 0 ],
390
    "With issuing rules (renewal allowed, 1 remaining) and with a valid parameter, Getrenewcount of item1 returns 0 renews left"
376
    "With issuing rules (renewal allowed, 1 remaining) and with a valid parameter, Getrenewcount of item1 returns 0 renews left"
391
);
377
);
392
378
Lines 504-508 AddIssue( $borrower_2, $barcode_1, dt_from_string, 'cancel' ); Link Here
504
my $hold = Koha::Holds->find( $reserve_id );
490
my $hold = Koha::Holds->find( $reserve_id );
505
is( $hold, undef, 'The reserve should have been correctly cancelled' );
491
is( $hold, undef, 'The reserve should have been correctly cancelled' );
506
492
493
# Unseen rewnewals
494
t::lib::Mocks::mock_preference('UnseenRenewals', 1);
495
# Add a default circ rule: 3 unseen renewals allowed
496
Koha::CirculationRules->set_rules(
497
    {
498
        categorycode => undef,
499
        itemtype     => undef,
500
        branchcode   => undef,
501
        rules        => {
502
            renewalsallowed => 10,
503
            unseen_renewals_allowed => 3
504
        }
505
    }
506
);
507
508
my $unseen_library = $builder->build_object( { class => 'Koha::Libraries' } );
509
my $unseen_patron  = $builder->build_object( { class => 'Koha::Patrons' } );
510
my $unseen_item = $builder->build_sample_item(
511
    { library => $unseen_library->branchcode, itype => $itemtype } );
512
my $unseen_issue = C4::Circulation::AddIssue( $unseen_patron->unblessed, $unseen_item->barcode );
513
514
# Does an unseen renewal increment the issue's count
515
my ( $unseen_before ) = ( C4::Circulation::GetRenewCount( $unseen_patron->borrowernumber, $unseen_item->itemnumber ) )[3];
516
AddRenewal( $unseen_patron->borrowernumber, $unseen_item->itemnumber, $branchcode_1, undef, undef, undef, 0 );
517
my ( $unseen_after ) = ( C4::Circulation::GetRenewCount( $unseen_patron->borrowernumber, $unseen_item->itemnumber ) )[3];
518
is( $unseen_after, $unseen_before + 1, 'unseen_renewals increments' );
519
520
# Does a seen renewal reset the unseen count
521
AddRenewal( $unseen_patron->borrowernumber, $unseen_item->itemnumber, $branchcode_1, undef, undef, undef, 1 );
522
my ( $unseen_reset ) = ( C4::Circulation::GetRenewCount( $unseen_patron->borrowernumber, $unseen_item->itemnumber ) )[3];
523
is( $unseen_reset, 0, 'seen renewal resets the unseen count' );
524
507
#End transaction
525
#End transaction
508
$schema->storage->txn_rollback;
526
$schema->storage->txn_rollback;
509
- 

Return to bug 24083