From 3d1f04b2699737ddd2b2ea5a374cc343f46c2380 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Mon, 16 Apr 2018 13:48:54 -0300 Subject: [PATCH] Bug 20562: Pass the Koha::Checkout object to AddIssuingCharge We do not need to pass all those parameters, just the checkout object is enough. Signed-off-by: Josef Moravec Signed-off-by: Jonathan Druart --- C4/Circulation.pm | 16 +++++++++------- t/db_dependent/Circulation/issue.t | 7 ++++--- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/C4/Circulation.pm b/C4/Circulation.pm index 9471e67546..1f1a431c7f 100644 --- a/C4/Circulation.pm +++ b/C4/Circulation.pm @@ -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, diff --git a/t/db_dependent/Circulation/issue.t b/t/db_dependent/Circulation/issue.t index e2cbf9d7d3..68160dd90b 100644 --- a/t/db_dependent/Circulation/issue.t +++ b/t/db_dependent/Circulation/issue.t @@ -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' ); -- 2.39.5