Bug 13378: Add a filter to search suggestions not linked to a fund

This patch adds a "None" option for the fund filter.

Test plan:
1/ Go on the suggestion search page
2/ Search suggestions not linked to a fund using the "None" option.
3/ Search all suggestions (linked or not to a fund) using the "Any" option.

Works as expected.
Signed-off-by: Marc Veron <veron@veron.ch>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@gmail.com>
This commit is contained in:
Jonathan Druart 2014-12-03 11:35:36 +01:00 committed by Tomas Cohen Arazi
parent 57ac4a126b
commit fbfc109777
3 changed files with 68 additions and 14 deletions

View File

@ -158,16 +158,17 @@ sub SearchSuggestion {
qw( STATUS itemtype suggestedby managedby acceptedby budgetid biblionumber )
)
{
if ( exists $suggestion->{$field} ) {
if ( defined $suggestion->{$field} and $suggestion->{$field} ne '' )
{
push @sql_params, $suggestion->{$field};
push @query, qq{ AND suggestions.$field=? };
if ( exists $suggestion->{$field}
and defined $suggestion->{$field}
and $suggestion->{$field} ne '__ANY__'
and $suggestion->{$field} ne q||
) {
if ( $suggestion->{$field} eq '__NONE__' ) {
push @query, qq{ AND (suggestions.$field = '' OR suggestions.$field IS NULL) };
}
else {
push @query, qq{
AND (suggestions.$field='' OR suggestions.$field IS NULL)
};
push @sql_params, $suggestion->{$field};
push @query, qq{ AND suggestions.$field = ? };
}
}
}

View File

@ -744,7 +744,14 @@ h4.local_collapse a { font-size : 80%; text-decoration: none; } fieldset.brief o
<fieldset class="brief"><h4 class="local_collapse"><a href="#">Acquisition information</a></h4>
<ol><li><label for="budgetid"> Book fund:</label>
<select name="budgetid" id="budgetid"><option value="">Any</option>[% FOREACH budgetid_loo IN budgetid_loop %]
<select name="budgetid" id="budgetid">
<option value="__ANY__">Any</option>
[% IF budgetid == '__NONE__' %]
<option value="__NONE__" selected="selected">None</option>
[% ELSE %]
<option value="__NONE__">None</option>
[% END %]
[% FOREACH budgetid_loo IN budgetid_loop %]
[% IF ( budgetid_loo.selected ) %] <option value="[% budgetid_loo.code %]" selected="selected">[% budgetid_loo.desc %]</option>[% ELSE %]<option value="[% budgetid_loo.code %]">[% budgetid_loo.desc %]</option>[% END %]
[% END %]
</select></li>

View File

@ -20,10 +20,11 @@ use Modern::Perl;
use C4::Context;
use C4::Members;
use C4::Letters;
use C4::Budgets;
use Koha::DateUtils qw( dt_from_string );
use Test::More tests => 97;
use Test::More tests => 101;
use Test::Warn;
BEGIN {
@ -65,6 +66,33 @@ my $my_suggestion = {
note => 'my note',
};
my $budgetperiod_id = AddBudgetPeriod({
budget_period_startdate => '2008-01-01',
budget_period_enddate => '2008-12-31',
budget_period_description => 'MAPERI',
budget_period_active => 1,
});
my $budget_id = AddBudget({
budget_code => 'ABCD',
budget_amount => '123.132000',
budget_name => 'ABCD',
budget_notes => 'This is a note',
budget_period_id => $budgetperiod_id,
});
my $my_suggestion_with_budget = {
title => 'my title 2',
author => 'my author 2',
publishercode => 'my publishercode 2',
suggestedby => $borrowernumber,
biblionumber => $biblionumber1,
managedby => '',
manageddate => '',
accepteddate => dt_from_string,
note => 'my note',
budgetid => $budget_id,
};
is( CountSuggestion(), 0, 'CountSuggestion without the status returns 0' );
is( CountSuggestion('ASKED'), 0, 'CountSuggestion returns the correct number of suggestions' );
@ -74,6 +102,7 @@ is( CountSuggestion('REJECTED'), 0, 'CountSuggestion returns the correct number
my $my_suggestionid = NewSuggestion($my_suggestion);
isnt( $my_suggestionid, 0, 'NewSuggestion returns an not null id' );
my $my_suggestionid_with_budget = NewSuggestion($my_suggestion_with_budget);
is( GetSuggestion(), undef, 'GetSuggestion without the suggestion id returns undef' );
my $suggestion = GetSuggestion($my_suggestionid);
@ -85,7 +114,7 @@ is( $suggestion->{biblionumber}, $my_suggestion->{biblionumber}, 'NewSuggestion
is( $suggestion->{STATUS}, 'ASKED', 'NewSuggestion stores a suggestion with the status ASKED by default' );
is( $suggestion->{managedby}, undef, 'NewSuggestion stores empty string as undef for non existent foreign key (integer)' );
is( $suggestion->{manageddate}, undef, 'NewSuggestion stores empty string as undef for date' );
is( CountSuggestion('ASKED'), 1, 'CountSuggestion returns the correct number of suggestions' );
is( CountSuggestion('ASKED'), 2, 'CountSuggestion returns the correct number of suggestions' );
is( ModSuggestion(), undef, 'ModSuggestion without the suggestion returns undef' );
@ -201,9 +230,8 @@ is( $connect_suggestion_and_biblio, '1', 'ConnectSuggestionAndBiblio returns 1'
$suggestion = GetSuggestion($my_suggestionid);
is( $suggestion->{biblionumber}, $biblionumber2, 'ConnectSuggestionAndBiblio updates the biblio number correctly' );
my $search_suggestion = SearchSuggestion();
is( @$search_suggestion, 1, 'SearchSuggestion without arguments returns all suggestions' );
is( @$search_suggestion, 2, 'SearchSuggestion without arguments returns all suggestions' );
$search_suggestion = SearchSuggestion({
title => $mod_suggestion1->{title},
@ -224,7 +252,7 @@ $search_suggestion = SearchSuggestion({
is( @$search_suggestion, 0, 'SearchSuggestion returns the correct number of suggestions' );
$search_suggestion = SearchSuggestion({
publishercode => $mod_suggestion3->{publishercode},
publishercode => $mod_suggestion1->{publishercode},
});
is( @$search_suggestion, 1, 'SearchSuggestion returns the correct number of suggestions' );
$search_suggestion = SearchSuggestion({
@ -241,6 +269,22 @@ $search_suggestion = SearchSuggestion({
});
is( @$search_suggestion, 0, 'SearchSuggestion returns the correct number of suggestions' );
$search_suggestion = SearchSuggestion({
budgetid => '',
});
is( @$search_suggestion, 2, 'SearchSuggestion (budgetid = "") returns the correct number of suggestions' );
$search_suggestion = SearchSuggestion({
budgetid => $budget_id,
});
is( @$search_suggestion, 1, 'SearchSuggestion (budgetid = $budgetid) returns the correct number of suggestions' );
$search_suggestion = SearchSuggestion({
budgetid => '__NONE__',
});
is( @$search_suggestion, 1, 'SearchSuggestion (budgetid = "__NONE__") returns the correct number of suggestions' );
$search_suggestion = SearchSuggestion({
budgetid => '__ANY__',
});
is( @$search_suggestion, 2, 'SearchSuggestion (budgetid = "__ANY__") returns the correct number of suggestions' );
my $del_suggestion = {
title => 'my deleted title',
@ -273,3 +317,5 @@ is(@$itemtypes2, 8, "Purchase suggestion itemtypes collected, default AdvancedSe
is_deeply($itemtypes1, $itemtypes2, 'same set of purchase suggestion formats retrieved');
$dbh->rollback;
done_testing;