Nicht-editierbare CVars bei "als neu speichern/verwenden" richtig setzen.
[kivitendo-erp.git] / SL / IR.pm
index 7a7f57c..a87fca3 100644 (file)
--- a/SL/IR.pm
+++ b/SL/IR.pm
@@ -369,6 +369,12 @@ sub post_invoice {
 
     next if $payments_only;
 
+    CVar->get_non_editable_ic_cvars(form               => $form,
+                                    dbh                => $dbh,
+                                    row                => $i, 
+                                    sub_module         => 'invoice',
+                                    may_converted_from => ['delivery_order_items', 'orderitems', 'invoice']);
+
     if (!$form->{"invoice_id_$i"}) {
       # there is no persistent id, therefore create one with all necessary constraints
       my $q_invoice_id = qq|SELECT nextval('invoiceid')|;
@@ -410,9 +416,10 @@ SQL
                                 name_prefix  => 'ic_',
                                 name_postfix => "_$i",
                                 dbh          => $dbh);
+
     # link previous items with invoice items See IS.pm (no credit note -> no invoice item)
     foreach (qw(delivery_order_items orderitems)) {
-      if ($form->{"converted_from_${_}_id_$i"}) {
+      if (!$form->{useasnew} && $form->{"converted_from_${_}_id_$i"}) {
         RecordLinks->create_links('dbh'        => $dbh,
                                   'mode'       => 'ids',
                                   'from_table' => $_,
@@ -420,8 +427,8 @@ SQL
                                   'to_table'   => 'invoice',
                                   'to_id'      => $form->{"invoice_id_$i"},
         );
-        delete $form->{"converted_from_${_}_id_$i"};
       }
+      delete $form->{"converted_from_${_}_id_$i"};
     }
   }
 
@@ -1640,5 +1647,4 @@ sub get_duedate {
   return $duedate;
 }
 
-
 1;