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

(-)a/C4/Circulation.pm (-113 / +6 lines)
Lines 2705-2710 sub CanBookBeRenewed { Link Here
2705
        return ( 0, "too_many" )
2705
        return ( 0, "too_many" )
2706
          if not $issuing_rule->{renewalsallowed} or $issuing_rule->{renewalsallowed} <= $issue->renewals;
2706
          if not $issuing_rule->{renewalsallowed} or $issuing_rule->{renewalsallowed} <= $issue->renewals;
2707
2707
2708
        return ( 0, "too_unseen" )
2709
          if C4::Context->preference('UnseenRenewals') &&
2710
            $issuing_rule->{unseen_renewals_allowed} &&
2711
            $issuing_rule->{unseen_renewals_allowed} <= $issue->unseen_renewals;
2712
2708
        my $overduesblockrenewing = C4::Context->preference('OverduesBlockRenewing');
2713
        my $overduesblockrenewing = C4::Context->preference('OverduesBlockRenewing');
2709
        my $restrictionblockrenewing = C4::Context->preference('RestrictionBlockRenewing');
2714
        my $restrictionblockrenewing = C4::Context->preference('RestrictionBlockRenewing');
2710
        $patron         = Koha::Patrons->find($borrowernumber); # FIXME Is this really useful?
2715
        $patron         = Koha::Patrons->find($borrowernumber); # FIXME Is this really useful?
Lines 2876-2993 sub CanBookBeRenewed { Link Here
2876
2881
2877
    return ( 0, "auto_renew" ) if $auto_renew eq "ok" && !$override_limit; # 0 if auto-renewal should not succeed
2882
    return ( 0, "auto_renew" ) if $auto_renew eq "ok" && !$override_limit; # 0 if auto-renewal should not succeed
2878
2883
2879
    return ( 1, undef ) if $override_limit;
2880
2881
    my $branchcode = _GetCircControlBranch( $item->unblessed, $patron->unblessed );
2882
    my $issuing_rule = Koha::CirculationRules->get_effective_rules(
2883
        {
2884
            categorycode => $patron->categorycode,
2885
            itemtype     => $item->effective_itemtype,
2886
            branchcode   => $branchcode,
2887
            rules => [
2888
                'renewalsallowed',
2889
                'no_auto_renewal_after',
2890
                'no_auto_renewal_after_hard_limit',
2891
                'lengthunit',
2892
                'norenewalbefore',
2893
                'unseen_renewals_allowed'
2894
            ]
2895
        }
2896
    );
2897
2898
    return ( 0, "too_many" )
2899
      if not $issuing_rule->{renewalsallowed} or $issuing_rule->{renewalsallowed} <= $issue->renewals;
2900
2901
    return ( 0, "too_unseen" )
2902
      if C4::Context->preference('UnseenRenewals') &&
2903
        $issuing_rule->{unseen_renewals_allowed} &&
2904
        $issuing_rule->{unseen_renewals_allowed} <= $issue->unseen_renewals;
2905
2906
    my $overduesblockrenewing = C4::Context->preference('OverduesBlockRenewing');
2907
    my $restrictionblockrenewing = C4::Context->preference('RestrictionBlockRenewing');
2908
    $patron         = Koha::Patrons->find($borrowernumber); # FIXME Is this really useful?
2909
    my $restricted  = $patron->is_debarred;
2910
    my $hasoverdues = $patron->has_overdues;
2911
2912
    if ( $restricted and $restrictionblockrenewing ) {
2913
        return ( 0, 'restriction');
2914
    } elsif ( ($hasoverdues and $overduesblockrenewing eq 'block') || ($issue->is_overdue and $overduesblockrenewing eq 'blockitem') ) {
2915
        return ( 0, 'overdue');
2916
    }
2917
2918
    if ( $issue->auto_renew ) {
2919
2920
        if ( $patron->category->effective_BlockExpiredPatronOpacActions and $patron->is_expired ) {
2921
            return ( 0, 'auto_account_expired' );
2922
        }
2923
2924
        if ( defined $issuing_rule->{no_auto_renewal_after}
2925
                and $issuing_rule->{no_auto_renewal_after} ne "" ) {
2926
            # Get issue_date and add no_auto_renewal_after
2927
            # If this is greater than today, it's too late for renewal.
2928
            my $maximum_renewal_date = dt_from_string($issue->issuedate, 'sql');
2929
            $maximum_renewal_date->add(
2930
                $issuing_rule->{lengthunit} => $issuing_rule->{no_auto_renewal_after}
2931
            );
2932
            my $now = dt_from_string;
2933
            if ( $now >= $maximum_renewal_date ) {
2934
                return ( 0, "auto_too_late" );
2935
            }
2936
        }
2937
        if ( defined $issuing_rule->{no_auto_renewal_after_hard_limit}
2938
                      and $issuing_rule->{no_auto_renewal_after_hard_limit} ne "" ) {
2939
            # If no_auto_renewal_after_hard_limit is >= today, it's also too late for renewal
2940
            if ( dt_from_string >= dt_from_string( $issuing_rule->{no_auto_renewal_after_hard_limit} ) ) {
2941
                return ( 0, "auto_too_late" );
2942
            }
2943
        }
2944
2945
        if ( C4::Context->preference('OPACFineNoRenewalsBlockAutoRenew') ) {
2946
            my $fine_no_renewals = C4::Context->preference("OPACFineNoRenewals");
2947
            my $amountoutstanding =
2948
              C4::Context->preference("OPACFineNoRenewalsIncludeCredit")
2949
              ? $patron->account->balance
2950
              : $patron->account->outstanding_debits->total_outstanding;
2951
            if ( $amountoutstanding and $amountoutstanding > $fine_no_renewals ) {
2952
                return ( 0, "auto_too_much_oweing" );
2953
            }
2954
        }
2955
    }
2956
2957
    if ( defined $issuing_rule->{norenewalbefore}
2958
        and $issuing_rule->{norenewalbefore} ne "" )
2959
    {
2960
2961
        # Calculate soonest renewal by subtracting 'No renewal before' from due date
2962
        my $soonestrenewal = dt_from_string( $issue->date_due, 'sql' )->subtract(
2963
            $issuing_rule->{lengthunit} => $issuing_rule->{norenewalbefore} );
2964
2965
        # Depending on syspref reset the exact time, only check the date
2966
        if ( C4::Context->preference('NoRenewalBeforePrecision') eq 'date'
2967
            and $issuing_rule->{lengthunit} eq 'days' )
2968
        {
2969
            $soonestrenewal->truncate( to => 'day' );
2970
        }
2971
2972
        if ( $soonestrenewal > dt_from_string() )
2973
        {
2974
            return ( 0, "auto_too_soon" ) if $issue->auto_renew;
2975
            return ( 0, "too_soon" );
2976
        }
2977
        elsif ( $issue->auto_renew ) {
2978
            return ( 0, "auto_renew" );
2979
        }
2980
    }
2981
2982
    # Fallback for automatic renewals:
2983
    # If norenewalbefore is undef, don't renew before due date.
2984
    if ( $issue->auto_renew ) {
2985
        my $now = dt_from_string;
2986
        return ( 0, "auto_renew" )
2987
          if $now >= dt_from_string( $issue->date_due, 'sql' );
2988
        return ( 0, "auto_too_soon" );
2989
    }
2990
2991
    return ( 1, undef );
2884
    return ( 1, undef );
2992
}
2885
}
2993
2886
Lines 3211-3217 sub GetRenewCount { Link Here
3211
    my $patron = Koha::Patrons->find( $bornum );
3104
    my $patron = Koha::Patrons->find( $bornum );
3212
    my $item   = Koha::Items->find($itemno);
3105
    my $item   = Koha::Items->find($itemno);
3213
3106
3214
    return (0, 0, 0) unless $patron or $item; # Wrong call, no renewal allowed
3107
    return (0, 0, 0, 0, 0, 0) unless $patron or $item; # Wrong call, no renewal allowed
3215
3108
3216
    # Look in the issues table for this item, lent to this borrower,
3109
    # Look in the issues table for this item, lent to this borrower,
3217
    # and not yet returned.
3110
    # 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 413-419 Link Here
413
                    <td><input type="text" name="maxsuspensiondays" id="maxsuspensiondays" size="3" /> </td>
413
                    <td><input type="text" name="maxsuspensiondays" id="maxsuspensiondays" size="3" /> </td>
414
                    <td><input type="text" name="suspension_chargeperiod" id="suspension_chargeperiod" size="3" /> </td>
414
                    <td><input type="text" name="suspension_chargeperiod" id="suspension_chargeperiod" size="3" /> </td>
415
                    <td><input type="text" name="renewalsallowed" id="renewalsallowed" size="2" /></td>
415
                    <td><input type="text" name="renewalsallowed" id="renewalsallowed" size="2" /></td>
416
                    <td><input type="text" name="unseen_renewals_allowed" id="unseen_renewals_allowed" size="2" /></td>
416
                    [% IF Koha.Preference('UnseenRenewals') %]
417
                        <td><input type="text" name="unseen_renewals_allowed" id="unseen_renewals_allowed" size="2" /></td>
418
                    [% END %]
417
                    <td><input type="text" name="renewalperiod" id="renewalperiod" size="3" /></td>
419
                    <td><input type="text" name="renewalperiod" id="renewalperiod" size="3" /></td>
418
                    <td><input type="text" name="norenewalbefore" id="norenewalbefore" size="3" /></td>
420
                    <td><input type="text" name="norenewalbefore" id="norenewalbefore" size="3" /></td>
419
                    <td>
421
                    <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 278-284 Koha::CirculationRules->set_rules( Link Here
278
278
279
my ( $reused_itemnumber_1, $reused_itemnumber_2 );
279
my ( $reused_itemnumber_1, $reused_itemnumber_2 );
280
subtest "CanBookBeRenewed tests" => sub {
280
subtest "CanBookBeRenewed tests" => sub {
281
    plan tests => 87;
281
    plan tests => 89;
282
282
283
    C4::Context->set_preference('ItemsDeniedRenewal','');
283
    C4::Context->set_preference('ItemsDeniedRenewal','');
284
    # Generate test biblio
284
    # Generate test biblio
Lines 1158-1169 subtest "CanBookBeRenewed tests" => sub { Link Here
1158
    is( $error, 'too_many', 'Cannot renew, 0 renewals allowed (returned code is too_many)');
1158
    is( $error, 'too_many', 'Cannot renew, 0 renewals allowed (returned code is too_many)');
1159
1159
1160
    # Too many unseen renewals
1160
    # Too many unseen renewals
1161
    $dbh->do('UPDATE issuingrules SET unseen_renewals_allowed = 2, renewalsallowed = 10');
1161
    Koha::CirculationRules->set_rules(
1162
        {
1163
            categorycode => undef,
1164
            branchcode   => undef,
1165
            itemtype     => undef,
1166
            rules        => {
1167
                unseen_renewals_allowed => 2,
1168
                renewalsallowed => 10,
1169
            }
1170
        }
1171
    );
1172
    t::lib::Mocks::mock_preference('UnseenRenewals', 1);
1162
    $dbh->do('UPDATE issues SET unseen_renewals = 2 where borrowernumber = ? AND itemnumber = ?', undef, ($renewing_borrowernumber, $item_1->itemnumber));
1173
    $dbh->do('UPDATE issues SET unseen_renewals = 2 where borrowernumber = ? AND itemnumber = ?', undef, ($renewing_borrowernumber, $item_1->itemnumber));
1163
    ( $renewokay, $error ) = CanBookBeRenewed($renewing_borrowernumber, $item_1->itemnumber);
1174
    ( $renewokay, $error ) = CanBookBeRenewed($renewing_borrowernumber, $item_1->itemnumber);
1164
    is( $renewokay, 0, 'Cannot renew, 0 unseen renewals allowed');
1175
    is( $renewokay, 0, 'Cannot renew, 0 unseen renewals allowed');
1165
    is( $error, 'too_unseen', 'Cannot renew, returned code is too_unseen');
1176
    is( $error, 'too_unseen', 'Cannot renew, returned code is too_unseen');
1166
    $dbh->do('UPDATE issuingrules SET norenewalbefore = NULL, renewalsallowed = 0');
1177
    Koha::CirculationRules->set_rules(
1178
        {
1179
            categorycode => undef,
1180
            branchcode   => undef,
1181
            itemtype     => undef,
1182
            rules        => {
1183
                norenewalbefore => undef,
1184
                renewalsallowed => 0,
1185
            }
1186
        }
1187
    );
1188
    t::lib::Mocks::mock_preference('UnseenRenewals', 0);
1167
1189
1168
    # Test WhenLostForgiveFine and WhenLostChargeReplacementFee
1190
    # Test WhenLostForgiveFine and WhenLostChargeReplacementFee
1169
    t::lib::Mocks::mock_preference('WhenLostForgiveFine','1');
1191
    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