Bug 32336: (QA follow-up) Use $metadata->schema
[srvgit] / Koha / Account.pm
index 962f6e1..e37e646 100644 (file)
@@ -35,6 +35,7 @@ use Koha::Account::Offsets;
 use Koha::Account::DebitTypes;
 use Koha::Exceptions;
 use Koha::Exceptions::Account;
+use Koha::Plugins;
 
 =head1 NAME
 
@@ -110,7 +111,7 @@ sub pay {
     }
 
     my $patron = Koha::Patrons->find( $self->{patron_id} );
-    my @account_offsets = $payment->debit_offsets;
+    my @account_offsets = $payment->credit_offsets({ type => 'APPLY' })->as_list;
     if ( C4::Context->preference('UseEmailReceipts') ) {
         if (
             my $letter = C4::Letters::GetPreparedLetter(
@@ -140,7 +141,7 @@ sub pay {
     }
 
     my $renew_outcomes = [];
-    for my $message ( @{$payment->messages} ) {
+    for my $message ( @{$payment->object_messages} ) {
         push @{$renew_outcomes}, $message->payload;
     }
 
@@ -173,6 +174,7 @@ $credit_type can be any of:
   - 'OVERPAYMENT'
   - 'PAYMENT'
   - 'WRITEOFF'
+  - 'PROCESSING_FOUND'
 
 =cut
 
@@ -209,7 +211,7 @@ sub add_credit {
     Koha::Exceptions::Account::RegisterRequired->throw()
       if ( C4::Context->preference("UseCashRegisters")
         && defined($payment_type)
-        && ( $payment_type eq 'CASH' )
+        && ( $payment_type eq 'CASH' || $payment_type eq 'SIP00' )
         && !defined($cash_register) );
 
     my $line;
@@ -242,7 +244,7 @@ sub add_credit {
                     {
                         credit_id => $line->id,
                         type      => 'CREATE',
-                        amount    => $amount
+                        amount    => $amount * -1
                     }
                 )->store();
 
@@ -255,6 +257,17 @@ sub add_credit {
                     }
                 ) if grep { $credit_type eq $_ } ( 'PAYMENT', 'WRITEOFF' );
 
+                Koha::Plugins->call(
+                    'after_account_action',
+                    {
+                        action  => "add_credit",
+                        payload => {
+                            type => lc($credit_type),
+                            line => $line->get_from_storage, #TODO Seems unneeded
+                        }
+                    }
+                );
+
                 if ( C4::Context->preference("FinesLog") ) {
                     logaction(
                         "FINES", 'CREATE',
@@ -338,7 +351,7 @@ sub payin_amount {
     Koha::Exceptions::Account::RegisterRequired->throw()
       if ( C4::Context->preference("UseCashRegisters")
         && defined( $params->{payment_type} )
-        && ( $params->{payment_type} eq 'CASH' )
+        && ( $params->{payment_type} eq 'CASH' || $params->{payment_type} eq 'SIP00' )
         && !defined($params->{cash_register}) );
 
     # amount should always be passed as a positive value
@@ -436,7 +449,7 @@ sub add_debit {
     Koha::Exceptions::Account::RegisterRequired->throw()
       if ( C4::Context->preference("UseCashRegisters")
         && defined( $params->{transaction_type} )
-        && ( $params->{transaction_type} eq 'CASH' )
+        && ( $params->{transaction_type} eq 'CASH' || $params->{payment_type} eq 'SIP00' )
         && !defined( $params->{cash_register} ) );
 
     # amount should always be a positive value
@@ -570,7 +583,7 @@ sub payout_amount {
     # Check for mandatory register
     Koha::Exceptions::Account::RegisterRequired->throw()
       if ( C4::Context->preference("UseCashRegisters")
-        && ( $params->{payout_type} eq 'CASH' )
+        && ( $params->{payout_type} eq 'CASH' || $params->{payout_type} eq 'SIP00' )
         && !defined($params->{cash_register}) );
 
     # Amount should always be passed as a positive value
@@ -606,7 +619,7 @@ sub payout_amount {
                     type              => 'PAYOUT',
                     transaction_type  => $params->{payout_type},
                     amountoutstanding => $params->{amount},
-                    manager_id        => $params->{staff_id},
+                    user_id           => $params->{staff_id},
                     interface         => $params->{interface},
                     branchcode        => $params->{branch},
                     cash_register     => $params->{cash_register}
@@ -647,8 +660,7 @@ my $lines = Koha::Account->new({ patron_id => $patron_id })->outstanding_debits;
 
 It returns the debit lines with outstanding amounts for the patron.
 
-In scalar context, it returns a Koha::Account::Lines iterator. In list context, it will
-return a list of Koha::Account::Line objects.
+It returns a Koha::Account::Lines iterator.
 
 =cut
 
@@ -669,8 +681,7 @@ my $lines = Koha::Account->new({ patron_id => $patron_id })->outstanding_credits
 
 It returns the credit lines with outstanding amounts for the patron.
 
-In scalar context, it returns a Koha::Account::Lines iterator. In list context, it will
-return a list of Koha::Account::Line objects.
+It returns a Koha::Account::Lines iterator.
 
 =cut