From de3b22db0c7e6e7ea96d8a3fff6c0ba6939b9519 Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Tue, 9 Aug 2022 08:40:45 -0300 Subject: [PATCH] Bug 31328: Make Koha::Item->get_transfer* use Koha::Item::Transfers->filter_by_current This patch makes the get_transfer and get_transfers methods internally use the new ->filter_by_current method. To test: 1. Run: $ kshell k$ prove t/db_dependent/Koha/Item.t => SUCCESS: Tests pass! 2. Apply this rewriting patch 3. Repeat 1 => SUCCESS: Tests still pass! 4. Sign off :-D Signed-off-by: Jonathan Druart --- Koha/Item.pm | 38 ++++++++++++++------------------------ 1 file changed, 14 insertions(+), 24 deletions(-) diff --git a/Koha/Item.pm b/Koha/Item.pm index b3ac3623347..d76722414d6 100644 --- a/Koha/Item.pm +++ b/Koha/Item.pm @@ -569,19 +569,13 @@ we still expect the item to end up at a final location eventually. sub get_transfer { my ($self) = @_; - my $transfer_rs = $self->_result->branchtransfers->search( - { - datearrived => undef, - datecancelled => undef - }, - { - order_by => - [ { -desc => 'datesent' }, { -asc => 'daterequested' } ], - rows => 1 - } - )->first; - return unless $transfer_rs; - return Koha::Item::Transfer->_new_from_dbic($transfer_rs); + + my $transfers_rs = Koha::Item::Transfers + ->_new_from_dbic(scalar $self->_result->branchtransfers) + ->filter_by_current + ->search( {}, { order_by => [ { -desc => 'datesent' }, { -asc => 'daterequested' } ], rows => 1 } ); + + return $transfers_rs->next; } =head3 get_transfers @@ -603,17 +597,13 @@ we still expect the item to end up at a final location eventually. sub get_transfers { my ($self) = @_; - my $transfer_rs = $self->_result->branchtransfers->search( - { - datearrived => undef, - datecancelled => undef - }, - { - order_by => - [ { -desc => 'datesent' }, { -asc => 'daterequested' } ], - } - ); - return Koha::Item::Transfers->_new_from_dbic($transfer_rs); + + my $transfer_rs = $self->_result->branchtransfers; + + return Koha::Item::Transfers + ->_new_from_dbic($transfer_rs) + ->filter_by_current + ->search( {}, { order_by => [ { -desc => 'datesent' }, { -asc => 'daterequested' } ], } ); } =head3 last_returned_by -- 2.25.1