From b92403aefae50ba6267e1f34f34234925688e78f Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jan=20B=C3=BCren?= Date: Sat, 2 Mar 2019 10:23:16 +0100 Subject: [PATCH] BankTransaction Die richtigen (erwarteten) Parameter von amount an pay_invoice MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Stellt den vorherigen Zustand im Controller wieder her, der über Fallunterschiede vom Invoice-Typ Vorzeichen verschoben hat. Tests laufen damit erstmal durch. Ferner kann und muss es mehr als 2 acc_trans_ids als Rückgabe von pay_invoice geben --- SL/Controller/BankTransaction.pm | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/SL/Controller/BankTransaction.pm b/SL/Controller/BankTransaction.pm index 69bc63114..2e10e4143 100644 --- a/SL/Controller/BankTransaction.pm +++ b/SL/Controller/BankTransaction.pm @@ -633,22 +633,32 @@ sub save_single_bank_transaction { # TODO rewrite this: really booked amount should be a return value of Payment.pm # also this controller shouldnt care about how to calc skonto. we simply delegate the # payment_type to the helper and get the corresponding bank_transaction values back - - my $open_amount = ($payment_type eq 'with_skonto_pt' ? $invoice->amount_less_skonto : $invoice->open_amount); - my $amount_for_booking = abs(($open_amount < $not_assigned_amount) ? $open_amount : $not_assigned_amount); + # hotfix to get the signs right - compare absolute values and later set the signs + # should be better done elsewhere - changing not_assigned_amount to abs feels seriously bogus + + my $open_amount = $payment_type eq 'with_skonto_pt' ? $invoice->amount_less_skonto : $invoice->open_amount; + $open_amount = abs($open_amount); + $not_assigned_amount = abs($not_assigned_amount); + my $amount_for_booking = ($open_amount < $not_assigned_amount) ? $open_amount : $not_assigned_amount; + my $amount_for_payment = $amount_for_booking; + + # get the right direction for the payment bookings (all amounts < 0 are stornos, credit notes or negative ap) + $amount_for_payment *= -1 if $invoice->amount < 0; + # get the right direction for the bank transaction $amount_for_booking *= $sign; + $bank_transaction->invoice_amount($bank_transaction->invoice_amount + $amount_for_booking); # ... and then pay the invoice my @acc_ids = $invoice->pay_invoice(chart_id => $bank_transaction->local_bank_account->chart_id, trans_id => $invoice->id, - amount => ($open_amount < $not_assigned_amount) ? $open_amount : $not_assigned_amount, + amount => $amount_for_payment, payment_type => $payment_type, source => $source, memo => $memo, transdate => $bank_transaction->transdate->to_kivitendo); # ... and record the origin via BankTransactionAccTrans - if (scalar(@acc_ids) != 2) { + if (scalar(@acc_ids) < 2) { return { %data, result => 'error', -- 2.20.1