From: Bernd Bleßmann Date: Tue, 28 Sep 2021 07:13:10 +0000 (+0200) Subject: S:D:Order: convert_to_invoice: items verlinken X-Git-Tag: kivitendo-mebil_0.1-0~10^2~2^2~337 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=6c3afa9b81facff4307c35b8f9de6999bb5e298e;p=kivitendo-erp.git S:D:Order: convert_to_invoice: items verlinken --- diff --git a/SL/DB/Order.pm b/SL/DB/Order.pm index f1cfba7f1..cfe8af48c 100644 --- a/SL/DB/Order.pm +++ b/SL/DB/Order.pm @@ -240,6 +240,21 @@ sub convert_to_invoice { require SL::DB::Invoice; $invoice = SL::DB::Invoice->new_from($self)->post(%params) || 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(orderitems)) { + if ($item->{"converted_from_${_}_id"}) { + die unless $item->{id}; + RecordLinks->create_links('mode' => 'ids', + 'from_table' => $_, + 'from_ids' => $item->{"converted_from_${_}_id"}, + 'to_table' => 'invoice', + 'to_id' => $item->{id}, + ) || die; + delete $item->{"converted_from_${_}_id"}; + } + } + } $self->update_attributes(closed => 1); 1; })) {