Bug 19489: Koha::Account::Line->issue method and Unit test
authorNazlı Çetin <nazli@devinim.com.tr>
Mon, 18 Feb 2019 09:44:24 +0000 (09:44 +0000)
committerNick Clemens <nick@bywatersolutions.com>
Mon, 11 Mar 2019 12:45:58 +0000 (12:45 +0000)
Signed-off-by: Josef Moravec <josef.moravec@gmail.com>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>

Koha/Account/Line.pm
t/db_dependent/Koha/Account/Lines.t

index a93cb81..d035e5c 100644 (file)
@@ -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();
index ec0743f..6639d33 100755 (executable)
@@ -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;