Bugzilla – Attachment 61980 Details for
Bug 18402
Add the Koha::Item->checkout method
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 18402: Add the Koha::Item->checkout method
Bug-18402-Add-the-KohaItem-checkout-method.patch (text/plain), 3.86 KB, created by
Jonathan Druart
on 2017-04-07 21:21:21 UTC
(
hide
)
Description:
Bug 18402: Add the Koha::Item->checkout method
Filename:
MIME Type:
Creator:
Jonathan Druart
Created:
2017-04-07 21:21:21 UTC
Size:
3.86 KB
patch
obsolete
>From 50abc2205ddd63725a44c0c711108c70daab7812 Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >Date: Wed, 5 Apr 2017 16:42:35 -0300 >Subject: [PATCH] Bug 18402: Add the Koha::Item->checkout method > >Return the current checkout for a given item. >Note it may not exist. > >Test plan: > prove t/db_dependent/Koha/Items.t >should return green >--- > Koha/Item.pm | 16 ++++++++++++++++ > t/db_dependent/Koha/Items.t | 30 +++++++++++++++++++++++++++++- > 2 files changed, 45 insertions(+), 1 deletion(-) > >diff --git a/Koha/Item.pm b/Koha/Item.pm >index 617f10c..0161581 100644 >--- a/Koha/Item.pm >+++ b/Koha/Item.pm >@@ -25,6 +25,7 @@ use Koha::Database; > use Koha::DateUtils qw( dt_from_string ); > > use C4::Context; >+use Koha::Checkouts; > use Koha::IssuingRules; > use Koha::Item::Transfer; > use Koha::Patrons; >@@ -92,6 +93,21 @@ sub biblio { > return Koha::Biblio->_new_from_dbic( $biblio_rs ); > } > >+=head3 checkout >+ >+my $checkout = $item->checkout; >+ >+Return the checkout for this item >+ >+=cut >+ >+sub checkout { >+ my ( $self ) = @_; >+ my $checkout_rs = $self->_result->issue; >+ return unless $checkout_rs; >+ return Koha::Checkout->_new_from_dbic( $checkout_rs ); >+} >+ > =head3 get_transfer > > my $transfer = $item->get_transfer; >diff --git a/t/db_dependent/Koha/Items.t b/t/db_dependent/Koha/Items.t >index c9d4bac..0989b21 100644 >--- a/t/db_dependent/Koha/Items.t >+++ b/t/db_dependent/Koha/Items.t >@@ -19,7 +19,7 @@ > > use Modern::Perl; > >-use Test::More tests => 6; >+use Test::More tests => 7; > > use C4::Circulation; > use Koha::Item; >@@ -41,6 +41,7 @@ my $new_item_1 = Koha::Item->new( > homebranch => $library->{branchcode}, > holdingbranch => $library->{branchcode}, > barcode => "a_barcode_for_t", >+ itype => 'BK', > } > )->store; > my $new_item_2 = Koha::Item->new( >@@ -49,9 +50,13 @@ my $new_item_2 = Koha::Item->new( > homebranch => $library->{branchcode}, > holdingbranch => $library->{branchcode}, > barcode => "another_barcode_for_t", >+ itype => 'BK', > } > )->store; > >+C4::Context->_new_userenv('xxx'); >+C4::Context->set_userenv(0,0,0,'firstname','surname', $library->{branchcode}, 'Midway Public Library', '', '', ''); >+ > like( $new_item_1->itemnumber, qr|^\d+$|, 'Adding a new item should have set the itemnumber' ); > is( Koha::Items->search->count, $nb_of_items + 2, 'The 2 items should have been added' ); > >@@ -82,6 +87,29 @@ subtest 'biblio' => sub { > is( $biblio->biblionumber, $retrieved_item_1->biblionumber, 'Koha::Item->biblio should return the correct biblio' ); > }; > >+subtest 'checkout' => sub { >+ plan tests => 5; >+ my $item = Koha::Items->find( $new_item_1->itemnumber ); >+ # No checkout yet >+ my $checkout = $item->checkout; >+ is( $checkout, undef, 'Koha::Item->checkout should return undef if there is no current checkout on this item' ); >+ >+ # Add a checkout >+ my $patron = $builder->build({ source => 'Borrower' }); >+ C4::Circulation::AddIssue( $patron, $item->barcode ); >+ $checkout = $retrieved_item_1->checkout; >+ is( ref( $checkout ), 'Koha::Checkout', 'Koha::Item->checkout should return a Koha::Checkout' ); >+ is( $checkout->itemnumber, $item->itemnumber, 'Koha::Item->checkout should return the correct checkout' ); >+ is( $checkout->borrowernumber, $patron->{borrowernumber}, 'Koha::Item->checkout should return the correct checkout' ); >+ >+ # Do the return >+ C4::Circulation::AddReturn( $item->barcode ); >+ >+ # There is no more checkout on this item, making sure it will not return old checkouts >+ $checkout = $item->checkout; >+ is( $checkout, undef, 'Koha::Item->checkout should return undef if there is no *current* checkout on this item' ); >+}; >+ > $retrieved_item_1->delete; > is( Koha::Items->search->count, $nb_of_items + 1, 'Delete should have deleted the item' ); > >-- >2.9.3
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 18402
:
61980
|
62009
|
62035
|
62701