Bug 15909 - Remove the use of makepartialpayment
authorKyle M Hall <kyle@bywatersolutions.com>
Wed, 24 Feb 2016 16:34:23 +0000 (16:34 +0000)
committerKyle M Hall <kyle@bywatersolutions.com>
Wed, 11 Jan 2017 14:41:04 +0000 (14:41 +0000)
Test Plan:
1) Apply this patch
2) prove t/db_dependent/Accounts.t
3) Test fine payment via the "Pay" button,
   but make the payment for less then the full amount

Signed-off-by: Laura Slavin <lslavin@hmcpl.org>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
C4/Accounts.pm
members/paycollect.pl
t/db_dependent/Accounts.t

index 682e59b..14487a4 100644 (file)
@@ -44,7 +44,6 @@ BEGIN {
                &getrefunds
                &chargelostitem
                &ReversePayment
-        &makepartialpayment
         &recordpayment_selectaccts
         &WriteOffFee
         &purge_zero_balance_fees
@@ -420,28 +419,6 @@ sub recordpayment_selectaccts {
       );
 }
 
-# makepayment needs to be fixed to handle partials till then this separate subroutine
-# fills in
-sub makepartialpayment {
-    my ( $accountlines_id, $borrowernumber, $accountno, $amount, $user, $branch, $payment_note ) = @_;
-
-    my $line = Koha::Account::Lines->find( $accountlines_id );
-
-    return Koha::Account->new(
-        {
-            patron_id => $borrowernumber,
-        }
-      )->pay(
-        {
-            amount => $amount,
-            lines  => [ $line ],
-            note   => $payment_note,
-            library_id => $branch,
-        }
-      );
-
-}
-
 =head2 WriteOffFee
 
   WriteOffFee( $borrowernumber, $accountline_id, $itemnum, $accounttype, $amount, $branch, $payment_note );
index b341e8c..be920e1 100755 (executable)
@@ -121,9 +121,18 @@ if ( $total_paid and $total_paid ne '0.00' ) {
                         note       => $payment_note
                     }
                 );
-            } else {
-                makepartialpayment( $accountlines_id, $borrowernumber, $accountno, $total_paid,
-                    $user, $branch, $payment_note );
+            }
+            else {
+                my $line = Koha::Account::Lines->find($accountlines_id);
+
+                Koha::Account->new( { patron_id => $borrowernumber, } )->pay(
+                    {
+                        amount     => $total_paid,
+                        lines      => [$line],
+                        note       => $payment_note,
+                        library_id => $branch,
+                    }
+                );
             }
             print $input->redirect(
                 "/cgi-bin/koha/members/pay.pl?borrowernumber=$borrowernumber");
index 6d58726..230a1d7 100644 (file)
@@ -46,7 +46,6 @@ can_ok( 'C4::Accounts',
         getrefunds
         ReversePayment
         recordpayment_selectaccts
-        makepartialpayment
         WriteOffFee
         purge_zero_balance_fees )
 );
@@ -357,7 +356,7 @@ subtest "makepayment() tests" => sub {
     }
 };
 
-subtest "makepartialpayment() tests" => sub {
+subtest "Even more Koha::Account::pay tests" => sub {
 
     plan tests => 6;
 
@@ -385,13 +384,10 @@ subtest "makepartialpayment() tests" => sub {
 
     is( $rs->count(), 1, 'Accountline created' );
 
+    my $account = Koha::Account->new( { patron_id => $borrowernumber } );
+    my $line = Koha::Account::Lines->find( $accountline->{ accountlines_id } );
     # make the full payment
-    makepartialpayment(
-        $accountline->{ accountlines_id }, $borrowernumber,
-        $accountline->{ accountno },       $partialamount,
-        $borrowernumber, $branch, 'A payment note' );
-
-    # TODO: someone should write actual tests for makepartialpayment()
+    $account->pay({ lines => [$line], amount => $partialamount, library_id => $branch, note => 'A payment note' });
 
     my $stat = $schema->resultset('Statistic')->search({
         branch  => $branch,