From 814789f8cb18d324591ecaeeeb01f6c79d4b239f Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Wed, 22 Sep 2021 11:49:14 +0000 Subject: [PATCH] Bug 29062: Use primary key issued_id to fetch old_issues for letters The code currently uses itemnumber to fetch old_issues for notices. This doesn't seem to be used in any current notices except the CHECKINSLIP: SELECTY letter.code,content FROM letter WHERE content LIKE 'old\\_%'\G For issues we use itemnumber, however, issues has a constraint to limit issues for an itemnumber to 1 Old issues has no such constraint, we try to rectify this in the old code by adding 'ORDER BY returndate DESC LIMIT 1" As the code is not used by default and buggy I think we can make a change to using 'issue_id' as the key and announcing the change - it prevents leaky data To test: 1. Check something out to patron A. Check it in. 2. Check something out to patron B. Check it in. 3. Check something out to patron C. Check it in and print the check-in slip. (Leave the checkin paghe open) 4. You will see the checkin repeat itself 3 times, one for each line in old_issues. 5. Apply patch and restart_all 6. Click the 'Print checkin slip' button again 7. You see a single checkin 8. Checkout a different item to patron A. Check it in and print the check-in slip 9. See the correct checkins Signed-off-by: Lucas Gass Signed-off-by: Marcel de Rooy Signed-off-by: Jonathan Druart --- C4/Letters.pm | 4 ++-- members/printslip.pl | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/C4/Letters.pm b/C4/Letters.pm index a02c0d51a9..f3cabc2856 100644 --- a/C4/Letters.pm +++ b/C4/Letters.pm @@ -785,7 +785,7 @@ sub _parseletter_sth { ($table eq 'debits' ) ? "SELECT * FROM accountlines WHERE accountlines_id = ?" : ($table eq 'items' ) ? "SELECT * FROM $table WHERE itemnumber = ?" : ($table eq 'issues' ) ? "SELECT * FROM $table WHERE itemnumber = ?" : - ($table eq 'old_issues' ) ? "SELECT * FROM $table WHERE itemnumber = ? ORDER BY timestamp DESC LIMIT 1" : + ($table eq 'old_issues' ) ? "SELECT * FROM $table WHERE issue_id = ?" : ($table eq 'reserves' ) ? "SELECT * FROM $table WHERE borrowernumber = ? and biblionumber = ?" : ($table eq 'borrowers' ) ? "SELECT * FROM $table WHERE borrowernumber = ?" : ($table eq 'branches' ) ? "SELECT * FROM $table WHERE branchcode = ?" : @@ -1757,7 +1757,7 @@ sub _get_tt_params { module => 'Koha::Old::Checkouts', singular => 'old_checkout', plural => 'old_checkouts', - fk => 'itemnumber', + pk => 'issue_id', }, overdues => { module => 'Koha::Checkouts', diff --git a/members/printslip.pl b/members/printslip.pl index 1bb11f68be..368d84cc7f 100755 --- a/members/printslip.pl +++ b/members/printslip.pl @@ -71,11 +71,11 @@ if ( $print eq 'checkinslip' ) { my $checkinslip_branch = $session->param('branch') ? $session->param('branch') : $branch; # get today's checkins - my @itemnumbers = $patron->old_checkouts->search( { branchcode => $checkinslip_branch } ) - ->filter_by_todays_checkins->get_column('itemnumber'); + my @issue_ids = $patron->old_checkouts->search( { branchcode => $checkinslip_branch } ) + ->filter_by_todays_checkins->get_column('issue_id'); my %loops = ( - old_issues => \@itemnumbers, + old_issues => \@issue_ids, ); my $letter = C4::Letters::GetPreparedLetter( -- 2.39.5