From 9e821301e8f4428f3ab73ba9f121b205bd28a715 Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Wed, 31 May 2023 12:02:41 +0000 Subject: [PATCH] Bug 33493: (follow-up) Rename relationship and add test Signed-off-by: Marcel de Rooy Signed-off-by: Tomas Cohen Arazi (cherry picked from commit 110d74f572748958720ee690ea68d666a7a0b477) Signed-off-by: Martin Renvoize --- Koha/Item.pm | 4 +-- Koha/Schema/Result/Item.pm | 2 +- t/db_dependent/Koha/Item.t | 54 +++++++++++++++++++++++++++++++++++++- 3 files changed, 56 insertions(+), 4 deletions(-) diff --git a/Koha/Item.pm b/Koha/Item.pm index ae2bb21561..c0d63c4c97 100644 --- a/Koha/Item.pm +++ b/Koha/Item.pm @@ -565,7 +565,7 @@ we still expect the item to end up at a final location eventually. sub get_transfer { my ($self) = @_; - my $transfer = $self->_result->branchtransfer; + my $transfer = $self->_result->current_branchtransfers; return Koha::Item::Transfers->_new_from_dbic($transfer)->next; } @@ -590,7 +590,7 @@ we still expect the item to end up at a final location eventually. sub get_transfers { my ($self) = @_; - my $transfer_rs = $self->_result->branchtransfer; + my $transfer_rs = $self->_result->current_branchtransfers; return Koha::Item::Transfers->_new_from_dbic($transfer_rs); } diff --git a/Koha/Schema/Result/Item.pm b/Koha/Schema/Result/Item.pm index 72112d27d3..50a9aac2cd 100644 --- a/Koha/Schema/Result/Item.pm +++ b/Koha/Schema/Result/Item.pm @@ -973,7 +973,7 @@ __PACKAGE__->many_to_many( ); __PACKAGE__->has_many( - "branchtransfer", + "current_branchtransfers", "Koha::Schema::Result::Branchtransfer", { 'foreign.itemnumber' => 'self.itemnumber' }, { diff --git a/t/db_dependent/Koha/Item.t b/t/db_dependent/Koha/Item.t index 7a4222ece1..52577c2797 100755 --- a/t/db_dependent/Koha/Item.t +++ b/t/db_dependent/Koha/Item.t @@ -20,7 +20,7 @@ use Modern::Perl; use utf8; -use Test::More tests => 28; +use Test::More tests => 29; use Test::Exception; use Test::MockModule; @@ -2160,3 +2160,55 @@ subtest 'is_denied_renewal' => sub { $schema->storage->txn_rollback; }; + +subtest 'current_branchtransfers relationship' => sub { + plan tests => 3; + + $schema->storage->txn_begin; + + my $biblio = $builder->build_sample_biblio(); + my $item = $builder->build_sample_item( + { + biblionumber => $biblio->biblionumber, + } + ); + my $transfers = $item->_result->current_branchtransfers; + is( ref($transfers), 'DBIx::Class::ResultSet', + 'current_branchtransfers returns a Koha::Item::Transfers object set' ); + is( $transfers->count, 0, + "Empty Koha::Item::Transfers set returned if no return_claims" ); + my $transfer1 = $builder->build( + { + source => 'Branchtransfer', + value => { + itemnumber => $item->itemnumber, + datearrived => dt_from_string, + } + } + ); + my $transfer2 = $builder->build( + { + source => 'Branchtransfer', + value => { + itemnumber => $item->itemnumber, + datearrived => undef, + datecancelled => dt_from_string, + } + } + ); + my $transfer3 = $builder->build( + { + source => 'Branchtransfer', + value => { + itemnumber => $item->itemnumber, + datearrived => undef, + datecancelled => undef, + } + } + ); + + is( $item->_result->current_branchtransfers()->count, + 1, "One transfer found for item" ); + + $schema->storage->txn_rollback; +}; -- 2.39.5