From 56bfbfc034131f2b2d7fa93093792f21b3a7f7a1 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 Content-Type: text/plain; charset=utf-8 Signed-off-by: Marcel de Rooy --- 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 d38265903f..7f5362dc68 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 8b6abda059..c5fd5fec1a 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; @@ -2175,3 +2175,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.30.2