From fc890e1040a469ee62b3661c5da2f3d2efb4cce9 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jan=20B=C3=BCren?= Date: Thu, 3 Dec 2015 21:01:10 +0100 Subject: [PATCH] convert_to_delivery_order um record_links auf item-Ebene erweitert MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Bisher wurden nur die Belege verknüpft und nicht die einzelnen Items. Analoge Implementierung wie bei convert_to_invoice. Sinnvoll wäre ein Auslagern, dieser "zu ähnlichen" Verfahren in beiden Fällen --- SL/DB/DeliveryOrder.pm | 8 +++++--- SL/DB/Order.pm | 16 ++++++++++++++++ 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/SL/DB/DeliveryOrder.pm b/SL/DB/DeliveryOrder.pm index d15b3fa0b..284c15fc8 100644 --- a/SL/DB/DeliveryOrder.pm +++ b/SL/DB/DeliveryOrder.pm @@ -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}; @@ -197,8 +198,9 @@ sub convert_to_invoice { require SL::DB::Invoice; $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', diff --git a/SL/DB/Order.pm b/SL/DB/Order.pm index d61ec31eb..4d0a2fa07 100644 --- a/SL/DB/Order.pm +++ b/SL/DB/Order.pm @@ -164,6 +164,22 @@ sub convert_to_delivery_order { $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 }) { + foreach (qw(orderitems)) { # expand if needed (delivery_order_items) + if ($item->{"converted_from_${_}_id"}) { + die unless $item->{id}; + RecordLinks->create_links('mode' => 'ids', + 'from_table' => $_, + 'from_ids' => $item->{"converted_from_${_}_id"}, + 'to_table' => 'delivery_order_items', + 'to_id' => $item->{id}, + ) || die; + delete $item->{"converted_from_${_}_id"}; + } + } + } + $self->update_attributes(delivered => 1); 1; })) { -- 2.20.1