Bug 20562: issue_id is not stored in accountlines for rental fees
authorKyle M Hall <kyle@bywatersolutions.com>
Sun, 8 Apr 2018 07:11:11 +0000 (07:11 +0000)
committerJonathan Druart <jonathan.druart@bugs.koha-community.org>
Wed, 18 Apr 2018 20:20:54 +0000 (17:20 -0300)
Test Plan:
1) Apply this patch
2) Assign a charge to an item type
3) Checkout an item of that type to a patron
4) View the accountlines table for that patron
SELECT * FROM accountlines WHERE accounttype='Rent' and borrowernumber=##;
5) Note there is an issue_id

Or

1) Apply this patch
2) prove t/db_dependent/Circulation/issue.t

Signed-off-by: Mark Tompsett <mtompset@hotmail.com>

Signed-off-by: Josef Moravec <josef.moravec@gmail.com>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>

C4/Circulation.pm
t/db_dependent/Circulation/issue.t

index 98498b8..9471e67 100644 (file)
@@ -1406,7 +1406,7 @@ sub AddIssue {
            # If it costs to borrow this book, charge it to the patron's account.
             my ( $charge, $itemtype ) = GetIssuingCharges( $item->{'itemnumber'}, $borrower->{'borrowernumber'} );
             if ( $charge > 0 ) {
-                AddIssuingCharge( $item->{'itemnumber'}, $borrower->{'borrowernumber'}, $charge );
+                AddIssuingCharge( $item->{'itemnumber'}, $borrower->{'borrowernumber'}, $issue->id, $charge );
                 $item->{'charge'} = $charge;
             }
 
@@ -3165,12 +3165,12 @@ sub _get_discount_from_rule {
 
 =head2 AddIssuingCharge
 
-  &AddIssuingCharge( $itemno, $borrowernumber, $charge )
+  &AddIssuingCharge( $itemno, $borrowernumber, $issue_id, $charge )
 
 =cut
 
 sub AddIssuingCharge {
-    my ( $itemnumber, $borrowernumber, $charge ) = @_;
+    my ( $itemnumber, $borrowernumber, $issue_id, $charge ) = @_;
 
     my $nextaccntno = getnextacctno($borrowernumber);
 
@@ -3181,6 +3181,7 @@ sub AddIssuingCharge {
         {
             borrowernumber    => $borrowernumber,
             itemnumber        => $itemnumber,
+            issue_id          => $issue_id,
             accountno         => $nextaccntno,
             amount            => $charge,
             amountoutstanding => $charge,
index 0986d02..e2cbf9d 100644 (file)
@@ -17,7 +17,7 @@
 
 use Modern::Perl;
 
-use Test::More tests => 31;
+use Test::More tests => 32;
 use DateTime::Duration;
 
 use t::lib::Mocks;
@@ -207,8 +207,10 @@ $sth = $dbh->prepare($query);
 $sth->execute;
 my $countaccount = $sth -> fetchrow_array;
 is ($countaccount,0,"0 accountline exists");
-is( ref( C4::Circulation::AddIssuingCharge( $item_id1, $borrower_id1, 10 ) ),
-    'Koha::Account::Offset', "An issuing charge has been added" );
+my $offset = C4::Circulation::AddIssuingCharge( $item_id1, $borrower_id1, $issue_id1, 10 );
+is( ref( $offset ), 'Koha::Account::Offset', "An issuing charge has been added" );
+my $charge = Koha::Account::Lines->find( $offset->debit_id );
+is( $charge->issue_id, $issue_id1, 'Issue id is set correctly for issuing charge' );
 my $account_id = $dbh->last_insert_id( undef, undef, 'accountlines', undef );
 $sth->execute;
 $countaccount = $sth -> fetchrow_array;