Bug 27636: (QA follow-up) Restore force AutoReconcile
authorMartin Renvoize <martin.renvoize@ptfs-europe.com>
Wed, 28 Apr 2021 13:36:27 +0000 (14:36 +0100)
committerJonathan Druart <jonathan.druart@bugs.koha-community.org>
Fri, 30 Apr 2021 15:07:31 +0000 (17:07 +0200)
This patch restores the behaviour ->pay always acting as though
`AccountAutoReconcile` was enabled.

Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Koha/Account.pm

index 16bff39..bd4af13 100644 (file)
@@ -86,7 +86,6 @@ sub pay {
 
     my $userenv = C4::Context->userenv;
 
-
     my $manager_id = $userenv ? $userenv->{number} : undef;
     my $interface = $params ? ( $params->{interface} || C4::Context->interface ) : C4::Context->interface;
     my $payment = $self->payin_amount(
@@ -105,6 +104,14 @@ sub pay {
         }
     );
 
+    # NOTE: Pay historically always applied as much credit as it could to all
+    # existing outstanding debits, whether passed specific debits or otherwise.
+    if ( $payment->amountoutstanding ) {
+        $payment =
+          $payment->apply(
+            { debits => [ $self->outstanding_debits->as_list ] } );
+    }
+
     my $patron = Koha::Patrons->find( $self->{patron_id} );
     my @account_offsets = $payment->debit_offsets;
     if ( C4::Context->preference('UseEmailReceipts') ) {