From: Bernd Bleßmann Date: Wed, 23 Mar 2022 09:41:57 +0000 (+0100) Subject: Verknüfpte Belege: Keine Verknüpfungen zu Angebot von Angebot oder Auftrag. X-Git-Tag: kivitendo-mebil_0.1-0~10^2~2^2~79 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=7bacc2aae8c0bf72a8fe1eaf757890184e6950f8;p=kivitendo-erp.git Verknüfpte Belege: Keine Verknüpfungen zu Angebot von Angebot oder Auftrag. Ein Angbot beginnt immer einen neuen Workflow (es sei denn der Vorgänger ist ein Pflichtenheft). Das kann sonst dazu führen, dass eine Position mehrere Angebote als Vorgänger hat und dann kann das Angebot nicht mehr gedruckt werden. Auch logisch ist das nicht sinnvoll. Fix im Auftrags-Controller und Upgrade-Skript, um solche Verknüpfungen zu entfernen. --- diff --git a/SL/Controller/Order.pm b/SL/Controller/Order.pm index f0920f739..b7793b1be 100644 --- a/SL/Controller/Order.pm +++ b/SL/Controller/Order.pm @@ -1847,7 +1847,10 @@ sub workflow_sales_or_request_for_quotation { my $destination_type = $::form->{type} eq sales_order_type() ? sales_quotation_type() : request_quotation_type(); $self->order(SL::DB::Order->new_from($self->order, destination_type => $destination_type)); - $self->{converted_from_oe_id} = delete $::form->{id}; + delete $::form->{id}; + + # no linked records from order to quotations + delete $::form->{$_} for qw(converted_from_oe_id converted_from_orderitems_ids); # set item ids to new fake id, to identify them as new items foreach my $item (@{$self->order->items_sorted}) { diff --git a/sql/Pg-upgrade2/record_links_remove_to_quotation.pl b/sql/Pg-upgrade2/record_links_remove_to_quotation.pl new file mode 100644 index 000000000..e92600607 --- /dev/null +++ b/sql/Pg-upgrade2/record_links_remove_to_quotation.pl @@ -0,0 +1,51 @@ +# @tag: record_links_remove_to_quotation +# @description: Verknüpfte Positionen mit Ziel Angebot und dazugehörige Belegverknüpfung entfernen, wenn Quelle Angebot oder Auftrag. +# @depends: release_3_6_0 +package SL::DBUpgrade2::record_links_remove_to_quotation; + +use strict; +use utf8; + +use parent qw(SL::DBUpgrade2::Base); + +use SL::DBUtils; + +sub run { + my ($self) = @_; + + my $query = qq|SELECT record_links.id AS rl_id, from_oe.id AS from_oe_id, to_oe.id AS to_oe_id FROM record_links + LEFT JOIN orderitems from_oi ON (from_oi.id = from_id) + LEFT JOIN orderitems to_oi ON (to_oi.id = to_id) + LEFT JOIN oe from_oe ON (from_oe.id = from_oi.trans_id) + LEFT JOIN oe to_oe ON (to_oe.id = to_oi.trans_id) + WHERE from_table = 'orderitems' + AND to_table = 'orderitems' + AND to_oe.quotation IS TRUE|; + + my $refs = selectall_hashref_query($::form, $self->dbh, $query); + + my $query_delete_oi_links = qq| + DELETE FROM record_links WHERE id = ?; + |; + my $sth_delete_oi_links = $self->dbh->prepare($query_delete_oi_links); + + my $query_delete_oe_links = qq| + DELETE FROM record_links WHERE from_table = 'oe' AND to_table = 'oe' AND from_id = ? AND to_id = ?; + |; + my $sth_delete_oe_links = $self->dbh->prepare($query_delete_oe_links); + + my %oe_links; + foreach my $ref (@$refs) { + $sth_delete_oi_links->execute($ref->{rl_id}) || $::form->dberror($query_delete_oi_links); + $oe_links{$ref->{from_oe_id} . ':' . $ref->{to_oe_id}} = 1; + } + + for my $from_to (keys %oe_links) { + my ($from_oe_id, $to_oe_id) = split ':', $from_to; + $sth_delete_oe_links->execute($from_oe_id, $to_oe_id) || $::form->dberror($query_delete_oe_links); + } + + return 1; +} + +1;