From acd30ce6603609d7b2c1971f6ffda6f91fa1c458 Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Thu, 12 Dec 2024 10:18:32 -0300 Subject: [PATCH] Bug 38686: Add Koha::Items->filter_by_checked_out() This patch adds a method for filtering `Koha::Items` resultsets by keeping only those items that currently checked out. Usage: ```perl if ( $biblio->items->filter_by_checked_out()->count ) { # do your stuff } ``` To test: 1. Apply this patches 2. Run: $ ktd --shell k$ prove t/db_dependent/Koha/Items.t => SUCCESS: Tests pass 3. Sign off :-D Signed-off-by: Roman Dolny --- Koha/Items.pm | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/Koha/Items.pm b/Koha/Items.pm index 1cb1dce1b5..978be39319 100644 --- a/Koha/Items.pm +++ b/Koha/Items.pm @@ -222,6 +222,23 @@ sub filter_by_bookable { ); } +=head3 filter_by_checked_out + + my $filterd_items = $items->filter_by_checked_out(); + +Returns a new resultset, containing only those items that are checked out. + +=cut + +sub filter_by_checked_out { + my ($self) = @_; + + return $self->search( + { issue_id => { '!=' => undef } }, + { join => 'issue' } + ); +} + =head3 move_to_biblio $items->move_to_biblio($to_biblio); -- 2.39.5