X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FController%2FRecordLinks.pm;h=900123ef835df96037212fd0a27a4f785cd58916;hb=14672a1d69298562d8aac987ff2c4eaab3492088;hp=3e8f028e5a4381448411626928927ab48f232f5a;hpb=149efbb1910ebf5e9ada649a4735777376067ab3;p=kivitendo-erp.git diff --git a/SL/Controller/RecordLinks.pm b/SL/Controller/RecordLinks.pm index 3e8f028e5..900123ef8 100644 --- a/SL/Controller/RecordLinks.pm +++ b/SL/Controller/RecordLinks.pm @@ -65,7 +65,10 @@ sub action_ajax_list { my ($self) = @_; eval { - my $linked_records = $self->object->linked_records(direction => 'both', recursive => 1, save_path => 1); + my $linked_records = ($::instance_conf->get_always_record_links_from_order && ref $self->object ne 'SL::DB::Order') + ? $self->get_order_centric_linked_records + : $self->object->linked_records(direction => 'both', recursive => 1, save_path => 1); + push @{ $linked_records }, $self->object->sepa_export_items if $self->object->can('sepa_export_items'); my $output = grouped_record_list( @@ -242,4 +245,24 @@ sub check_auth { $::auth->assert('record_links'); } +# internal + +sub get_order_centric_linked_records { + my ($self) = @_; + + my $all_linked_records = $self->object->linked_records(direction => 'from', recursive => 1); + my $filtered_orders = [ grep { 'SL::DB::Order' eq ref $_ && $_->is_type('sales_order') } @$all_linked_records ]; + + # no orders no call to linked_records via batch mode + # but instead return default list + return $self->object->linked_records(direction => 'both', recursive => 1, save_path => 1) + unless scalar @$filtered_orders; + + # we have a order, therefore get the tree view from the top (order) + my $id_ref = [ map { $_->id } @$filtered_orders ]; + my $linked_records = SL::DB::Order->new->linked_records(direction => 'to', recursive => 1, batch => $id_ref); + push @{ $linked_records }, @$filtered_orders; + + return $linked_records; +} 1;