Bugzilla – Attachment 110508 Details for
Bug 25757
Add a Koha::Item::Transfer->transit method
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 25757: Add Koha::Item::Transfer->transit method
Bug-25757-Add-KohaItemTransfer-transit-method.patch (text/plain), 5.61 KB, created by
Katrin Fischer
on 2020-09-21 20:55:40 UTC
(
hide
)
Description:
Bug 25757: Add Koha::Item::Transfer->transit method
Filename:
MIME Type:
Creator:
Katrin Fischer
Created:
2020-09-21 20:55:40 UTC
Size:
5.61 KB
patch
obsolete
>From b4b910705bc01454337c2f24212abca8f213d434 Mon Sep 17 00:00:00 2001 >From: Martin Renvoize <martin.renvoize@ptfs-europe.com> >Date: Fri, 17 Jan 2020 16:35:15 +0000 >Subject: [PATCH] Bug 25757: Add Koha::Item::Transfer->transit method > >Test plan >1/ Run the included unit tests > >Signed-off-by: Kathleen Milne <kathleen.milne@cne-siar.gov.uk> > >Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de> >--- > Koha/Exceptions/Item/Transfer.pm | 5 ++ > Koha/Item/Transfer.pm | 37 +++++++++++++++ > t/db_dependent/Koha/Item/Transfer.t | 92 +++++++++++++++++++++++++++++++++++++ > 3 files changed, 134 insertions(+) > create mode 100644 t/db_dependent/Koha/Item/Transfer.t > >diff --git a/Koha/Exceptions/Item/Transfer.pm b/Koha/Exceptions/Item/Transfer.pm >index 746877bd04..40b247c59d 100644 >--- a/Koha/Exceptions/Item/Transfer.pm >+++ b/Koha/Exceptions/Item/Transfer.pm >@@ -15,7 +15,12 @@ use Exception::Class ( > 'Koha::Exceptions::Item::Transfer::Limit' => { > isa => 'Koha::Exceptions::Item::Transfer', > description => "Transfer not allowed" >+ }, >+ 'Koha::Exceptions::Item::Transfer::Out' => { >+ isa => 'Koha::Exceptions::Item::Transfer', >+ description => "Transfer item is currently checked out" > } >+ > ); > > 1; >diff --git a/Koha/Item/Transfer.pm b/Koha/Item/Transfer.pm >index 50868aba76..669559d15b 100644 >--- a/Koha/Item/Transfer.pm >+++ b/Koha/Item/Transfer.pm >@@ -19,7 +19,11 @@ use Modern::Perl; > > use Carp; > >+use C4::Items; >+ > use Koha::Database; >+use Koha::DateUtils; >+use Koha::Exceptions::Item::Transfer; > > use base qw(Koha::Object); > >@@ -47,6 +51,39 @@ sub item { > return Koha::Item->_new_from_dbic($item_rs); > } > >+=head3 transit >+ >+Set the transfer as in transit by updateing the datesent time. >+ >+Also, update date last seen and ensure item holdingbranch is correctly set. >+ >+=cut >+ >+sub transit { >+ my ($self) = @_; >+ >+ # Throw exception if item is still checked out >+ Koha::Exceptions::Item::Transfer::Out->throw() if ( $self->item->checkout ); >+ >+ # Remove the 'shelving cart' location status if it is being used (Bug 3701) >+ CartToShelf( $self->item->itemnumber ) >+ if $self->item->location >+ && $self->item->location eq 'CART' >+ && (!$self->item->permanent_location >+ || $self->item->permanent_location ne 'CART' ); >+ >+ # Update the transit state >+ $self->set( >+ { >+ frombranch => $self->item->holdingbranch, >+ datesent => 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 >new file mode 100644 >index 0000000000..37b5fbae75 >--- /dev/null >+++ b/t/db_dependent/Koha/Item/Transfer.t >@@ -0,0 +1,92 @@ >+#!/usr/bin/perl >+ >+# Copyright 2020 Koha Development team >+# >+# This file is part of Koha >+# >+# Koha is free software; you can redistribute it and/or modify it >+# under the terms of the GNU General Public License as published by >+# the Free Software Foundation; either version 3 of the License, or >+# (at your option) any later version. >+# >+# Koha is distributed in the hope that it will be useful, but >+# WITHOUT ANY WARRANTY; without even the implied warranty of >+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the >+# GNU General Public License for more details. >+# >+# You should have received a copy of the GNU General Public License >+# along with Koha; if not, see <http://www.gnu.org/licenses>. >+ >+use Modern::Perl; >+ >+use Koha::Database; >+ >+use t::lib::TestBuilder; >+ >+use Test::More tests => 1; >+use Test::Exception; >+ >+my $schema = Koha::Database->new->schema; >+my $builder = t::lib::TestBuilder->new; >+ >+subtest 'transit tests' => sub { >+ plan tests => 7; >+ >+ $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, >+ 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->transit() } >+ 'Koha::Exceptions::Item::Transfer::Out', >+ 'Exception thrown if item is checked out'; >+ >+ $checkout->delete; >+ >+ # CartToShelf test >+ $item->set({ location => 'CART', permanent_location => 'TEST' })->store(); >+ is ( $item->location, 'CART', 'Item location set to CART'); >+ $transfer->discard_changes; >+ $transfer->transit(); >+ $item->discard_changes; >+ is ( $item->location, 'TEST', 'Item location correctly restored to match permanent location'); >+ >+ # Transit state set >+ ok( $transfer->datesent, 'Transit set the datesent for the transfer' ); >+ >+ # Last seen >+ ok ( $item->datelastseen, 'Transit set item datelastseen date'); >+ >+ $schema->storage->txn_rollback; >+}; >-- >2.11.0
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 25757
:
105900
|
105901
|
105902
|
107241
|
107242
|
107243
|
107296
|
107297
|
107298
|
110274
|
110275
|
110276
|
110296
|
110297
|
110298
|
110507
|
110508
|
110509
|
116547
|
116548
|
116549
|
117580
|
117581
|
117582