Bug 20562: Pass the Koha::Checkout object to AddIssuingCharge
authorJonathan Druart <jonathan.druart@bugs.koha-community.org>
Mon, 16 Apr 2018 16:48:54 +0000 (13:48 -0300)
committerJonathan Druart <jonathan.druart@bugs.koha-community.org>
Wed, 18 Apr 2018 20:20:54 +0000 (17:20 -0300)
We do not need to pass all those parameters, just the checkout object is
enough.

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 9471e67..1f1a431 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'}, $issue->id, $charge );
+                AddIssuingCharge( $issue, $charge );
                 $item->{'charge'} = $charge;
             }
 
@@ -3165,23 +3165,25 @@ sub _get_discount_from_rule {
 
 =head2 AddIssuingCharge
 
-  &AddIssuingCharge( $itemno, $borrowernumber, $issue_id, $charge )
+  &AddIssuingCharge( $checkout, $charge )
 
 =cut
 
 sub AddIssuingCharge {
-    my ( $itemnumber, $borrowernumber, $issue_id, $charge ) = @_;
+    my ( $checkout, $charge ) = @_;
 
-    my $nextaccntno = getnextacctno($borrowernumber);
+    # FIXME What if checkout does not exist?
+
+    my $nextaccntno = getnextacctno($checkout->borrowernumber);
 
     my $manager_id  = 0;
     $manager_id = C4::Context->userenv->{'number'} if C4::Context->userenv;
 
     my $accountline = Koha::Account::Line->new(
         {
-            borrowernumber    => $borrowernumber,
-            itemnumber        => $itemnumber,
-            issue_id          => $issue_id,
+            borrowernumber    => $checkout->borrowernumber,
+            itemnumber        => $checkout->itemnumber,
+            issue_id          => $checkout->issue_id,
             accountno         => $nextaccntno,
             amount            => $charge,
             amountoutstanding => $charge,
index e2cbf9d..68160dd 100644 (file)
@@ -29,6 +29,7 @@ use C4::Context;
 use C4::Items;
 use C4::Members;
 use C4::Reserves;
+use Koha::Checkouts;
 use Koha::Database;
 use Koha::DateUtils;
 use Koha::Holds;
@@ -191,11 +192,10 @@ like(
     qr/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}/,
     "Koha::Schema::Result::Issue->date_due() returns a date"
 );
-my $issue_id1 = $dbh->last_insert_id( undef, undef, 'issues', undef );
+my $issue_id1 = $issue1->issue_id;
 
 my $issue2 = C4::Circulation::AddIssue( $borrower_1, 'nonexistent_barcode' );
 is( $issue2, undef, "AddIssue returns undef if no datedue is specified" );
-my $issue_id2 = $dbh->last_insert_id( undef, undef, 'issues', undef );
 
 $sth->execute;
 $countissue = $sth -> fetchrow_array;
@@ -207,7 +207,8 @@ $sth = $dbh->prepare($query);
 $sth->execute;
 my $countaccount = $sth -> fetchrow_array;
 is ($countaccount,0,"0 accountline exists");
-my $offset = C4::Circulation::AddIssuingCharge( $item_id1, $borrower_id1, $issue_id1, 10 );
+my $checkout = Koha::Checkouts->find( $issue_id1 );
+my $offset = C4::Circulation::AddIssuingCharge( $checkout, 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' );