From 23758ec05dbf09a977c9ad5e7880cde6c74cd78c Mon Sep 17 00:00:00 2001 From: =?utf8?q?Bernd=20Ble=C3=9Fmann?= Date: Fri, 20 Nov 2020 17:02:32 +0100 Subject: [PATCH] Massenerstellen von RG aus LS: geschlossene LS nicht (erneut) verarbeiten MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Geschlossene Lieferscheine werden nicht zum Umwandeln in der Liste angezeigt, das war auch bisher so. Aber weenn man nach dem Erzeuigen der Rechnungen von der Folgeseite den Browser-Zurück-Knopf drückt, konnten aus den selben Lieferscheine durchaus nochmal Rechnungen erzeugt werden. Das wird nun abgefangen. --- SL/Controller/MassInvoiceCreatePrint.pm | 27 ++++++++++++++++++++++--- locale/de/all | 1 + locale/en/all | 1 + 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/SL/Controller/MassInvoiceCreatePrint.pm b/SL/Controller/MassInvoiceCreatePrint.pm index c85d0e638..acc300e0a 100644 --- a/SL/Controller/MassInvoiceCreatePrint.pm +++ b/SL/Controller/MassInvoiceCreatePrint.pm @@ -58,13 +58,23 @@ sub action_create_invoices { my $db = SL::DB::Invoice->new->db; my @invoices; + my @already_closed_delivery_orders; if (!$db->with_transaction(sub { foreach my $id (@sales_delivery_order_ids) { my $delivery_order = SL::DB::DeliveryOrder->new(id => $id)->load; - my $invoice = $delivery_order->convert_to_invoice() || die $db->error; - push @invoices, $invoice; + # Only process open delivery orders. In this list should only be open + # delivery orders, but if the user clicked browser back, a new creation + # of invoices for delivery orders which are closed now can be triggered. + # Prevent this. + if ($delivery_order->closed) { + push @already_closed_delivery_orders, $delivery_order; + + } else { + my $invoice = $delivery_order->convert_to_invoice() || die $db->error; + push @invoices, $invoice; + } } 1; @@ -76,7 +86,13 @@ sub action_create_invoices { my $key = sprintf('%d-%d', Time::HiRes::gettimeofday()); $::auth->set_session_value("MassInvoiceCreatePrint::ids-${key}" => [ map { $_->id } @invoices ]); - flash_later('info', t8('The invoices have been created. They\'re pre-selected below.')); + if (@already_closed_delivery_orders) { + my $dos_list = join ' ', map { $_->donumber } @already_closed_delivery_orders; + flash_later('error', t8('The following delivery orders could not be processed because they are already closed: #1', $dos_list)); + } + + flash_later('info', t8('The invoices have been created. They\'re pre-selected below.')) if @invoices; + $self->redirect_to(action => 'list_invoices', ids => $key); } @@ -89,6 +105,11 @@ sub action_list_invoices { if ($::form->{ids}) { my $key = 'MassInvoiceCreatePrint::ids-' . $::form->{ids}; $self->invoice_ids($::auth->get_session_value($key) || []); + + # Prevent models->get to retrieve any invoices if session key is there + # but no ids are given. + $self->invoice_ids([0]) if !@{$self->invoice_ids}; + $self->invoice_models->add_additional_url_params(ids => $::form->{ids}); } diff --git a/locale/de/all b/locale/de/all index 6ebd46cc4..b0954aa52 100755 --- a/locale/de/all +++ b/locale/de/all @@ -3377,6 +3377,7 @@ $self->{texts} = { 'The first reason is that kivitendo contained a bug which resulted in the wrong taxkeys being recorded for transactions in which two entries are posted for the same chart with different taxkeys.' => 'Der erste Grund war ein Fehler in kivitendo, der dazu führte, dass bei einer Transaktion, bei der zwei Buchungen mit unterschiedlichen Steuerschlüsseln auf dasselbe Konto durchgeführt wurden, die falschen Steuerschlüssel gespeichert wurden.', 'The follow-up date is missing.' => 'Das Wiedervorlagedatum fehlt.', 'The following currencies have been used, but they are not defined:' => 'Die folgenden Währungen wurden benutzt, sind aber nicht ordnungsgemäß in der Datenbank eingetragen:', + 'The following delivery orders could not be processed because they are already closed: #1' => 'Die folgenden Lieferscheine konnten nicht verarbeitet werden, da sie bereits geschlossen sind: #1', 'The following drafts have been saved and can be loaded.' => 'Die folgenden Entwürfe wurden gespeichert und können geladen werden.', 'The following groups are valid for this client' => 'Die folgenden Gruppen sind für diesen Mandanten gültig', 'The following is only a preview.' => 'Das Folgende ist nur eine Vorschau.', diff --git a/locale/en/all b/locale/en/all index 1a9d6de03..98641e2da 100644 --- a/locale/en/all +++ b/locale/en/all @@ -3376,6 +3376,7 @@ $self->{texts} = { 'The first reason is that kivitendo contained a bug which resulted in the wrong taxkeys being recorded for transactions in which two entries are posted for the same chart with different taxkeys.' => '', 'The follow-up date is missing.' => '', 'The following currencies have been used, but they are not defined:' => '', + 'The following delivery orders could not be processed because they are already closed: #1' => '', 'The following drafts have been saved and can be loaded.' => '', 'The following groups are valid for this client' => '', 'The following is only a preview.' => '', -- 2.20.1