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 <lucas@bywatersolutions.com>

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
This commit is contained in:
Nick Clemens 2021-09-22 11:49:14 +00:00 committed by Jonathan Druart
parent d8a2df77f8
commit 814789f8cb
2 changed files with 5 additions and 5 deletions

View File

@ -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',

View File

@ -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(