$args{quodate} = $source->transdate;
}
- my $invoice = $class->new(%args, %params);
+ my $invoice = $class->new(%args, %{ $params{attributes} || {} });
+ my $items = delete($params{items}) || $source->items_sorted;
my @items = map {
my $source_item = $_;
custom_variables => \@custom_variables,
);
- } @{ $source->items_sorted };
+ } @{ $items };
+
+ @items = grep { $_->qty * 1 } @items if $params{skip_items_zero_qty};
$invoice->invoiceitems(\@items);
=over 4
-=item C<new_from $source>
+=item C<new_from $source, %params>
Creates a new C<SL::DB::Invoice> instance and copies as much
information from C<$source> as possible. At the moment only sales
as appropriate, e.g. the C<transdate> field from an order will be
copied into the invoice's C<orddate> field.
+C<%params> can include the following options:
+
+=over 2
+
+=item C<items>
+
+An optional array reference of RDBO instances for the items to use. If
+missing then the method C<items_sorted> will be called on
+C<$source>. This option can be used to override the sorting, to
+exclude certain positions or to add additional ones.
+
+=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
+
Amounts, prices and taxes are not
calculated. L<SL::DB::Helper::PriceTaxCalculator::calculate_prices_and_taxes>
can be used for this.