From 68b299559a5478f84b6866e8efeb9346267fc49b Mon Sep 17 00:00:00 2001 From: =?utf8?q?Sven=20Sch=C3=B6ling?= Date: Fri, 10 Feb 2017 15:33:11 +0100 Subject: [PATCH] Part: exact_match robuster mit localized $::form Behebt Bugs mit vergessenen Filtern wie unit_obj.convertible_unit --- SL/Controller/Part.pm | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/SL/Controller/Part.pm b/SL/Controller/Part.pm index fce0b6fb3..9666296aa 100644 --- a/SL/Controller/Part.pm +++ b/SL/Controller/Part.pm @@ -500,22 +500,19 @@ sub action_ajax_autocomplete { # if someone types something, and hits enter, assume he entered the full name. # if something matches, treat that as sole match - # unfortunately get_models can't do more than one per package atm, so we d it - # the oldfashioned way. + # since we need a second get models instance with different filters for that, + # we only modify the original filter temporarily in place if ($::form->{prefer_exact}) { + local $::form->{filter}{'all::ilike'} = delete local $::form->{filter}{'all:substr:multi::ilike'}; + + my $exact_models = SL::Controller::Helper::GetModels->new( + controller => $self, + sorted => 0, + paginated => { per_page => 2 }, + with_objects => [ qw(unit_obj classification) ], + ); my $exact_matches; - if (1 == scalar @{ $exact_matches = SL::DB::Manager::Part->get_all( - query => [ - obsolete => 0, - SL::DB::Manager::Part->type_filter($::form->{filter}{part_type}), - SL::DB::Manager::PartClassification->classification_filter($::form->{filter}{classification_id}), - or => [ - description => { ilike => $::form->{filter}{'all:substr:multi::ilike'} }, - partnumber => { ilike => $::form->{filter}{'all:substr:multi::ilike'} }, - ] - ], - limit => 2, - ) }) { + if (1 == scalar @{ $exact_matches = $exact_models->get }) { $self->parts($exact_matches); } } -- 2.20.1