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;
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);
}
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});
}
'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.',
'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.' => '',