$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 = $_;
} @{ $source->items_sorted };
+ @items = grep { $_->qty * 1 } @items if $params{skip_items_zero_qty};
+
$delivery_order->items(\@items);
return ($delivery_order, $custom_shipto);
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
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
}
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);