# Custom shipto addresses (the ones specific to the sales/purchase
# record and not to the customer/vendor) are only linked from
- # shipto -> delivery_orders. Meaning delivery_orders.shipto_id
- # will not be filled in that case. Therefore we have to return the
- # new shipto object as a separate object so that the caller can
- # save it, too.
- my $custom_shipto;
+ # shipto → delivery_orders. Meaning delivery_orders.shipto_id
+ # will not be filled in that case.
if (!$source->shipto_id && $source->id) {
- $custom_shipto = $source->custom_shipto->clone($class) if $source->can('custom_shipto') && $source->custom_shipto;
+ $args{custom_shipto} = $source->custom_shipto->clone($class) if $source->can('custom_shipto') && $source->custom_shipto;
} else {
$args{shipto_id} = $source->shipto_id;
$delivery_order->items(\@items);
- return ($delivery_order, $custom_shipto);
+ return $delivery_order;
}
sub customervendor {
The conversion copies order items into delivery order items. Dates are copied
as appropriate, e.g. the C<transdate> field will be set to the current date.
-Returns one or two objects depending on the context. In list context
-the new delivery order instance and a shipto instance will be
-returned. In scalar instance only the delivery order instance is
-returned.
-
-Custom shipto addresses (the ones specific to the sales/purchase
-record and not to the customer/vendor) are only linked from C<shipto>
-to C<delivery_orders>. Meaning C<delivery_orders.shipto_id> will not
-be filled in that case. That's why a separate shipto object is created
-and returned.
-
-The objects returned are not saved.
+Returns the new delivery order instance. The object returned is not
+saved.
C<%params> can include the following options:
sub convert_to_delivery_order {
my ($self, @args) = @_;
- my ($delivery_order, $custom_shipto);
+ my $delivery_order;
if (!$self->db->with_transaction(sub {
require SL::DB::DeliveryOrder;
- ($delivery_order, $custom_shipto) = SL::DB::DeliveryOrder->new_from($self, @args);
+ $delivery_order = SL::DB::DeliveryOrder->new_from($self, @args);
$delivery_order->save;
- $custom_shipto->save if $custom_shipto;
$self->link_to_record($delivery_order);
# TODO extend link_to_record for items, otherwise long-term no d.r.y.
foreach my $item (@{ $delivery_order->items }) {
$self->update_attributes(delivered => 1);
1;
})) {
- return wantarray ? () : undef;
+ return undef;
}
- return wantarray ? ($delivery_order, $custom_shipto) : $delivery_order;
+ return $delivery_order;
}
sub number {
The arguments in C<%params> are passed to
L<SL::DB::DeliveryOrder::new_from>.
-Returns C<undef> on failure. Otherwise the return value depends on the
-context. In list context the new delivery order and a shipto instance
-will be returned. In scalar instance only the delivery order instance
-is returned.
-
-Custom shipto addresses (the ones specific to the sales/purchase
-record and not to the customer/vendor) are only linked from C<shipto>
-to C<delivery_orders>. Meaning C<delivery_orders.shipto_id> will not
-be filled in that case. That's why a separate shipto object is created
-and returned.
+Returns C<undef> on failure. Otherwise the new delivery order will be
+returned.
=head2 C<convert_to_invoice %params>