From 289320f9938182b41948c6b416ade9156100b99c Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Mon, 20 Jan 2020 15:51:39 +0000 Subject: [PATCH] Bug 25767: Add Koha::Item::Transfer->receive method MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Was Bug 25767: Add Koha::Item::Transfer->receipt method Signed-off-by: Kathleen Milne Signed-off-by: Katrin Fischer Signed-off-by: Joonas Kylmälä Bug 25767: Add unit tests for Koha::Item::Transfer->receipt Signed-off-by: Kathleen Milne Signed-off-by: Katrin Fischer Signed-off-by: Joonas Kylmälä Bug 25767: (QA follow-up) receipt -> receive Signed-off-by: Kathleen Milne Signed-off-by: Katrin Fischer Signed-off-by: Joonas Kylmälä --- Koha/Item/Transfer.pm | 19 ++++++++++ t/db_dependent/Koha/Item/Transfer.t | 59 ++++++++++++++++++++++++++++- 2 files changed, 77 insertions(+), 1 deletion(-) diff --git a/Koha/Item/Transfer.pm b/Koha/Item/Transfer.pm index 2928480c0a..0afe12ed1a 100644 --- a/Koha/Item/Transfer.pm +++ b/Koha/Item/Transfer.pm @@ -84,6 +84,25 @@ sub transit { return $self; } +=head3 receive + +Receive the transfer by setting the datearrived time. + +=cut + +sub receive { + my ($self) = @_; + + # Throw exception if item is checked out + Koha::Exceptions::Item::Transfer::Out->throw() if ($self->item->checkout); + + # Update the arrived date + $self->set({ datearrived => dt_from_string })->store; + + ModDateLastSeen( $self->item->itemnumber ); + return $self; +} + =head3 type =cut diff --git a/t/db_dependent/Koha/Item/Transfer.t b/t/db_dependent/Koha/Item/Transfer.t index 4b094d80cb..b82e2c8094 100755 --- a/t/db_dependent/Koha/Item/Transfer.t +++ b/t/db_dependent/Koha/Item/Transfer.t @@ -23,7 +23,7 @@ use Koha::Database; use t::lib::TestBuilder; -use Test::More tests => 2; +use Test::More tests => 3; use Test::Exception; my $schema = Koha::Database->new->schema; @@ -112,3 +112,60 @@ subtest 'transit tests' => sub { $schema->storage->txn_rollback; }; + +subtest 'receive tests' => sub { + plan tests => 5; + + $schema->storage->txn_begin; + + my $library1 = $builder->build_object( { class => 'Koha::Libraries' } ); + my $library2 = $builder->build_object( { class => 'Koha::Libraries' } ); + my $item = $builder->build_sample_item( + { + homebranch => $library1->branchcode, + holdingbranch => $library2->branchcode, + datelastseen => undef + } + ); + + my $transfer = $builder->build_object( + { + class => 'Koha::Item::Transfers', + value => { + itemnumber => $item->itemnumber, + frombranch => $library2->branchcode, + tobranch => $library1->branchcode, + datearrived => undef, + reason => 'Manual' + } + } + ); + is( ref($transfer), 'Koha::Item::Transfer', 'Mock transfer added' ); + + # Item checked out should result in failure + my $checkout = $builder->build_object( + { + class => 'Koha::Checkouts', + value => { + itemnumber => $item->itemnumber + } + } + ); + is( ref($checkout), 'Koha::Checkout', 'Mock checkout added' ); + + throws_ok { $transfer->receive() } + 'Koha::Exceptions::Item::Transfer::Out', + 'Exception thrown if item is checked out'; + + $checkout->delete; + + # Transit state set + $transfer->discard_changes; + $transfer->receive(); + ok( $transfer->datearrived, 'Receipt set the datearrived for the transfer' ); + + # Last seen + ok( $item->datelastseen, 'Receipt set item datelastseen date' ); + + $schema->storage->txn_rollback; +}; -- 2.20.1