From c37da034c649ac67a2235fd0527f6fef5e26ec5a Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Mon, 10 Feb 2014 14:02:34 +0100 Subject: [PATCH] SL::DB::DeliveryOrder->new_from: Optionen zum Weglassen von Positionen mit Menge 0 --- SL/DB/DeliveryOrder.pm | 22 ++++++++++++++++++++-- SL/DB/Order.pm | 4 ++-- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/SL/DB/DeliveryOrder.pm b/SL/DB/DeliveryOrder.pm index febf5e27e..02d003aab 100644 --- a/SL/DB/DeliveryOrder.pm +++ b/SL/DB/DeliveryOrder.pm @@ -132,7 +132,7 @@ sub new_from { $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 = $_; @@ -146,6 +146,8 @@ sub new_from { } @{ $source->items_sorted }; + @items = grep { $_->qty * 1 } @items if $params{skip_items_zero_qty}; + $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). -=item C +=item C Creates a new C 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. +C<%params> can include the following options: + +=over 2 + +=item C + +If trueish then items with a quantity of 0 are skipped. + +=item C + +An optional hash reference. If it exists then it is passed to C +allowing the caller to set certain attributes for the new delivery +order. + +=back + =item C TODO: Describe sales_order diff --git a/SL/DB/Order.pm b/SL/DB/Order.pm index f037ed16a..a605a3689 100644 --- a/SL/DB/Order.pm +++ b/SL/DB/Order.pm @@ -150,12 +150,12 @@ sub convert_to_invoice { } 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; - ($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); -- 2.20.1