From 17954a4c348b28a58f2a24ee13f658b646036413 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Tue, 23 Sep 2025 12:58:24 +0200 Subject: [PATCH] Bug 40704: Store and display deleted item for checkouts --- Koha/Item.pm | 19 ++++++++++++++++++- Koha/Old/Checkout.pm | 16 ++++++++++++++++ Koha/Old/Item.pm | 16 +++++++++++++++- .../prog/en/modules/members/readingrec.tt | 2 +- .../en/modules/opac-readingrecord.tt | 8 +++----- 5 files changed, 53 insertions(+), 8 deletions(-) diff --git a/Koha/Item.pm b/Koha/Item.pm index c675d0638e4..501e27c70ca 100644 --- a/Koha/Item.pm +++ b/Koha/Item.pm @@ -332,6 +332,8 @@ sub safe_delete { $self->move_to_deleted; + $self->old_checkouts->update( { deleted_itemnumber => $self->itemnumber } ); + return $self->delete($params); } @@ -500,11 +502,26 @@ Return the checkout for this item sub checkout { my ($self) = @_; - my $checkout_rs = $self->_result->issue; + my $checkout_rs = $self->_result->checkout; return unless $checkout_rs; return Koha::Checkout->_new_from_dbic($checkout_rs); } +=head3 old_checkouts + +my $old_checkouts = $item->old_checkouts; + +Return the old checkouts for this item + +=cut + +sub old_checkouts { + my ($self) = @_; + my $rs = $self->_result->old_checkouts; + require Koha::Old::Checkouts; + return Koha::Old::Checkouts->_new_from_dbic($rs); +} + =head3 serial_item =cut diff --git a/Koha/Old/Checkout.pm b/Koha/Old/Checkout.pm index d7171000683..be941d0c02c 100644 --- a/Koha/Old/Checkout.pm +++ b/Koha/Old/Checkout.pm @@ -47,6 +47,22 @@ sub item { return Koha::Item->_new_from_dbic($item_rs); } +=head3 deleted_item + +my $deleted_item = $checkout->deleted_item; + +Return the checked out item that has been deleted + +=cut + +sub deleted_item { + my ($self) = @_; + my $rs = $self->_result->deleted_item; + return unless $rs; + require Koha::Old::Item; + return Koha::Old::Item->_new_from_dbic($rs); +} + =head3 account_lines my $account_lines = $checkout->account_lines; diff --git a/Koha/Old/Item.pm b/Koha/Old/Item.pm index cc94cecc1e9..c0ab048a944 100644 --- a/Koha/Old/Item.pm +++ b/Koha/Old/Item.pm @@ -17,7 +17,7 @@ package Koha::Old::Item; use Modern::Perl; -use base qw(Koha::Object); +use base qw(Koha::Item); =head1 NAME @@ -31,6 +31,20 @@ Koha::Old::Item - Koha Old::Item Object class =head2 Internal methods +=head3 biblio + +my $biblio = $item->biblio; + +Return the bibliographic record of this item + +=cut + +sub biblio { + my ($self) = @_; + my $biblio_rs = $self->_result->biblio; + return Koha::Biblio->_new_from_dbic($biblio_rs); +} + =head3 _type =cut 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 f0d600463e5..d5591cbc71a 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/readingrec.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/members/readingrec.tt @@ -80,7 +80,7 @@ [% FOREACH checkout IN all_checkouts %] - [% SET item = checkout.item %] + [% SET item = checkout.item || checkout.deleted_item %] [% SET biblio = item.biblio %] diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-readingrecord.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-readingrecord.tt index 74745dad127..18e4ee62eb1 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-readingrecord.tt +++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-readingrecord.tt @@ -133,7 +133,7 @@ [% FOREACH checkout IN checkouts %] - [% SET item = checkout.item %] + [% SET item = checkout.item || checkout.deleted_item %] [% SET biblio = item.biblio %] @@ -185,14 +185,12 @@ [% END %] - [% IF item %] - [% INCLUDE 'biblio-title.inc' biblio=biblio, link => 1 %] + [% INCLUDE 'biblio-title.inc' biblio=biblio, link => 1 %] + [% UNLESS item.deleted_on %] [% IF ( Koha.Preference( 'OpacStarRatings' ) == 'all' ) %] [% SET ratings = {ratings => biblio.ratings, itemnumber => item.itemnumber, biblionumber => biblio.biblionumber, my_rating => biblio.ratings.search( borrowernumber => logged_in_user.borrowernumber ).next } %] [% INCLUDE 'user-star-ratings.inc' item=ratings %] [% END %] - [% ELSE %] - The item has been deleted [% END %] [% biblio.author | html %] -- 2.34.1