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 2125-2130 tables: Link Here
2125
            - "This item must be renewed at the library."
2125
            - "This item must be renewed at the library."
2126
            - "[% ELSIF checkout.auto_renew_error == 'auto_account_expired' %]"
2126
            - "[% ELSIF checkout.auto_renew_error == 'auto_account_expired' %]"
2127
            - "Your account has expired."
2127
            - "Your account has expired."
2128
            - "[% ELSIF checkout.auto_renew_error == 'auto_renew_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 automatic renewals and will no longer be renewed."
2131
            - "[% ELSIF checkout.auto_renew_error == 'auto_unseen_final' %]"
2132
            - "The following item, [% biblio.title %], has correctly been renewed and is now due on [% checkout.date_due | $KohaDates as_due_date => 1 %]"
2133
            - "This item has reached the maximum number of unseen renewals and will need to be renewed at the library."
2128
            - "[% END %]"
2134
            - "[% END %]"
2129
            - "[% ELSE %]"
2135
            - "[% ELSE %]"
2130
            - "The following item, [% biblio.title %], has correctly been renewed and is now due on [% checkout.date_due | $KohaDates as_due_date => 1 %]"
2136
            - "The following item, [% biblio.title %], has correctly been renewed and is now due on [% checkout.date_due | $KohaDates as_due_date => 1 %]"
Lines 2199-2204 tables: Link Here
2199
            - "Your total unpaid fines are too high."
2205
            - "Your total unpaid fines are too high."
2200
            - "[% ELSIF checkout.auto_renew_error == 'too_unseen' %]"
2206
            - "[% ELSIF checkout.auto_renew_error == 'too_unseen' %]"
2201
            - "This item must be renewed at the library."
2207
            - "This item must be renewed at the library."
2208
            - "[% ELSIF checkout.auto_renew_error == 'auto_renew_final' %]"
2209
            - "was renewed until [% checkout.date_due | $KohaDates as_due_date => 1%]"
2210
            - "This item has reached the maximum number of automatic renewals and will no longer be renewed."
2211
            - "[% ELSIF checkout.auto_renew_error == 'auto_unseen_final' %]"
2212
            - "was renewed until [% checkout.date_due | $KohaDates as_due_date => 1%]"
2213
            - "This item has reached the maximum number of unseen renewals and will need to be renewed at the library."
2202
            - "[% END %]"
2214
            - "[% END %]"
2203
            - "[% END %]"
2215
            - "[% END %]"
2204
2216
(-)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