]> wagnertech.de Git - mfinanz.git/blobdiff - SL/Controller/Order.pm
SL/Dev/CustomerVendor um create_vendor erweitert
[mfinanz.git] / SL / Controller / Order.pm
index 741476603c49c3cfdd064537049b82c40fec424d..78e9e5436041a78664c7ae4040c84820b9a3f54f 100644 (file)
@@ -425,6 +425,10 @@ sub action_add_item {
                    description => $assortment_item->part->description,
                  };
       my $item = _new_item($self->order, $attr);
                    description => $assortment_item->part->description,
                  };
       my $item = _new_item($self->order, $attr);
+
+      # set discount to 100% if item isn't supposed to be charged, overwriting any customer discount
+      $item->discount(1) unless $assortment_item->charge;
+
       $self->order->add_items( $item );
       $self->_recalc();
       my $item_id = join('_', 'new', Time::HiRes::gettimeofday(), int rand 1000000000000);
       $self->order->add_items( $item );
       $self->_recalc();
       my $item_id = join('_', 'new', Time::HiRes::gettimeofday(), int rand 1000000000000);
@@ -486,7 +490,22 @@ sub action_add_multi_items {
 
   my @items;
   foreach my $attr (@form_attr) {
 
   my @items;
   foreach my $attr (@form_attr) {
-    push @items, _new_item($self->order, $attr);
+    my $item = _new_item($self->order, $attr);
+    push @items, $item;
+    if ( $item->part->is_assortment ) {
+      foreach my $assortment_item ( @{$item->part->assortment_items} ) {
+        my $attr = { parts_id => $assortment_item->parts_id,
+                     qty      => $assortment_item->qty * $item->qty, # TODO $form_attr->{unit}
+                     unit     => $assortment_item->unit,
+                     description => $assortment_item->part->description,
+                   };
+        my $item = _new_item($self->order, $attr);
+
+        # set discount to 100% if item isn't supposed to be charged, overwriting any customer discount
+        $item->discount(1) unless $assortment_item->charge;
+        push @items, $assortment_item;
+      }
+    }
   }
   $self->order->add_items(@items);
 
   }
   $self->order->add_items(@items);
 
@@ -829,7 +848,11 @@ sub _new_item {
   $item->unit($part->unit) if !$item->unit;
 
   my $price_src;
   $item->unit($part->unit) if !$item->unit;
 
   my $price_src;
-  if ($item->sellprice) {
+  if ( $part->is_assortment ) {
+    # add assortment items with price 0, as the components carry the price
+    $price_src = $price_source->price_from_source("");
+    $price_src->price(0);
+  } elsif ($item->sellprice) {
     $price_src = $price_source->price_from_source("");
     $price_src->price($item->sellprice);
   } else {
     $price_src = $price_source->price_from_source("");
     $price_src->price($item->sellprice);
   } else {