TopQuickSearch: Alle Artikelsuchen haben nur Erzeugnisse gefunden
[kivitendo-erp.git] / SL / Controller / TopQuickSearch / Article.pm
1 package SL::Controller::TopQuickSearch::Article;
2
3 use strict;
4 use parent qw(Rose::Object);
5
6 use SL::Locale::String qw(t8);
7 use SL::DB::Part;
8 use SL::Controller::Helper::GetModels;
9 use SL::Controller::Base;
10
11 use Rose::Object::MakeMethods::Generic (
12   'scalar --get_set_init' => [ qw(parts models part) ],
13 );
14
15 sub auth { 'part_service_assembly_edit' }
16
17 sub name { 'article' }
18
19 sub description_config { t8('Articles') }
20
21 sub description_field { t8('Articles') }
22
23 sub query_autocomplete {
24   my ($self) = @_;
25
26   my $objects = $self->models->get;
27
28   [
29     map {
30      value       => $_->displayable_name,
31      label       => $_->displayable_name,
32      id          => $_->id,
33     }, @$objects
34   ];
35 }
36
37 sub select_autocomplete {
38   redirect_to_part($::form->{id});
39 }
40
41 sub do_search {
42   my ($self) = @_;
43
44   my $objects = $self->models->get;
45
46   return !@$objects     ? ()
47        : @$objects == 1 ? redirect_to_part($objects->[0]->id)
48        :                  redirect_to_search($::form->{term});
49 }
50
51 sub redirect_to_search {
52   SL::Controller::Base->new->url_for(
53     controller  => 'ic.pl',
54     action      => 'generate_report',
55     all         => $_[0],
56   );
57 }
58
59 sub redirect_to_part {
60   SL::Controller::Base->new->url_for(
61     controller => 'ic.pl',
62     action     => 'edit',
63     id         => $_[0],
64   );
65 }
66
67 sub type {
68   ()
69 }
70
71 sub init_models {
72   my ($self) = @_;
73
74   SL::Controller::Helper::GetModels->new(
75     controller => $self,
76     model      => 'Part',
77     source     => {
78       filter => {
79         ($self->type),
80         'all:substr:multi::ilike' => $::form->{term},
81       },
82     },
83     sorted     => {
84       _default   => {
85         by  => 'partnumber',
86         dir => 1,
87       },
88       partnumber => t8('Partnumber'),
89     },
90     paginated  => {
91       per_page => 10,
92     },
93   )
94 }
95
96 1;