From 6c3afa9b81facff4307c35b8f9de6999bb5e298e Mon Sep 17 00:00:00 2001 From: =?utf8?q?Bernd=20Ble=C3=9Fmann?= Date: Tue, 28 Sep 2021 09:13:10 +0200 Subject: [PATCH] S:D:Order: convert_to_invoice: items verlinken --- SL/DB/Order.pm | 15 +++++++++++++++ 1 file changed, 15 insertions(+) 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; })) { -- 2.20.1