X-Git-Url: http://wagnertech.de/gitweb/gitweb.cgi/kivitendo-erp.git/blobdiff_plain/a7ca8ba215c2a039e97c27bc3c637712fca837e9..a2bab345aedcfbb03bdf0e0aa1f28a5c57a5d02b:/SL/DB/DeliveryOrder.pm diff --git a/SL/DB/DeliveryOrder.pm b/SL/DB/DeliveryOrder.pm index b6f1f9596..284c15fc8 100644 --- a/SL/DB/DeliveryOrder.pm +++ b/SL/DB/DeliveryOrder.pm @@ -119,7 +119,7 @@ sub new_from { $item_parent_column = 'order'; } - my %args = ( map({ ( $_ => $source->$_ ) } qw(cp_id currency_id customer_id cusordnumber department_id employee_id globalproject_id intnotes language_id notes + my %args = ( map({ ( $_ => $source->$_ ) } qw(cp_id currency_id customer_id cusordnumber delivery_term_id department_id employee_id globalproject_id intnotes language_id notes ordnumber payment_id reqdate salesman_id shippingpoint shipvia taxincluded taxzone_id transaction_description vendor_id )), closed => 0, @@ -164,14 +164,15 @@ sub new_from { $item_parents{$source_item_id} ||= $source_item->$item_parent_column; my $item_parent = $item_parents{$source_item_id}; - SL::DB::DeliveryOrderItem->new(map({ ( $_ => $source_item->$_ ) } + my $current_do_item = SL::DB::DeliveryOrderItem->new(map({ ( $_ => $source_item->$_ ) } qw(base_qty cusordnumber description discount lastcost longdescription marge_price_factor parts_id price_factor price_factor_id project_id qty reqdate sellprice serialnumber transdate unit active_discount_source active_price_source )), custom_variables => \@custom_variables, ordnumber => ref($item_parent) eq 'SL::DB::Order' ? $item_parent->ordnumber : $source_item->ordnumber, ); - + $current_do_item->{"converted_from_orderitems_id"} = $_->{id} if ref($item_parent) eq 'SL::DB::Order'; + $current_do_item; } @{ $items }; @items = grep { $params{item_filter}->($_) } @items if $params{item_filter}; @@ -195,10 +196,11 @@ sub convert_to_invoice { my $invoice; if (!$self->db->with_transaction(sub { require SL::DB::Invoice; - $invoice = SL::DB::Invoice->new_from($self)->post(%params) || die; + $invoice = SL::DB::Invoice->new_from($self, %params)->post || die; $self->link_to_record($invoice); + # TODO extend link_to_record for items, otherwise long-term no d.r.y. foreach my $item (@{ $invoice->items }) { - foreach (qw(delivery_order_items)) { # expand if needed (delivery_order_items) + foreach (qw(delivery_order_items)) { # expand if needed (orderitems) if ($item->{"converted_from_${_}_id"}) { die unless $item->{id}; RecordLinks->create_links('mode' => 'ids', @@ -328,7 +330,7 @@ L. That invoice is posted, and C<$self> is linked to the new invoice via L. C<$self>'s C attribute is set to C, and C<$self> is saved. -The arguments in C<%params> are passed to L. +The arguments in C<%params> are passed to L. Returns the new invoice instance on success and C on failure. The whole process is run inside a transaction. On failure