SL::DB::DeliveryOrder->new_from: Optionen zum Weglassen von Positionen mit Menge 0
authorMoritz Bunkus <m.bunkus@linet-services.de>
Mon, 10 Feb 2014 13:02:34 +0000 (14:02 +0100)
committerMoritz Bunkus <m.bunkus@linet-services.de>
Mon, 24 Feb 2014 13:40:02 +0000 (14:40 +0100)
SL/DB/DeliveryOrder.pm
SL/DB/Order.pm

index febf5e2..02d003a 100644 (file)
@@ -132,7 +132,7 @@ sub new_from {
     $args{shipto_id} = $source->shipto_id;
   }
 
     $args{shipto_id} = $source->shipto_id;
   }
 
-  my $delivery_order = $class->new(%args, %params);
+  my $delivery_order = $class->new(%args, %{ $params{attributes} || {} });
 
   my @items = map {
     my $source_item      = $_;
 
   my @items = map {
     my $source_item      = $_;
@@ -146,6 +146,8 @@ sub new_from {
 
   } @{ $source->items_sorted };
 
 
   } @{ $source->items_sorted };
 
+  @items = grep { $_->qty * 1 } @items if $params{skip_items_zero_qty};
+
   $delivery_order->items(\@items);
 
   return ($delivery_order, $custom_shipto);
   $delivery_order->items(\@items);
 
   return ($delivery_order, $custom_shipto);
@@ -186,7 +188,7 @@ sales/purchase models.
 Returns the delivery order items sorted by their ID (same order they
 appear in the frontend delivery order masks).
 
 Returns the delivery order items sorted by their ID (same order they
 appear in the frontend delivery order masks).
 
-=item C<new_from $source>
+=item C<new_from $source, %params>
 
 Creates a new C<SL::DB::DeliveryOrder> instance and copies as much
 information from C<$source> as possible. At the moment only instances
 
 Creates a new C<SL::DB::DeliveryOrder> instance and copies as much
 information from C<$source> as possible. At the moment only instances
@@ -209,6 +211,22 @@ and returned.
 
 The objects returned are not saved.
 
 
 The objects returned are not saved.
 
+C<%params> can include the following options:
+
+=over 2
+
+=item C<skip_items_zero_qty>
+
+If trueish then items with a quantity of 0 are skipped.
+
+=item C<attributes>
+
+An optional hash reference. If it exists then it is passed to C<new>
+allowing the caller to set certain attributes for the new delivery
+order.
+
+=back
+
 =item C<sales_order>
 
 TODO: Describe sales_order
 =item C<sales_order>
 
 TODO: Describe sales_order
index f037ed1..a605a36 100644 (file)
@@ -150,12 +150,12 @@ sub convert_to_invoice {
 }
 
 sub convert_to_delivery_order {
 }
 
 sub convert_to_delivery_order {
-  my ($self, %params) = @_;
+  my ($self, @args) = @_;
 
   my ($delivery_order, $custom_shipto);
   if (!$self->db->with_transaction(sub {
     require SL::DB::DeliveryOrder;
 
   my ($delivery_order, $custom_shipto);
   if (!$self->db->with_transaction(sub {
     require SL::DB::DeliveryOrder;
-    ($delivery_order, $custom_shipto) = SL::DB::DeliveryOrder->new_from($self, %params);
+    ($delivery_order, $custom_shipto) = SL::DB::DeliveryOrder->new_from($self, @args);
     $delivery_order->save;
     $custom_shipto->save if $custom_shipto;
     $self->link_to_record($delivery_order);
     $delivery_order->save;
     $custom_shipto->save if $custom_shipto;
     $self->link_to_record($delivery_order);