From: Jan Büren Date: Thu, 18 May 2017 08:08:02 +0000 (+0200) Subject: behebt #242 Negative Verkaufsrechnungen mit Bankbewegung verknüpfen X-Git-Tag: release-3.5.4~1088 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=2c5a1cefe12c923fce743e46d42702570978edfb;p=kivitendo-erp.git behebt #242 Negative Verkaufsrechnungen mit Bankbewegung verknüpfen Es ist möglich negative Verkaufsrechnungen zu erstellen. Bei Bankbewegung verbuchen, ist dieser Fall nicht berücksichtigt. Entsprechend den Fall berücksichtigt. Den Test erweitert und Hinweise im Ticket erstellt. --- diff --git a/SL/Controller/BankTransaction.pm b/SL/Controller/BankTransaction.pm index f93bfd79e..52d43e1d6 100644 --- a/SL/Controller/BankTransaction.pm +++ b/SL/Controller/BankTransaction.pm @@ -669,7 +669,8 @@ sub save_single_bank_transaction { } else { # use the whole amount of the bank transaction for the invoice, overpay the invoice if necessary - if ( $invoice->is_sales && $invoice->invoice_type eq 'credit_note' ) { + # this catches credit_notes and negative sales invoices + if ( $invoice->is_sales && $invoice->amount < 0 ) { # $invoice->open_amount is negative for credit_notes # $bank_transaction->amount is negative for outgoing transactions # so $amount_of_transaction is negative but needs positive diff --git a/t/bank/bank_transactions.t b/t/bank/bank_transactions.t index 687a64636..fd9757518 100644 --- a/t/bank/bank_transactions.t +++ b/t/bank/bank_transactions.t @@ -1,4 +1,4 @@ -use Test::More tests => 100; +use Test::More tests => 105; use strict; @@ -77,6 +77,7 @@ test_ap_transaction(); test_neg_ap_transaction(); test_ap_payment_transaction(); test_ap_payment_part_transaction(); +test_neg_sales_invoice(); # remove all created data at end of test clear_up(); @@ -620,4 +621,39 @@ sub test_ap_payment_part_transaction { return $invoice; }; +sub test_neg_sales_invoice { + + my $testname = 'test_neg_sales_invoice'; + + my $part1 = SL::Dev::Part::create_part( partnumber => 'Funkenhaube öhm')->save; + my $part2 = SL::Dev::Part::create_service(partnumber => 'Service-Pauschale Pasch!')->save; + + my $neg_sales_inv = SL::Dev::Record::create_sales_invoice( + invnumber => '20172201', + customer => $customer, + taxincluded => 0, + invoiceitems => [ SL::Dev::Record::create_invoice_item(part => $part1, qty => 3, sellprice => 70), + SL::Dev::Record::create_invoice_item(part => $part2, qty => 10, sellprice => -50), + ] + ); + my $bt = SL::Dev::Payment::create_bank_transaction(record => $neg_sales_inv, + amount => $neg_sales_inv->amount, + bank_chart_id => $bank->id, + transdate => DateTime->today, + ); + $::form->{invoice_ids} = { + $bt->id => [ $neg_sales_inv->id ] + }; + + save_btcontroller_to_string(); + + $neg_sales_inv->load; + $bt->load; + is($neg_sales_inv->amount , '-345.10000', "$testname: amount ok"); + is($neg_sales_inv->netamount, '-290.00000', "$testname: netamount ok"); + is($neg_sales_inv->paid , '-345.10000', "$testname: paid ok"); + is($bt->amount , '-345.10000', "$testname: bt amount ok"); + is($bt->invoice_amount , '-345.10000', "$testname: bt invoice_amount ok"); +} + 1;