Bug 30612: Add accountlines method to Koha::Checkout and Koha::Old::Checkout
authorKyle M Hall <kyle@bywatersolutions.com>
Wed, 8 Jun 2022 17:41:56 +0000 (13:41 -0400)
committerTomas Cohen Arazi <tomascohen@theke.io>
Mon, 1 Aug 2022 12:59:05 +0000 (09:59 -0300)
It would be very useful to have an accountlines method on checkouts objects. In particular it would make fees related to a checkout available from the checkout objects in overdue notices.

Test Plan:
1) Apply this patch
2) prove t/db_dependent/Koha/Account/Line.t
3) prove t/db_dependent/Koha/Checkouts.t

Signed-off-by: David Nind <david@davidnind.com>
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Koha/Checkout.pm
Koha/Old/Checkout.pm
t/db_dependent/Koha/Account/Line.t
t/db_dependent/Koha/Checkouts.t

index 82cdfe4..61dc30d 100644 (file)
@@ -79,6 +79,20 @@ sub item {
     return Koha::Item->_new_from_dbic( $item_rs );
 }
 
+=head3 accountlines
+
+my $accountlines = $checkout->accountlines;
+
+Return the checked out accountlines
+
+=cut
+
+sub accountlines {
+    my ( $self ) = @_;
+    my $accountlines_rs = $self->_result->accountlines;
+    return Koha::Account::Lines->_new_from_dbic( $accountlines_rs );
+}
+
 =head3 library
 
 my $library = $checkout->library;
index ab95898..91f7072 100644 (file)
@@ -45,6 +45,20 @@ sub item {
     return Koha::Item->_new_from_dbic( $item_rs );
 }
 
+=head3 accountlines
+
+my $accountlines = $checkout->accountlines;
+
+Return the checked out accountlines
+
+=cut
+
+sub accountlines {
+    my ( $self ) = @_;
+    my $accountlines_rs = $self->_result->accountlines;
+    return Koha::Account::Lines->_new_from_dbic( $accountlines_rs );
+}
+
 =head3 library
 
 my $library = $checkout->library;
index 098d8e8..c2436b7 100755 (executable)
@@ -203,7 +203,7 @@ subtest 'is_credit() and is_debit() tests' => sub {
 
 subtest 'apply() tests' => sub {
 
-    plan tests => 31;
+    plan tests => 32;
 
     $schema->storage->txn_begin;
 
@@ -346,6 +346,9 @@ subtest 'apply() tests' => sub {
         }
     )->store();
 
+    my $a = $checkout->accountlines->next;
+    is( $a->id, $accountline->id, "Koha::Checkout::accountlines returns the related acountline" );
+
     # Enable renewing upon fine payment
     t::lib::Mocks::mock_preference( 'RenewAccruingItemWhenPaid', 1 );
     my $called = 0;
index 9c4b0db..8ca855d 100755 (executable)
@@ -19,7 +19,7 @@
 
 use Modern::Perl;
 
-use Test::More tests => 10;
+use Test::More tests => 11;
 
 use C4::Circulation qw( MarkIssueReturned AddReturn );
 use Koha::Checkouts;
@@ -110,6 +110,39 @@ subtest 'item' => sub {
         'Koha::Checkout->item should return the correct item' );
 };
 
+subtest 'accountlines' => sub {
+    plan tests => 3;
+
+    my $accountline = Koha::Account::Line->new(
+        {
+            issue_id          => $retrieved_checkout_1->id,
+            borrowernumber    => $retrieved_checkout_1->borrowernumber,
+            itemnumber        => $retrieved_checkout_1->itemnumber,
+            branchcode        => $retrieved_checkout_1->branchcode,
+            date              => \'NOW()',
+            debit_type_code   => 'OVERDUE',
+            status            => 'UNRETURNED',
+            interface         => 'cli',
+            amount            => '1',
+            amountoutstanding => '1',
+        }
+    )->store();
+
+    my $accountlines = $retrieved_checkout_1->accountlines;
+    is( ref($accountlines), 'Koha::Account::Lines',
+        'Koha::Checkout->accountlines should return a Koha::Item' );
+
+    my $line = $accountlines->next;
+    is( ref($line), 'Koha::Account::Line',
+        'next returns a Koha::Account::Line' );
+
+    is(
+        $accountline->id,
+        $line->id,
+        'Koha::Checkout->accountlines should return the correct accountlines'
+    );
+};
+
 subtest 'patron' => sub {
     plan tests => 3;
     my $patron = $builder->build_object(