Bug 20934: Fix display of old checkouts in the checkout history page
authorJonathan Druart <jonathan.druart@bugs.koha-community.org>
Wed, 13 Jun 2018 16:26:43 +0000 (13:26 -0300)
committerNick Clemens <nick@bywatersolutions.com>
Fri, 22 Jun 2018 12:47:48 +0000 (12:47 +0000)
Again a regression caused by
  commit fa54100dffe092e606f79b15692eedaf78f42e45
  Bug 18403: Use patron-title.inc when hidepatronname is used [SPECIFIC for issuehistory]

GetBiblioIssues does a union all with issues and old_issues, so we
should old_issues as well.
To make the join on the items table we need to define the item and
patron methods. For consistency the relationships have been redefined
(item instead of itemnumber, borrower instead of borrowernumber) in the
DBIx::Class definition.

This is not perfect but I think the best way to provide an easy to
backport patch.

It highlights that we need improvements in this area.

Signed-off-by: Maryse Simard <maryse.simard@inlibro.com>
The patch works as expected.

Signed-off-by: Josef Moravec <josef.moravec@gmail.com>

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>

Koha/Old/Checkout.pm
Koha/Schema/Result/OldIssue.pm
catalogue/issuehistory.pl
koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/issuehistory.tt

index 3a7c1eb..2507cc1 100644 (file)
@@ -21,6 +21,38 @@ use Koha::Database;
 
 use base qw(Koha::Object);
 
+=head3 item
+
+my $item = $checkout->item;
+
+Return the checked out item
+
+=cut
+
+sub item {
+    my ( $self ) = @_;
+    my $item_rs = $self->_result->item;
+    return Koha::Item->_new_from_dbic( $item_rs );
+}
+
+=head3 patron
+
+my $patron = $checkout->patron
+
+Return the patron for who the checkout has been done
+
+=cut
+
+sub patron {
+    my ( $self ) = @_;
+    my $patron_rs = $self->_result->borrower;
+    return Koha::Patron->_new_from_dbic( $patron_rs );
+}
+
+
+
+
+
 sub _type {
     return 'OldIssue';
 }
index b9c5b23..32a90ab 100644 (file)
@@ -229,6 +229,25 @@ __PACKAGE__->belongs_to(
 # Created by DBIx::Class::Schema::Loader v0.07042 @ 2018-02-16 17:54:54
 # DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:RKLeDDEz22G5BU/ZAl7QLA
 
+__PACKAGE__->belongs_to(
+    "borrower",
+    "Koha::Schema::Result::Borrower",
+    { borrowernumber => "borrowernumber" },
+    { join_type => "LEFT", on_delete => "CASCADE", on_update => "CASCADE" },
+);
+
+__PACKAGE__->belongs_to(
+  "item",
+  "Koha::Schema::Result::Item",
+  { itemnumber => "itemnumber" },
+  {
+    is_deferrable => 1,
+    join_type     => "LEFT",
+    on_delete     => "CASCADE",
+    on_update     => "CASCADE",
+  },
+);
+
 sub koha_objects_class {
     'Koha::Old::Checkouts';
 }
index 6a7f623..f704402 100755 (executable)
@@ -25,6 +25,7 @@ use C4::Output;
 use C4::Biblio;    # GetBiblio
 use C4::Search;                # enabled_staff_search_views
 use Koha::Checkouts;
+use Koha::Old::Checkouts;
 
 use Koha::Biblios;
 
@@ -41,17 +42,25 @@ my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
 
 my $biblionumber = $query->param('biblionumber');
 
-my $checkouts = Koha::Checkouts->search(
+my @checkouts = Koha::Checkouts->search(
     { biblionumber => $biblionumber },
     {
         join       => 'item',
         order_by   => 'timestamp',
     }
 );
+my @old_checkouts = Koha::Old::Checkouts->search(
+    { biblionumber => $biblionumber },
+    {
+        join       => 'item',
+        order_by   => 'timestamp',
+    }
+);
+
 my $biblio = Koha::Biblios->find( $biblionumber );
 
 $template->param(
-    checkouts => $checkouts,
+    checkouts => [ @checkouts, @old_checkouts ],
     biblio    => $biblio,
        issuehistoryview => 1,
        C4::Search::enabled_staff_search_views,
index 0d3c01d..e831fa6 100644 (file)
@@ -26,8 +26,8 @@
 [% IF biblio.author %]<h3>by [% biblio.author %]</h3>[% END %]
 
 <div class="searchresults">
-    [% IF checkouts.count %]
-        <h4>Checked out [% checkouts.count %] times</h4>
+    [% IF checkouts %]
+        <h4>Checked out [% checkouts %] times</h4>
         <table id="table_issues">
             <thead><tr>
             [% IF Koha.Preference('intranetreadinghistory') AND CAN_user_circulate_circulate_remaining_permissions %]