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

(-)a/Koha/Checkout.pm (-4 / +11 lines)
Lines 168-174 sub attempt_auto_renew { Link Here
168
168
169
    # CanBookBeRenewed returns 'auto_renew' when the renewal should be done by this script
169
    # CanBookBeRenewed returns 'auto_renew' when the renewal should be done by this script
170
    my ( $ok, $error ) = C4::Circulation::CanBookBeRenewed( $self->patron, $self, undef, 1 );
170
    my ( $ok, $error ) = C4::Circulation::CanBookBeRenewed( $self->patron, $self, undef, 1 );
171
    if ( $error eq 'auto_renew' ) {
171
    my $store_error;
172
    if ( $error eq 'auto_renew' || $error eq 'auto_renew_final' || $error eq 'auto_unseen_final' ) {
172
        if ($confirm) {
173
        if ($confirm) {
173
            my $date_due = C4::Circulation::AddRenewal(
174
            my $date_due = C4::Circulation::AddRenewal(
174
                {
175
                {
Lines 179-192 sub attempt_auto_renew { Link Here
179
                    automatic      => 1,
180
                    automatic      => 1,
180
                }
181
                }
181
            );
182
            );
182
            $self->auto_renew_error(undef)->store;
183
            $store_error = $error eq 'auto_renew' ? undef : $error;
184
            $self->auto_renew_error($store_error)->store;
183
        }
185
        }
184
        return ( 1, undef, 1 );
186
        return ( 1, $store_error, 1 );
185
    } else {
187
    } else {
186
        my $updated = 0;
188
        my $updated = 0;
187
        if ( !$self->auto_renew_error || $error ne $self->auto_renew_error ) {
189
        if ( !$self->auto_renew_error || $error ne $self->auto_renew_error ) {
190
            $updated = 1
191
                unless (
192
                $self->auto_renew_error
193
                && (   $self->auto_renew_error eq 'auto_renew_final' && $error eq 'too_many'
194
                    || $self->auto_renew_error eq 'auto_unseen_final' && $error eq 'too_unseen' )
195
                );
188
            $self->auto_renew_error($error)->store if $confirm;
196
            $self->auto_renew_error($error)->store if $confirm;
189
            $updated = 1;
190
        }
197
        }
191
        return ( 0, $error, $updated );
198
        return ( 0, $error, $updated );
192
    }
199
    }
(-)a/installer/data/mysql/en/mandatory/sample_notices.yml (+12 lines)
Lines 2122-2127 tables: Link Here
2122
            - "This item must be renewed at the library."
2122
            - "This item must be renewed at the library."
2123
            - "[% ELSIF checkout.auto_renew_error == 'auto_account_expired' %]"
2123
            - "[% ELSIF checkout.auto_renew_error == 'auto_account_expired' %]"
2124
            - "Your account has expired."
2124
            - "Your account has expired."
2125
            - "[% ELSIF checkout.auto_renew_error == 'auto_renew_final' %]"
2126
            - "The following item, [% biblio.title %], has correctly been renewed and is now due on [% checkout.date_due | $KohaDates as_due_date => 1 %]"
2127
            - "This item has reached the maximum number of automatic renewals and will no longer be renewed."
2128
            - "[% ELSIF checkout.auto_renew_error == 'auto_unseen_final' %]"
2129
            - "The following item, [% biblio.title %], has correctly been renewed and is now due on [% checkout.date_due | $KohaDates as_due_date => 1 %]"
2130
            - "This item has reached the maximum number of unseen renewals and will need to be renewed at the library."
2125
            - "[% END %]"
2131
            - "[% END %]"
2126
            - "[% ELSE %]"
2132
            - "[% ELSE %]"
2127
            - "The following item, [% biblio.title %], has correctly been renewed and is now due on [% checkout.date_due | $KohaDates as_due_date => 1 %]"
2133
            - "The following item, [% biblio.title %], has correctly been renewed and is now due on [% checkout.date_due | $KohaDates as_due_date => 1 %]"
Lines 2196-2201 tables: Link Here
2196
            - "Your total unpaid fines are too high."
2202
            - "Your total unpaid fines are too high."
2197
            - "[% ELSIF checkout.auto_renew_error == 'too_unseen' %]"
2203
            - "[% ELSIF checkout.auto_renew_error == 'too_unseen' %]"
2198
            - "This item must be renewed at the library."
2204
            - "This item must be renewed at the library."
2205
            - "[% ELSIF checkout.auto_renew_error == 'auto_renew_final' %]"
2206
            - "was renewed until [% checkout.date_due | $KohaDates as_due_date => 1%]"
2207
            - "This item has reached the maximum number of automatic renewals and will no longer be renewed."
2208
            - "[% ELSIF checkout.auto_renew_error == 'auto_unseen_final' %]"
2209
            - "was renewed until [% checkout.date_due | $KohaDates as_due_date => 1%]"
2210
            - "This item has reached the maximum number of unseen renewals and will need to be renewed at the library."
2199
            - "[% END %]"
2211
            - "[% END %]"
2200
            - "[% END %]"
2212
            - "[% END %]"
2201
2213
(-)a/t/db_dependent/Circulation.t (-1 / +1 lines)
Lines 1389-1395 subtest "CanBookBeRenewed tests" => sub { Link Here
1389
        $issue->unseen_renewals(1)->renewals_count(1)->store;
1389
        $issue->unseen_renewals(1)->renewals_count(1)->store;
1390
1390
1391
        ( $renewokay, $error ) = CanBookBeRenewed( $renewing_borrower_obj, $issue );
1391
        ( $renewokay, $error ) = CanBookBeRenewed( $renewing_borrower_obj, $issue );
1392
        is( $renewokay, 0,                  'No success for auto_renewal' );
1392
        is( $renewokay, 0,                   'No success for auto_renewal' );
1393
        is( $error,     'auto_unseen_final', 'Final unseen renewal reported, not final overall' );
1393
        is( $error,     'auto_unseen_final', 'Final unseen renewal reported, not final overall' );
1394
1394
1395
        # Final unseen renewal
1395
        # Final unseen renewal
(-)a/t/db_dependent/Koha/Checkouts.t (-4 / +36 lines)
Lines 412-426 subtest 'automatic_checkin' => sub { Link Here
412
412
413
subtest 'attempt_auto_renew' => sub {
413
subtest 'attempt_auto_renew' => sub {
414
414
415
    plan tests => 17;
415
    plan tests => 33;
416
416
417
    $schema->storage->txn_begin;
417
    $schema->storage->txn_begin;
418
418
419
    my $renew_error = 'auto_renew';
419
    my $renew_error = 'auto_renew';
420
    my $module      = Test::MockModule->new('C4::Circulation');
420
    my $module      = Test::MockModule->new('C4::Circulation');
421
    $module->mock( 'CanBookBeRenewed', sub { return ( 1, $renew_error ) } );
421
    $module->mock( 'CanBookBeRenewed', sub { return ( 1, $renew_error ) } );
422
    my $around_now = dt_from_string();
422
    $module->mock( 'AddRenewal',       sub { warn "AddRenewal called" } );
423
    $module->mock( 'AddRenewal', sub { warn "AddRenewal called" } );
424
    my $checkout = $builder->build_object(
423
    my $checkout = $builder->build_object(
425
        {
424
        {
426
            class => 'Koha::Checkouts',
425
            class => 'Koha::Checkouts',
Lines 452-457 subtest 'attempt_auto_renew' => sub { Link Here
452
    is( $error, undef, "No error when renewed" );
451
    is( $error, undef, "No error when renewed" );
453
    ok( $updated, "Issue reported as updated when renewed" );
452
    ok( $updated, "Issue reported as updated when renewed" );
454
453
454
    $module->mock( 'AddRenewal', sub { return; } );
455
455
    $renew_error = 'anything_else';
456
    $renew_error = 'anything_else';
456
    ( $success, $error, $updated ) = $checkout->attempt_auto_renew();
457
    ( $success, $error, $updated ) = $checkout->attempt_auto_renew();
457
    ok( !$success, "Success is untrue for any other status" );
458
    ok( !$success, "Success is untrue for any other status" );
Lines 471-475 subtest 'attempt_auto_renew' => sub { Link Here
471
    ( $success, $error, $updated ) = $checkout->attempt_auto_renew();
472
    ( $success, $error, $updated ) = $checkout->attempt_auto_renew();
472
    ok( !$updated, "Issue not reported as updated when status has not changed" );
473
    ok( !$updated, "Issue not reported as updated when status has not changed" );
473
474
475
    $renew_error = "auto_unseen_final";
476
    ( $success, $error, $updated ) = $checkout->attempt_auto_renew( { confirm => 1 } );
477
    ok( $success, "Issue is renewed when error is 'auto_unseen_final'" );
478
    is( $error, 'auto_unseen_final', "Error of finality reported when renewed" );
479
    ok( $updated, "Issue reported as updated when renewed" );
480
    $checkout->discard_changes();
481
    is( $checkout->auto_renew_error, 'auto_unseen_final', "Error updated" );
482
483
    $renew_error = "too_unseen";
484
    ( $success, $error, $updated ) = $checkout->attempt_auto_renew( { confirm => 1 } );
485
    ok( !$success, "Issue is not renewed when error is 'too_unseen'" );
486
    is( $error, 'too_unseen', "Error reported correctly" );
487
    ok( !$updated, "Issue not reported as updated when moved from final to too unseen" );
488
    $checkout->discard_changes();
489
    is( $checkout->auto_renew_error, 'too_unseen', "Error updated" );
490
491
    $renew_error = "auto_renew_final";
492
    ( $success, $error, $updated ) = $checkout->attempt_auto_renew( { confirm => 1 } );
493
    ok( $success, "Issue is renewed when error is 'auto_renew_final'" );
494
    is( $error, 'auto_renew_final', "Error of finality reported when renewed" );
495
    ok( $updated, "Issue reported as updated when renewed" );
496
    $checkout->discard_changes();
497
    is( $checkout->auto_renew_error, 'auto_renew_final', "Error updated" );
498
499
    $renew_error = "too_many";
500
    ( $success, $error, $updated ) = $checkout->attempt_auto_renew( { confirm => 1 } );
501
    ok( !$success, "Issue is not renewed when error is 'too_many'" );
502
    is( $error, 'too_many', "Error reported correctly" );
503
    ok( !$updated, "Issue not reported as updated when moved from final to too many" );
504
    $checkout->discard_changes();
505
    is( $checkout->auto_renew_error, 'too_many', "Error updated" );
506
474
    $schema->storage->txn_rollback;
507
    $schema->storage->txn_rollback;
475
};
508
};
476
- 

Return to bug 34924