PriceSource: Featureabdeckung
[kivitendo-erp.git] / bin / mozilla / oe.pl
index 50e6b35..1460630 100644 (file)
@@ -678,6 +678,15 @@ sub update {
         if ($sellprice) {
           $form->{"sellprice_$i"} = $sellprice;
         } else {
+          my $record       = _make_record();
+          my $price_source = SL::PriceSource->new(record_item => $record->items->[$i-1], record => $record);
+          my $best_price   = $price_source->best_price;
+
+          if ($best_price) {
+            $::form->{"sellprice_$i"}           = $best_price->price;
+            $::form->{"active_price_source_$i"} = $best_price->source;
+          }
+
           $form->{"sellprice_$i"} *= (1 - $form->{tradediscount});
           $form->{"sellprice_$i"} /= $exchangerate;   # if there is an exchange rate adjust sellprice
         }
@@ -692,12 +701,6 @@ sub update {
         $form->{"sellprice_$i"} = $form->format_amount(\%myconfig, $form->{"sellprice_$i"}, $decimalplaces);
         $form->{"lastcost_$i"}  = $form->format_amount(\%myconfig, $form->{"lastcost_$i"}, $decimalplaces);
         $form->{"qty_$i"}       = $form->format_amount(\%myconfig, $form->{"qty_$i"}, $dec_qty);
-
-        # get pricegroups for parts
-        IS->get_pricegroups_for_parts(\%myconfig, \%$form);
-
-        # build up html code for prices_$i
-        &set_pricegroup($i);
       }
 
       display_form();
@@ -1344,9 +1347,14 @@ sub delete {
   if (OE->delete(\%myconfig, \%$form)){
     # saving the history
     if(!exists $form->{addition}) {
-      $form->{snumbers} = qq|ordnumber_| . $form->{ordnumber};
-      $form->{addition} = "DELETED";
-      $form->save_history;
+      if ( $form->{formname} eq 'sales_quotation' or  $form->{formname} eq 'request_quotation' ) {
+          $form->{snumbers} = qq|quonumber_| . $form->{quonumber};
+      } elsif ( $form->{formname} eq 'sales_order' or $form->{formname} eq 'purchase_order') {
+          $form->{snumbers} = qq|ordnumber_| . $form->{ordnumber};
+      };
+        $form->{what_done} = $form->{formname};
+        $form->{addition} = "DELETED";
+        $form->save_history;
     }
     # /saving the history
     $form->info($msg);
@@ -1505,10 +1513,6 @@ sub invoice {
       $form->format_amount(\%myconfig, $form->{"qty_$i"}, $dec_qty);
   }
 
-  #  show pricegroup in newly loaded invoice when creating invoice from quotation/order
-  IS->get_pricegroups_for_parts(\%myconfig, \%$form);
-  set_pricegroup($_) for 1 .. $form->{rowcount};
-
   &display_form;
 
   $main::lxdebug->leave_sub();
@@ -1811,6 +1815,7 @@ sub poso {
 
   # reset
   map { delete $form->{$_} } qw(id subject message cc bcc printed emailed queued customer vendor creditlimit creditremaining discount tradediscount oldinvtotal delivered ordnumber);
+  delete $form->{"orderitems_id_$_"} for 1 .. $form->{"rowcount"};  # always reset orderitems_id
 
   # if purchase_order was generated from sales_order, use  lastcost_$i as sellprice_$i
   # also reset discounts
@@ -1818,7 +1823,6 @@ sub poso {
     for my $i (1 .. $form->{rowcount}) {
       $form->{"sellprice_${i}"} = $form->{"lastcost_${i}"};
       $form->{"discount_${i}"}  = 0;
-      delete $form->{"orderitems_id_$_"};
     };
   };
 
@@ -2113,3 +2117,4 @@ sub dispatcher {
 
   $::form->error($::locale->text('No action defined.'));
 }
+