From a082c674f694bb67acd5677c0c9c1f71a1cea50e Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Mon, 17 Jan 2022 14:20:49 +0100 Subject: [PATCH] Bug 23991: Fix branchcode and budgetid filtering --- suggestion/suggestion.pl | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/suggestion/suggestion.pl b/suggestion/suggestion.pl index 30cb57d367a..ebf119528be 100755 --- a/suggestion/suggestion.pl +++ b/suggestion/suggestion.pl @@ -362,16 +362,19 @@ if ($op=~/else/) { @criteria_dv = ( C4::Context->userenv->{'branch'} ); } + unless ( exists $suggestion_ref->{branchcode} ) { + $suggestion_ref->{branchcode} = C4::Context->userenv->{'branch'}; + } + my @allsuggestions; foreach my $criteriumvalue ( @criteria_dv ) { + my $search_params = {%$suggestion_ref}; # By default, display suggestions from current working branch - unless ( exists $$suggestion_ref{'branchcode'} ) { - $$suggestion_ref{'branchcode'} = C4::Context->userenv->{'branch'}; - } my $definedvalue = defined $$suggestion_ref{$displayby} && $$suggestion_ref{$displayby} ne ""; next if ( $definedvalue && $$suggestion_ref{$displayby} ne $criteriumvalue ) and ($displayby ne 'branchcode' && $branchfilter ne '__ANY__' ); - $$suggestion_ref{$displayby} = $criteriumvalue; + + $search_params->{$displayby} = $criteriumvalue; # filter on date fields foreach my $field (qw( suggesteddate manageddate accepteddate )) { @@ -389,17 +392,24 @@ if ($op=~/else/) { if ( $from_dt || $to_dt ) { my $dtf = Koha::Database->new->schema->storage->datetime_parser; if ( $from_dt && $to_dt ) { - $suggestion_ref->{$field} = { -between => [ $from_dt, $to_dt ] }; + $search_params->{$field} = { -between => [ $from_dt, $to_dt ] }; } elsif ( $from_dt ) { - $suggestion_ref->{$field} = { '>=' => $from_dt }; + $search_params->{$field} = { '>=' => $from_dt }; } elsif ( $to_dt ) { - $suggestion_ref->{$field} = { '<=' => $to_dt }; + $search_params->{$field} = { '<=' => $to_dt }; } } } + if ( $search_params->{budgetid} && $search_params->{budgetid} eq '__NONE__' ) { + $search_params->{budgetid} = [undef, '' ]; + } + for my $f (qw (branchcode budgetid)) { + delete $search_params->{$f} if $search_params->{$f} eq '__ANY__'; + } + my @suggestions = Koha::Suggestions->search_limited( - { %$suggestion_ref, archived => $filter_archived } )->as_list; + { %$search_params, archived => $filter_archived } )->as_list; push @allsuggestions, { -- 2.25.1