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 2163-2168 tables: Link Here
2163
            - "This item must be renewed at the library."
2163
            - "This item must be renewed at the library."
2164
            - "[% ELSIF checkout.auto_renew_error == 'auto_account_expired' %]"
2164
            - "[% ELSIF checkout.auto_renew_error == 'auto_account_expired' %]"
2165
            - "Your account has expired."
2165
            - "Your account has expired."
2166
            - "[% ELSIF checkout.auto_renew_error == 'auto_renew_final' %]"
2167
            - "The following item, [% biblio.title %], has correctly been renewed and is now due on [% checkout.date_due | $KohaDates as_due_date => 1 %]"
2168
            - "This item has reached the maximum number of automatic renewals and will no longer be renewed."
2169
            - "[% ELSIF checkout.auto_renew_error == 'auto_unseen_final' %]"
2170
            - "The following item, [% biblio.title %], has correctly been renewed and is now due on [% checkout.date_due | $KohaDates as_due_date => 1 %]"
2171
            - "This item has reached the maximum number of unseen renewals and will need to be renewed at the library."
2166
            - "[% END %]"
2172
            - "[% END %]"
2167
            - "[% ELSE %]"
2173
            - "[% ELSE %]"
2168
            - "The following item, [% biblio.title %], has correctly been renewed and is now due on [% checkout.date_due | $KohaDates as_due_date => 1 %]"
2174
            - "The following item, [% biblio.title %], has correctly been renewed and is now due on [% checkout.date_due | $KohaDates as_due_date => 1 %]"
Lines 2237-2242 tables: Link Here
2237
            - "Your total unpaid fines are too high."
2243
            - "Your total unpaid fines are too high."
2238
            - "[% ELSIF checkout.auto_renew_error == 'too_unseen' %]"
2244
            - "[% ELSIF checkout.auto_renew_error == 'too_unseen' %]"
2239
            - "This item must be renewed at the library."
2245
            - "This item must be renewed at the library."
2246
            - "[% ELSIF checkout.auto_renew_error == 'auto_renew_final' %]"
2247
            - "was renewed until [% checkout.date_due | $KohaDates as_due_date => 1%]"
2248
            - "This item has reached the maximum number of automatic renewals and will no longer be renewed."
2249
            - "[% ELSIF checkout.auto_renew_error == 'auto_unseen_final' %]"
2250
            - "was renewed until [% checkout.date_due | $KohaDates as_due_date => 1%]"
2251
            - "This item has reached the maximum number of unseen renewals and will need to be renewed at the library."
2240
            - "[% END %]"
2252
            - "[% END %]"
2241
            - "[% END %]"
2253
            - "[% END %]"
2242
2254
(-)a/t/db_dependent/Koha/Checkouts.t (-4 / +36 lines)
Lines 487-501 subtest 'automatic_checkin' => sub { Link Here
487
487
488
subtest 'attempt_auto_renew' => sub {
488
subtest 'attempt_auto_renew' => sub {
489
489
490
    plan tests => 17;
490
    plan tests => 33;
491
491
492
    $schema->storage->txn_begin;
492
    $schema->storage->txn_begin;
493
493
494
    my $renew_error = 'auto_renew';
494
    my $renew_error = 'auto_renew';
495
    my $module      = Test::MockModule->new('C4::Circulation');
495
    my $module      = Test::MockModule->new('C4::Circulation');
496
    $module->mock( 'CanBookBeRenewed', sub { return ( 1, $renew_error ) } );
496
    $module->mock( 'CanBookBeRenewed', sub { return ( 1, $renew_error ) } );
497
    my $around_now = dt_from_string();
497
    $module->mock( 'AddRenewal',       sub { warn "AddRenewal called" } );
498
    $module->mock( 'AddRenewal', sub { warn "AddRenewal called" } );
499
    my $checkout = $builder->build_object(
498
    my $checkout = $builder->build_object(
500
        {
499
        {
501
            class => 'Koha::Checkouts',
500
            class => 'Koha::Checkouts',
Lines 527-532 subtest 'attempt_auto_renew' => sub { Link Here
527
    is( $error, undef, "No error when renewed" );
526
    is( $error, undef, "No error when renewed" );
528
    ok( $updated, "Issue reported as updated when renewed" );
527
    ok( $updated, "Issue reported as updated when renewed" );
529
528
529
    $module->mock( 'AddRenewal', sub { return; } );
530
530
    $renew_error = 'anything_else';
531
    $renew_error = 'anything_else';
531
    ( $success, $error, $updated ) = $checkout->attempt_auto_renew();
532
    ( $success, $error, $updated ) = $checkout->attempt_auto_renew();
532
    ok( !$success, "Success is untrue for any other status" );
533
    ok( !$success, "Success is untrue for any other status" );
Lines 546-550 subtest 'attempt_auto_renew' => sub { Link Here
546
    ( $success, $error, $updated ) = $checkout->attempt_auto_renew();
547
    ( $success, $error, $updated ) = $checkout->attempt_auto_renew();
547
    ok( !$updated, "Issue not reported as updated when status has not changed" );
548
    ok( !$updated, "Issue not reported as updated when status has not changed" );
548
549
550
    $renew_error = "auto_unseen_final";
551
    ( $success, $error, $updated ) = $checkout->attempt_auto_renew( { confirm => 1 } );
552
    ok( $success, "Issue is renewed when error is 'auto_unseen_final'" );
553
    is( $error, 'auto_unseen_final', "Error of finality reported when renewed" );
554
    ok( $updated, "Issue reported as updated when renewed" );
555
    $checkout->discard_changes();
556
    is( $checkout->auto_renew_error, 'auto_unseen_final', "Error updated" );
557
558
    $renew_error = "too_unseen";
559
    ( $success, $error, $updated ) = $checkout->attempt_auto_renew( { confirm => 1 } );
560
    ok( !$success, "Issue is not renewed when error is 'too_unseen'" );
561
    is( $error, 'too_unseen', "Error reported correctly" );
562
    ok( !$updated, "Issue not reported as updated when moved from final to too unseen" );
563
    $checkout->discard_changes();
564
    is( $checkout->auto_renew_error, 'too_unseen', "Error updated" );
565
566
    $renew_error = "auto_renew_final";
567
    ( $success, $error, $updated ) = $checkout->attempt_auto_renew( { confirm => 1 } );
568
    ok( $success, "Issue is renewed when error is 'auto_renew_final'" );
569
    is( $error, 'auto_renew_final', "Error of finality reported when renewed" );
570
    ok( $updated, "Issue reported as updated when renewed" );
571
    $checkout->discard_changes();
572
    is( $checkout->auto_renew_error, 'auto_renew_final', "Error updated" );
573
574
    $renew_error = "too_many";
575
    ( $success, $error, $updated ) = $checkout->attempt_auto_renew( { confirm => 1 } );
576
    ok( !$success, "Issue is not renewed when error is 'too_many'" );
577
    is( $error, 'too_many', "Error reported correctly" );
578
    ok( !$updated, "Issue not reported as updated when moved from final to too many" );
579
    $checkout->discard_changes();
580
    is( $checkout->auto_renew_error, 'too_many', "Error updated" );
581
549
    $schema->storage->txn_rollback;
582
    $schema->storage->txn_rollback;
550
};
583
};
551
- 

Return to bug 34924