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

(-)a/C4/Circulation.pm (-21 / +8 lines)
Lines 1928-1948 sub AddReturn { Link Here
1928
1928
1929
        if ($patron) {
1929
        if ($patron) {
1930
            eval {
1930
            eval {
1931
                my $issue_id = MarkIssueReturned( $borrowernumber, $item->{'itemnumber'},
1931
                MarkIssueReturned( $borrowernumber, $item->{'itemnumber'},
1932
                    $circControlBranch, $return_date, $patron->privacy );
1932
                    $circControlBranch, $return_date, $patron->privacy );
1933
                $issue->issue_id($issue_id);
1934
            };
1933
            };
1935
            unless ( $@ ) {
1934
            unless ( $@ ) {
1936
                if ( ( C4::Context->preference('CalculateFinesOnReturn') && $is_overdue ) || $return_date ) {
1935
                if ( ( C4::Context->preference('CalculateFinesOnReturn') && $is_overdue ) || $return_date ) {
1937
                    _CalculateAndUpdateFine( { issue => $issue, item => $item, borrower => $patron_unblessed, return_date => $return_date } );
1936
                    _CalculateAndUpdateFine( { issue => $issue, item => $item, borrower => $patron_unblessed, return_date => $return_date } );
1938
                }
1937
                }
1939
            } else {
1938
            } else {
1940
                $messages->{'Wrongbranch'} = {
1939
                carp "The checkin for the following issue failed, Please go to the about page, section 'data corrupted' to know how to fix this problem ($@)" . Dumper( $issue->unblessed );
1941
                    Wrongbranch => $branch,
1940
1942
                    Rightbranch => $message
1941
                return ( 0, { WasReturned => 0, DataCorrupted => 1 }, $issue, $patron_unblessed );
1943
                };
1944
                carp $@;
1945
                return ( 0, { WasReturned => 0 }, $issue, $patron_unblessed );
1946
            }
1942
            }
1947
1943
1948
            # FIXME is the "= 1" right?  This could be the borrower hash.
1944
            # FIXME is the "= 1" right?  This could be the borrower hash.
Lines 2169-2191 sub MarkIssueReturned { Link Here
2169
    # FIXME Improve the return value and handle it from callers
2165
    # FIXME Improve the return value and handle it from callers
2170
    $schema->txn_do(sub {
2166
    $schema->txn_do(sub {
2171
2167
2168
        # Update the returndate
2172
        $dbh->do( $query, undef, @bind );
2169
        $dbh->do( $query, undef, @bind );
2173
2170
2171
        # Retrieve the issue
2174
        my $issue = Koha::Checkouts->find( $issue_id ); # FIXME should be fetched earlier
2172
        my $issue = Koha::Checkouts->find( $issue_id ); # FIXME should be fetched earlier
2175
2173
2176
        # Create the old_issues entry
2174
        # Create the old_issues entry
2177
        my $old_checkout_data = $issue->unblessed;
2175
        my $old_checkout = Koha::Old::Checkout->new($issue->unblessed)->store;
2178
2179
        if ( Koha::Old::Checkouts->find( $issue_id ) ) {
2180
            my $new_issue_id = ( Koha::Old::Checkouts->search(
2181
                {},
2182
                { columns => [ { max_issue_id => { max => 'issue_id' } } ] }
2183
            )->get_column('max_issue_id') )[0];
2184
            $new_issue_id++;
2185
            $issue_id = $new_issue_id;
2186
        }
2187
        $old_checkout_data->{issue_id} = $issue_id;
2188
        my $old_checkout = Koha::Old::Checkout->new($old_checkout_data)->store;
2189
2176
2190
        # Update the fines
2177
        # Update the fines
2191
        $dbh->do(q|UPDATE accountlines SET issue_id = ? WHERE issue_id = ?|, undef, $old_checkout->issue_id, $issue->issue_id);
2178
        $dbh->do(q|UPDATE accountlines SET issue_id = ? WHERE issue_id = ?|, undef, $old_checkout->issue_id, $issue->issue_id);
Lines 2195-2201 sub MarkIssueReturned { Link Here
2195
            $dbh->do(q|UPDATE old_issues SET borrowernumber=? WHERE issue_id = ?|, undef, $anonymouspatron, $old_checkout->issue_id);
2182
            $dbh->do(q|UPDATE old_issues SET borrowernumber=? WHERE issue_id = ?|, undef, $anonymouspatron, $old_checkout->issue_id);
2196
        }
2183
        }
2197
2184
2198
        # Delete the issue
2185
        # And finally delete the issue
2199
        $issue->delete;
2186
        $issue->delete;
2200
2187
2201
        ModItem( { 'onloan' => undef }, undef, $itemnumber );
2188
        ModItem( { 'onloan' => undef }, undef, $itemnumber );
(-)a/circ/returns.pl (+3 lines)
Lines 549-554 foreach my $code ( keys %$messages ) { Link Here
549
    elsif ( $code eq 'NotForLoanStatusUpdated' ) {
549
    elsif ( $code eq 'NotForLoanStatusUpdated' ) {
550
        $err{NotForLoanStatusUpdated} = $messages->{NotForLoanStatusUpdated};
550
        $err{NotForLoanStatusUpdated} = $messages->{NotForLoanStatusUpdated};
551
    }
551
    }
552
    elsif ( $code eq 'DataCorrupted' ) {
553
        $err{data_corrupted} = 1;
554
    }
552
    else {
555
    else {
553
        die "Unknown error code $code";    # note we need all the (empty) elsif's above, or we die.
556
        die "Unknown error code $code";    # note we need all the (empty) elsif's above, or we die.
554
        # This forces the issue of staying in sync w/ Circulation.pm
557
        # This forces the issue of staying in sync w/ Circulation.pm
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/returns.tt (+5 lines)
Lines 237-242 $(document).ready(function () { Link Here
237
        <p>This item must be checked in at following library: <strong>[% Branches.GetName( rightbranch ) %]</strong></p>
237
        <p>This item must be checked in at following library: <strong>[% Branches.GetName( rightbranch ) %]</strong></p>
238
    </div>
238
    </div>
239
[% END %]
239
[% END %]
240
240
<!-- case of a mistake in transfer loop -->
241
<!-- case of a mistake in transfer loop -->
241
[% IF ( WrongTransfer ) %]
242
[% IF ( WrongTransfer ) %]
242
    <div id="return2" class="dialog message">
243
    <div id="return2" class="dialog message">
Lines 640-645 $(document).ready(function () { Link Here
640
            [% IF ( errmsgloo.foreverdebarred ) %]
641
            [% IF ( errmsgloo.foreverdebarred ) %]
641
                <p class="problem"><b>Reminder: </b>Patron has an indefinite restriction.</p>
642
                <p class="problem"><b>Reminder: </b>Patron has an indefinite restriction.</p>
642
            [% END %]
643
            [% END %]
644
645
            [% IF errmsgloo.data_corrupted %]
646
                <p class="problem">The item has not been checked in due to a configuration issue in your system. You must ask an administrator to take a look at the <a href="/cgi-bin/koha/about.pl#sysinfo">about page</a> and search for the "data problems" section</p>
647
            [% END %]
643
        [% END %]
648
        [% END %]
644
    </div>
649
    </div>
645
[% END %]
650
[% END %]
(-)a/t/db_dependent/Circulation/Returns.t (-12 / +22 lines)
Lines 277-283 subtest "AddReturn logging on statistics table (item-level_itypes=0)" => sub { Link Here
277
};
277
};
278
278
279
subtest 'Handle ids duplication' => sub {
279
subtest 'Handle ids duplication' => sub {
280
    plan tests => 4;
280
    plan tests => 6;
281
281
282
    t::lib::Mocks::mock_preference( 'item-level_itypes', 1 );
282
    t::lib::Mocks::mock_preference( 'item-level_itypes', 1 );
283
    t::lib::Mocks::mock_preference( 'CalculateFinesOnReturn', 1 );
283
    t::lib::Mocks::mock_preference( 'CalculateFinesOnReturn', 1 );
Lines 302-322 subtest 'Handle ids duplication' => sub { Link Here
302
    $patron = Koha::Patrons->find( $patron->{borrowernumber} );
302
    $patron = Koha::Patrons->find( $patron->{borrowernumber} );
303
303
304
    my $original_checkout = AddIssue( $patron->unblessed, $item->{barcode}, dt_from_string->subtract( days => 50 ) );
304
    my $original_checkout = AddIssue( $patron->unblessed, $item->{barcode}, dt_from_string->subtract( days => 50 ) );
305
    $builder->build({ source => 'OldIssue', value => { issue_id => $original_checkout->issue_id } });
306
    my $old_checkout = Koha::Old::Checkouts->find( $original_checkout->issue_id );
307
305
308
    AddRenewal( $patron->borrowernumber, $item->{itemnumber} );
306
    my $issue_id = $original_checkout->issue_id;
307
    # Create an existing entry in old_issue
308
    $builder->build({ source => 'OldIssue', value => { issue_id => $issue_id } });
309
310
    my $old_checkout = Koha::Old::Checkouts->find( $issue_id );
309
311
310
    my ($doreturn, $messages, $new_checkout, $borrower) = AddReturn( $item->{barcode}, undef, undef, undef, dt_from_string );
312
    my ($doreturn, $messages, $new_checkout, $borrower);
313
    warning_like {
314
        ( $doreturn, $messages, $new_checkout, $borrower ) =
315
          AddReturn( $item->{barcode}, undef, undef, undef, dt_from_string );
316
    }
317
    [
318
        qr{.*DBD::mysql::st execute failed: Duplicate entry.*},
319
        { carped => qr{The checkin for the following issue failed.*DBIx::Class::Storage::DBI::_dbh_execute.*} }
320
    ],
321
    'DBD should have raised an error about dup primary key';
311
322
312
    my $account_lines = Koha::Account::Lines->search({ borrowernumber => $patron->borrowernumber, issue_id => $original_checkout->issue_id });
323
    is( $doreturn, 0, 'Return should not have been done' );
313
    is( $account_lines->count, 0, 'No account lines should exist on old issue_id' );
324
    is( $messages->{WasReturned}, 0, 'messages should have the WasReturned flag set to 0' );
325
    is( $messages->{DataCorrupted}, 1, 'messages should have the DataCorrupted flag set to 1' );
314
326
315
    $account_lines = Koha::Account::Lines->search({ borrowernumber => $patron->borrowernumber, issue_id => $new_checkout->{issue_id} });
327
    my $account_lines = Koha::Account::Lines->search({ borrowernumber => $patron->borrowernumber, issue_id => $issue_id });
316
    is( $account_lines->count, 2, 'Two account lines should exist on new issue_id' );
328
    is( $account_lines->count, 0, 'No account lines should exist for this issue_id, patron should not have been charged' );
317
329
318
    isnt( $original_checkout->issue_id, $new_checkout->{issue_id}, 'AddReturn should return the issue with the new issue_id' );
330
    is( Koha::Checkouts->find( $issue_id )->issue_id, $issue_id, 'The issues entry should not have been removed' );
319
    isnt( $old_checkout->itemnumber, $item->{itemnumber}, 'If an item is checked-in, it should be moved to old_issues even if the issue_id already existed in the table' );
320
};
331
};
321
332
322
1;
333
1;
323
- 

Return to bug 18966