Bug 18651: Update accountlines.issue_id is the issue_id has been changed during the move

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Chris Cormack <chrisc@catalyst.net.nz>

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
(cherry picked from commit be3d39c8b1)
Signed-off-by: Fridolin Somers <fridolin.somers@biblibre.com>
This commit is contained in:
Jonathan Druart 2017-05-22 14:30:48 -03:00 committed by Fridolin Somers
parent e5f05f2634
commit 45bc82bb7d
2 changed files with 8 additions and 2 deletions

View File

@ -2175,6 +2175,7 @@ sub MarkIssueReturned {
$schema->txn_do(sub {
$dbh->do( $query, undef, @bind );
my $original_issue_id = $issue_id;
my $id_already_exists = $dbh->selectrow_array(
q|SELECT COUNT(*) FROM old_issues WHERE issue_id = ?|,
undef, $issue_id
@ -2191,6 +2192,8 @@ sub MarkIssueReturned {
$dbh->do(q|INSERT INTO old_issues SELECT * FROM issues WHERE issue_id = ?|, undef, $issue_id);
$dbh->do(q|UPDATE accountlines SET issue_id = ? WHERE issue_id = ?|, undef, $issue_id, $original_issue_id);
# anonymise patron checkout immediately if $privacy set to 2 and AnonymousPatron is set to a valid borrowernumber
if ( $privacy == 2) {
$dbh->do(q|UPDATE old_issues SET borrowernumber=? WHERE issue_id = ?|, undef, $anonymouspatron, $issue_id);

View File

@ -296,8 +296,11 @@ subtest 'Handle ids duplication' => sub {
my ($doreturn, $messages, $new_checkout, $borrower) = AddReturn( $item->{barcode}, undef, undef, undef, dt_from_string );
my $account_lines = Koha::Account::Lines->search({ borrowernumber => $patron->borrowernumber, issue_id => $new_checkout->{issue_id} });
is( $account_lines->count, 1, 'One account line should exist on new issue_id' );
my $account_lines = Koha::Account::Lines->search({ borrowernumber => $patron->borrowernumber, issue_id => $original_checkout->issue_id });
is( $account_lines->count, 0, 'No account lines should exist on old issue_id' );
$account_lines = Koha::Account::Lines->search({ borrowernumber => $patron->borrowernumber, issue_id => $new_checkout->{issue_id} });
is( $account_lines->count, 2, 'Two account lines should exist on new issue_id' );
isnt( $original_checkout->issue_id, $new_checkout->{issue_id}, 'AddReturn should return the issue with the new issue_id' );
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' );