From 2c5a1cefe12c923fce743e46d42702570978edfb Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jan=20B=C3=BCren?= Date: Thu, 18 May 2017 10:08:02 +0200 Subject: [PATCH] =?utf8?q?behebt=20#242=20Negative=20Verkaufsrechnungen=20?= =?utf8?q?mit=20Bankbewegung=20verkn=C3=BCpfen?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 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. --- SL/Controller/BankTransaction.pm | 3 ++- t/bank/bank_transactions.t | 38 +++++++++++++++++++++++++++++++- 2 files changed, 39 insertions(+), 2 deletions(-) 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; -- 2.20.1