From 7fd26e069eb0694f07ee63fbacebd3e8d1c8290c Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Thu, 8 Jun 2023 09:36:35 +0200 Subject: [PATCH] Bug 33948: Replace GetAllIssues with Koha::Checkouts - staff This patch replace GetAllIssues in readingrec.pl which is the only occurrence in the staff code. To test this patch you will need several items in your checkout history in order to confirm that the display is the same before and after the patch. However there is one change! And it's a bug fix (or an enhancement, it depends on how you see things). It includes checkouts with deleted items, which is a long standing bug (see bug 8483). Performance will be compared as well. Signed-off-by: Fridolin Somers Signed-off-by: Kyle M Hall Signed-off-by: Tomas Cohen Arazi --- .../prog/en/modules/members/readingrec.tt | 56 +++++++++---------- members/readingrec.pl | 32 +++++++---- 2 files changed, 50 insertions(+), 38 deletions(-) diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/members/readingrec.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/members/readingrec.tt index a872b6f79f..b45cf35308 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/readingrec.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/members/readingrec.tt @@ -43,13 +43,14 @@ [% INCLUDE 'members-toolbar.inc' %]

Circulation history

+[% SET all_checkouts = checkouts.merge(old_checkouts) %] [% UNLESS Koha.Preference('intranetreadinghistory') %]
Staff members are not allowed to access patron's checkout history
[% ELSIF is_anonymous %]
This is the anonymous patron, so no circulation history is displayed. To get a list of anonymized loans, please run a report.
[% ELSIF ( patron.privacy == 2) %]
This patron has set the privacy rules to never keeping a circulation history.
-[% ELSIF ( !loop_reading ) %] +[% ELSIF ( !all_checkouts.size ) %]
This patron has no circulation history.
[% ELSE %]
@@ -76,57 +77,56 @@ - [% FOREACH issue IN loop_reading %] - [% IF issue.returndate %][% ELSE %][% END %] + [% FOREACH checkout IN all_checkouts %] + [% SET item = checkout.item %] + [% SET biblio = item.biblio %] + [% IF checkout.returndate %][% ELSE %][% END %] - [% IF issue.onsite_checkout %][% issuetype = 'onsite_checkout' | html %] + [% IF checkout.onsite_checkout %][% issuetype = 'onsite_checkout' | html %] [% ELSE %][% issuetype = 'standard_checkout' | html %] [% END %] [% issuetype | html %] - - [% issue.issuestimestamp | $KohaDates with_hours => 1 %] + + [% checkout.timestamp | $KohaDates with_hours => 1 %] - [% INCLUDE 'biblio-title.inc' biblio=issue link = 1 %] + [% INCLUDE 'biblio-title.inc' biblio=biblio link = 1 %] - [% issue.author | html %] + [% biblio.author | html %] - [% IF issue.classification %] - [% issue.classification | html %] - [% ELSE %] - [% issue.itemcallnumber | html %] - [% END %] + [% item.itemcallnumber | html %] - [% IF issue.enumchron %] - [% issue.enumchron | html %] + [% IF item.enumchron %] + [% item.enumchron | html %] [% END %] - [% issue.barcode | html %] + [% item.barcode | html %] - [% issue.renewals_count | html %] - [% IF issue.renewals_count > 0 %] - [ View ] + [% checkout.renewals_count | html %] + [% IF checkout.renewals_count > 0 %] + [ View ] [% END %] - - [% issue.issuedate |$KohaDates with_hours => 1 %] + + [% checkout.issuedate | $KohaDates with_hours => 1 %] - [% Branches.GetName( issue.branchcode ) | html %] + [% Branches.GetName( checkout.branchcode ) | html %] [% IF Koha.Preference('RecordStaffUserOnCheckout') %] - [% issue.firstname | html %] [% issue.surname | html %] + [% SET issuer = checkout.issuer %] + [% issuer.firstname | html %] [% issuer.surname | html %] [% END %] - - [% issue.date_due | $KohaDates as_due_date => 1 %] + + [% checkout.date_due | $KohaDates as_due_date => 1 %] - [% IF issue.returndate %] - - [% issue.returndate |$KohaDates with_hours => 1 %] + [% IF checkout.returndate %] + + [% checkout.returndate | $KohaDates with_hours => 1 %] [% ELSE %] Checked out diff --git a/members/readingrec.pl b/members/readingrec.pl index 0dcdab25ce..08eff9f010 100755 --- a/members/readingrec.pl +++ b/members/readingrec.pl @@ -26,7 +26,6 @@ use CGI qw ( -utf8 ); use C4::Auth qw( get_template_and_user ); use C4::Output qw( output_and_exit_if_error output_and_exit output_html_with_http_headers ); -use C4::Members qw( GetAllIssues ); use List::MoreUtils qw( any uniq ); use Koha::DateUtils qw( dt_from_string ); use Koha::ActionLogs; @@ -79,26 +78,39 @@ if ( $op eq 'export_barcodes' ) { } } -my $order = 'date_due desc'; -my $limit = 0; -my $issues = (); # Do not request the old issues of anonymous patron if ( $patron->borrowernumber eq C4::Context->preference('AnonymousPatron') ){ # use of 'eq' in the above comparison is intentional -- the # system preference value could be blank $template->param( is_anonymous => 1 ); } else { - $issues = GetAllIssues($patron->borrowernumber,$order,$limit); -} - -if (! $limit){ - $limit = 'full'; + $template->param( + checkouts => [ + $patron->checkouts( + {}, + { + order_by => 'date_due desc', + prefetch => { item => { biblio => 'biblioitems' } }, + } + )->as_list + ] + ); + $template->param( + old_checkouts => [ + $patron->old_checkouts( + {}, + { + order_by => 'date_due desc', + prefetch => { item => { biblio => 'biblioitems' } }, + } + )->as_list + ] + ); } $template->param( patron => $patron, readingrecordview => 1, - loop_reading => $issues ); output_html_with_http_headers $input, $cookie, $template->output; -- 2.39.5