From 4937c5c339b4b5541f562ade897458868dabff77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nazl=C4=B1=20=C3=87etin?= Date: Mon, 18 Feb 2019 09:44:24 +0000 Subject: [PATCH] Bug 19489: Koha::Account::Line->issue method and Unit test Signed-off-by: Josef Moravec --- Koha/Account/Line.pm | 15 +++++++++++++ t/db_dependent/Koha/Account/Lines.t | 43 ++++++++++++++++++++++++++++++++++++- 2 files changed, 57 insertions(+), 1 deletion(-) diff --git a/Koha/Account/Line.pm b/Koha/Account/Line.pm index df5d98b..cf7e595 100644 --- a/Koha/Account/Line.pm +++ b/Koha/Account/Line.pm @@ -54,6 +54,21 @@ sub item { return Koha::Item->_new_from_dbic( $rs ); } +=head3 issue + +Return the item linked to this account line if exists + +=cut + +sub issue { + my ( $self ) = @_; + return unless $self->issue_id ; + + my $issue = Koha::Checkouts->find( $self->issue_id ); + $issue = Koha::Old::Checkouts->find( $self->issue_id ) unless $issue; + return $issue; +} + =head3 void $payment_accountline->void(); diff --git a/t/db_dependent/Koha/Account/Lines.t b/t/db_dependent/Koha/Account/Lines.t index f7f0c16..e00841c 100755 --- a/t/db_dependent/Koha/Account/Lines.t +++ b/t/db_dependent/Koha/Account/Lines.t @@ -19,7 +19,7 @@ use Modern::Perl; -use Test::More tests => 6; +use Test::More tests => 7; use Test::Exception; use Koha::Account; @@ -414,4 +414,45 @@ subtest 'adjust() tests' => sub { $schema->storage->txn_rollback; }; +subtest 'issue() tests' => sub { + plan tests => 6; + + $schema->storage->txn_begin; + + my $library = $builder->build( { source => 'Branch' } ); + my $patron = $builder->build( { source => 'Borrower' } ); + my $item = $builder->build( { source => 'Item' } ); + + my $checkout = Koha::Checkout->new( + { borrowernumber => $patron->{borrowernumber}, + itemnumber => $item->{itemnumber}, + branchcode => $library->{branchcode}, + })->store; + + my $line = Koha::Account::Line->new( + { + borrowernumber => $patron->{borrowernumber}, + itemnumber => $item->{itemnumber}, + issue_id => $checkout->issue_id, + accounttype => "F", + amount => 10, + })->store; + + my $line_issue = $line->issue; + is( ref($line_issue), 'Koha::Checkout', 'Result type is correct' ); + is( $line_issue->issue_id, $checkout->issue_id, 'Koha::Account::Line->issue should return the correct issue'); + + my ( $returned, undef, $old_checkout) = C4::Circulation::AddReturn( $item->{barcode} ,$library->{branchcode} ); + is( $returned, 1, 'The item should have been returned' ); + + my $old_line_issue = $line->issue; + is( ref($old_line_issue), 'Koha::Old::Checkout', 'Result type is correct' ); + is( $old_line_issue->issue_id, $old_checkout->issue_id, 'Koha::Account::Line->issue should return the correct old_issue' ); + + $line->issue_id(undef)->store; + is( $line->issue, undef, 'Koha::Account::Line->issue should return undef if no issue linked' ); + + $schema->storage->txn_rollback; +}; + 1; -- 2.1.4